gameone.py 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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': 'Puh, das ist ja wieder eine volle Packung! Erst begleiten wir Nils zum '
  25. 'FIFA-Pressepokal 2014, den er nach 2010 nun zum zweiten Mal gewinnen will.\n'
  26. 'Danach gibt’s eine Vorschau auf die drei kommenden Hits “Star Citizen”, “Kingdom Come: Deliverance” und “Project Cars”.\n'
  27. 'Und dann geht’s auch schon weiter mit der nächsten Folge vom Nerdquiz! Der schöne Trant foltert seine Kandidaten wieder '
  28. 'mit fiesen Fragen. Hier gibt’s die erste Hälfte, in Folge 289 geht’s weiter.'
  29. }
  30. }
  31. def _real_extract(self, url):
  32. mobj = re.match(self._VALID_URL, url)
  33. video_id = mobj.group('id')
  34. webpage = self._download_webpage(url, video_id)
  35. og_video = self._og_search_video_url(webpage, secure=False)
  36. mrss_url = self._search_regex(r'mrss=([^&]+)', og_video, 'mrss')
  37. mrss = self._download_xml(mrss_url, video_id, 'Downloading mrss')
  38. title = mrss.find('.//item/title').text
  39. thumbnail = mrss.find('.//item/image').get('url')
  40. description = self._extract_description(mrss)
  41. content = mrss.find(xpath_with_ns('.//media:content', NAMESPACE_MAP))
  42. content_url = content.get('url')
  43. content = self._download_xml(content_url, video_id, 'Downloading media:content')
  44. rendition_items = content.findall('.//rendition')
  45. duration = int(rendition_items[0].get('duration'))
  46. formats = [
  47. {
  48. 'url': re.sub(r'.*/(r2)', RAW_MP4_URL + r'\1', r.find('./src').text),
  49. 'width': int(r.get('width')),
  50. 'height': int(r.get('height')),
  51. 'tbr': int(r.get('bitrate')),
  52. }
  53. for r in rendition_items
  54. ]
  55. return {
  56. 'id': video_id,
  57. 'title': title,
  58. 'thumbnail': thumbnail,
  59. 'duration': duration,
  60. 'formats': formats,
  61. 'description': description,
  62. }
  63. def _extract_description(self, mrss):
  64. description = mrss.find('.//item/description')
  65. return u''.join(t for t in description.itertext())