gameone.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import xpath_with_ns
  6. NAMESPACE_MAP = {
  7. 'media': 'http://search.yahoo.com/mrss/',
  8. }
  9. # URL prefix to download the mp4 files directly instead of streaming via rtmp
  10. # Credits go to XBox-Maniac http://board.jdownloader.org/showpost.php?p=185835&postcount=31
  11. RAW_MP4_URL = 'http://cdn.riptide-mtvn.com/'
  12. class GameOneIE(InfoExtractor):
  13. _VALID_URL = r'https?://(?:www\.)?gameone\.de/tv/(?P<id>\d+)'
  14. _TESTS = {
  15. 'url': 'http://www.gameone.de/tv/288',
  16. 'md5': '136656b7fb4c9cb4a8e2d500651c499b',
  17. 'info_dict': {
  18. 'id': '288',
  19. 'ext': 'mp4',
  20. 'title': 'Game One - Folge 288',
  21. 'duration': 1238,
  22. 'thumbnail': 'http://s3.gameone.de/gameone/assets/video_metas/teaser_images/000/643/636/big/640x360.jpg',
  23. }
  24. }
  25. def _real_extract(self, url):
  26. mobj = re.match(self._VALID_URL, url)
  27. video_id = mobj.group('id')
  28. webpage = self._download_webpage(url, video_id)
  29. og_video = self._og_search_video_url(webpage, secure=False)
  30. mrss_url = self._search_regex(r'mrss=([^&]+)', og_video, 'mrss')
  31. mrss = self._download_xml(mrss_url, video_id, 'Downloading mrss')
  32. title = mrss.find('.//item/title').text
  33. thumbnail = mrss.find('.//item/image').get('url')
  34. content = mrss.find(xpath_with_ns('.//media:content', NAMESPACE_MAP))
  35. content_url = content.get('url')
  36. content = self._download_xml(content_url, video_id, 'Downloading media:content')
  37. rendition_items = content.findall('.//rendition')
  38. duration = int(rendition_items[0].get('duration'))
  39. formats = [
  40. {
  41. 'url': re.sub(r'.*/(r2)', RAW_MP4_URL + r'\1', r.find('./src').text),
  42. 'width': int(r.get('width')),
  43. 'height': int(r.get('height')),
  44. 'tbr': int(r.get('bitrate')),
  45. }
  46. for r in rendition_items
  47. ]
  48. return {
  49. 'id': video_id,
  50. 'title': title,
  51. 'thumbnail': thumbnail,
  52. 'duration': duration,
  53. 'formats': formats,
  54. }