gameone.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. xpath_with_ns,
  7. parse_iso8601
  8. )
  9. NAMESPACE_MAP = {
  10. 'media': 'http://search.yahoo.com/mrss/',
  11. }
  12. # URL prefix to download the mp4 files directly instead of streaming via rtmp
  13. # Credits go to XBox-Maniac
  14. # http://board.jdownloader.org/showpost.php?p=185835&postcount=31
  15. RAW_MP4_URL = 'http://cdn.riptide-mtvn.com/'
  16. class GameOneIE(InfoExtractor):
  17. _VALID_URL = r'https?://(?:www\.)?gameone\.de/tv/(?P<id>\d+)'
  18. _TESTS = [
  19. {
  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. {
  35. 'url': 'http://gameone.de/tv/220',
  36. 'md5': '5227ca74c4ae6b5f74c0510a7c48839e',
  37. 'info_dict': {
  38. 'id': '220',
  39. 'ext': 'mp4',
  40. 'upload_date': '20120918',
  41. 'description': 'Jet Set Radio HD, Tekken Tag Tournament 2, Source Filmmaker',
  42. 'timestamp': 1347971451,
  43. 'title': 'Game One - Folge 220',
  44. 'duration': 896,
  45. 'age_limit': 16,
  46. }
  47. }
  48. ]
  49. def _real_extract(self, url):
  50. mobj = re.match(self._VALID_URL, url)
  51. video_id = mobj.group('id')
  52. webpage = self._download_webpage(url, video_id)
  53. og_video = self._og_search_video_url(webpage, secure=False)
  54. description = self._html_search_meta('description', webpage)
  55. age_limit = int(
  56. self._search_regex(
  57. r'age=(\d+)',
  58. self._html_search_meta(
  59. 'age-de-meta-label',
  60. webpage),
  61. 'age_limit',
  62. '0'))
  63. mrss_url = self._search_regex(r'mrss=([^&]+)', og_video, 'mrss')
  64. mrss = self._download_xml(mrss_url, video_id, 'Downloading mrss')
  65. title = mrss.find('.//item/title').text
  66. thumbnail = mrss.find('.//item/image').get('url')
  67. timestamp = parse_iso8601(mrss.find('.//pubDate').text, delimiter=' ')
  68. content = mrss.find(xpath_with_ns('.//media:content', NAMESPACE_MAP))
  69. content_url = content.get('url')
  70. content = self._download_xml(
  71. content_url,
  72. video_id,
  73. 'Downloading media:content')
  74. rendition_items = content.findall('.//rendition')
  75. duration = int(rendition_items[0].get('duration').split('.')[0])
  76. formats = [
  77. {
  78. 'url': re.sub(r'.*/(r2)', RAW_MP4_URL + r'\1', r.find('./src').text),
  79. 'width': int(r.get('width')),
  80. 'height': int(r.get('height')),
  81. 'tbr': int(r.get('bitrate')),
  82. }
  83. for r in rendition_items
  84. ]
  85. self._sort_formats(formats)
  86. return {
  87. 'id': video_id,
  88. 'title': title,
  89. 'thumbnail': thumbnail,
  90. 'duration': duration,
  91. 'formats': formats,
  92. 'description': description,
  93. 'age_limit': age_limit,
  94. 'timestamp': timestamp,
  95. }
  96. class GameOnePlaylistIE(InfoExtractor):
  97. _VALID_URL = r'https?://(?:www\.)?gameone\.de(?:/tv)?/?$'
  98. IE_NAME = 'gameone:playlist'
  99. _TEST = {
  100. 'url': 'http://www.gameone.de/tv',
  101. 'info_dict': {
  102. 'title': 'GameOne',
  103. },
  104. 'playlist_mincount': 294,
  105. }
  106. def _real_extract(self, url):
  107. webpage = self._download_webpage('http://www.gameone.de/tv', 'TV')
  108. max_id = max(map(int, re.findall(r'<a href="/tv/(\d+)"', webpage)))
  109. entries = [
  110. self.url_result('http://www.gameone.de/tv/%d' %
  111. video_id, 'GameOne')
  112. for video_id in range(max_id, 0, -1)]
  113. return {
  114. '_type': 'playlist',
  115. 'title': 'GameOne',
  116. 'entries': entries,
  117. }