gameone.py 2.5 KB

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