gameone.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 http://board.jdownloader.org/showpost.php?p=185835&postcount=31
  14. RAW_MP4_URL = 'http://cdn.riptide-mtvn.com/'
  15. PUB_DATE_FORMAT = '%Y-%m-%d %H:%M:%S %z'
  16. class GameOneIE(InfoExtractor):
  17. _VALID_URL = r'https?://(?:www\.)?gameone\.de/tv/(?P<id>\d+)'
  18. _TEST = {
  19. 'url': 'http://www.gameone.de/tv/288',
  20. 'md5': '136656b7fb4c9cb4a8e2d500651c499b',
  21. 'info_dict': {
  22. 'id': '288',
  23. 'ext': 'mp4',
  24. 'title': 'Game One - Folge 288',
  25. 'duration': 1238,
  26. 'thumbnail': 'http://s3.gameone.de/gameone/assets/video_metas/teaser_images/000/643/636/big/640x360.jpg',
  27. 'description': 'FIFA-Pressepokal 2014, Star Citizen, Kingdom Come: Deliverance, Project Cars, Schöner Trants Nerdquiz Folge 2 Runde 1',
  28. 'age_limit': 16,
  29. 'upload_date': '20140513',
  30. 'timestamp': 1399980122,
  31. }
  32. }
  33. def _real_extract(self, url):
  34. mobj = re.match(self._VALID_URL, url)
  35. video_id = mobj.group('id')
  36. webpage = self._download_webpage(url, video_id)
  37. og_video = self._og_search_video_url(webpage, secure=False)
  38. description = self._html_search_meta('description', webpage)
  39. age_limit = int(self._search_regex(r'age=(\d+)', self._html_search_meta('age-de-meta-label', webpage), 'age_limit', '0'))
  40. mrss_url = self._search_regex(r'mrss=([^&]+)', og_video, 'mrss')
  41. mrss = self._download_xml(mrss_url, video_id, 'Downloading mrss')
  42. title = mrss.find('.//item/title').text
  43. thumbnail = mrss.find('.//item/image').get('url')
  44. timestamp = parse_iso8601(mrss.find('.//pubDate').text, delimiter=' ')
  45. content = mrss.find(xpath_with_ns('.//media:content', NAMESPACE_MAP))
  46. content_url = content.get('url')
  47. content = self._download_xml(content_url, video_id, 'Downloading media:content')
  48. rendition_items = content.findall('.//rendition')
  49. duration = int(rendition_items[0].get('duration'))
  50. formats = [
  51. {
  52. 'url': re.sub(r'.*/(r2)', RAW_MP4_URL + r'\1', r.find('./src').text),
  53. 'width': int(r.get('width')),
  54. 'height': int(r.get('height')),
  55. 'tbr': int(r.get('bitrate')),
  56. }
  57. for r in rendition_items
  58. ]
  59. return {
  60. 'id': video_id,
  61. 'title': title,
  62. 'thumbnail': thumbnail,
  63. 'duration': duration,
  64. 'formats': formats,
  65. 'description': description,
  66. 'age_limit': age_limit,
  67. 'timestamp': timestamp,
  68. }