gameone.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. RAW_MP4_URL = 'http://cdn.riptide-mtvn.com/'
  10. class GameOneIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?gameone\.de/tv/(?P<id>\d+)'
  12. _TESTS = {
  13. 'url': 'http://www.gameone.de/tv/288',
  14. 'md5': '136656b7fb4c9cb4a8e2d500651c499b',
  15. 'info_dict': {
  16. 'id': '288',
  17. 'ext': 'mp4',
  18. 'title': 'Game One - Folge 288',
  19. 'duration': 1238,
  20. 'thumbnail': 'http://s3.gameone.de/gameone/assets/video_metas/teaser_images/000/643/636/big/640x360.jpg',
  21. }
  22. }
  23. def _real_extract(self, url):
  24. mobj = re.match(self._VALID_URL, url)
  25. video_id = mobj.group('id')
  26. webpage = self._download_webpage(url, video_id)
  27. og_video = self._og_search_video_url(webpage, secure=False)
  28. mrss_url = self._search_regex(r'mrss=([^&]+)', og_video, 'mrss')
  29. mrss = self._download_xml(mrss_url, video_id, 'Downloading mrss')
  30. title = mrss.find('.//item/title').text
  31. thumbnail = mrss.find('.//item/image').get('url')
  32. content = mrss.find(xpath_with_ns('.//media:content', NAMESPACE_MAP))
  33. content_url = content.get('url')
  34. content = self._download_xml(content_url, video_id, 'Downloading media:content')
  35. rendition_items = content.findall('.//rendition')
  36. duration = int(rendition_items[0].get('duration'))
  37. formats = [
  38. {
  39. 'url': re.sub(r'.*/(r2)', RAW_MP4_URL + r'\1', r.find('./src').text),
  40. 'width': int(r.get('width')),
  41. 'height': int(r.get('height')),
  42. 'tbr': int(r.get('bitrate')),
  43. }
  44. for r in rendition_items
  45. ]
  46. return {
  47. 'id': video_id,
  48. 'title': title,
  49. 'thumbnail': thumbnail,
  50. 'duration': duration,
  51. 'formats': formats,
  52. }