gameone.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import datetime
  4. import re
  5. from .common import InfoExtractor
  6. from ..utils import (
  7. xpath_with_ns,
  8. parse_iso8601
  9. )
  10. NAMESPACE_MAP = {
  11. 'media': 'http://search.yahoo.com/mrss/',
  12. }
  13. # URL prefix to download the mp4 files directly instead of streaming via rtmp
  14. # Credits go to XBox-Maniac
  15. # http://board.jdownloader.org/showpost.php?p=185835&postcount=31
  16. RAW_MP4_URL = 'http://cdn.riptide-mtvn.com/'
  17. class GameOneIE(InfoExtractor):
  18. _VALID_URL = r'https?://(?:www\.)?gameone\.de/tv/(?P<id>\d+)'
  19. _TEST = {
  20. 'url': 'http://www.gameone.de/tv/288',
  21. 'md5': '136656b7fb4c9cb4a8e2d500651c499b',
  22. 'info_dict': {
  23. 'id': '288',
  24. 'ext': 'mp4',
  25. 'title': 'Game One - Folge 288',
  26. 'duration': 1238,
  27. 'thumbnail': 'http://s3.gameone.de/gameone/assets/video_metas/teaser_images/000/643/636/big/640x360.jpg',
  28. 'description': 'FIFA-Pressepokal 2014, Star Citizen, Kingdom Come: Deliverance, Project Cars, Schöner Trants Nerdquiz Folge 2 Runde 1',
  29. 'age_limit': 16,
  30. 'upload_date': '20140513',
  31. 'timestamp': 1399980122,
  32. }
  33. }
  34. def _real_extract(self, url):
  35. mobj = re.match(self._VALID_URL, url)
  36. video_id = mobj.group('id')
  37. webpage = self._download_webpage(url, video_id)
  38. og_video = self._og_search_video_url(webpage, secure=False)
  39. description = self._html_search_meta('description', webpage)
  40. age_limit = int(
  41. self._search_regex(
  42. r'age=(\d+)',
  43. self._html_search_meta(
  44. 'age-de-meta-label',
  45. webpage),
  46. 'age_limit',
  47. '0'))
  48. mrss_url = self._search_regex(r'mrss=([^&]+)', og_video, 'mrss')
  49. mrss = self._download_xml(mrss_url, video_id, 'Downloading mrss')
  50. title = mrss.find('.//item/title').text
  51. thumbnail = mrss.find('.//item/image').get('url')
  52. timestamp = parse_iso8601(mrss.find('.//pubDate').text, delimiter=' ')
  53. content = mrss.find(xpath_with_ns('.//media:content', NAMESPACE_MAP))
  54. content_url = content.get('url')
  55. content = self._download_xml(
  56. content_url,
  57. video_id,
  58. 'Downloading media:content')
  59. rendition_items = content.findall('.//rendition')
  60. duration = int(rendition_items[0].get('duration'))
  61. formats = [
  62. {
  63. 'url': re.sub(r'.*/(r2)', RAW_MP4_URL + r'\1', r.find('./src').text),
  64. 'width': int(r.get('width')),
  65. 'height': int(r.get('height')),
  66. 'tbr': int(r.get('bitrate')),
  67. }
  68. for r in rendition_items
  69. ]
  70. self._sort_formats(formats)
  71. return {
  72. 'id': video_id,
  73. 'title': title,
  74. 'thumbnail': thumbnail,
  75. 'duration': duration,
  76. 'formats': formats,
  77. 'description': description,
  78. 'age_limit': age_limit,
  79. 'timestamp': timestamp,
  80. }
  81. class GameOnePlaylistIE(InfoExtractor):
  82. _VALID_URL = r'https?://(?:www\.)?gameone\.de(?:/tv)?/?$'
  83. def _real_extract(self, url):
  84. this_year = datetime.date.today().year
  85. webpage = self._download_webpage('http://www.gameone.de/tv/year/%d' % this_year, this_year)
  86. max_id = max(map(int, re.findall(r'<a href="/tv/(\d+)"', webpage)))
  87. entries = [self.url_result('http://www.gameone.de/tv/%d' % video_id, 'GameOne') for video_id in range(max_id, 0, -1)]
  88. return {
  89. '_type': 'playlist',
  90. 'title': 'GameOne',
  91. 'entries': entries,
  92. }