You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
4.0 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. xpath_text,
  7. xpath_element,
  8. int_or_none,
  9. parse_duration,
  10. )
  11. class HBOIE(InfoExtractor):
  12. _VALID_URL = r'https?://(?:www\.)?hbo\.com/video/video\.html\?.*vid=(?P<id>[0-9]+)'
  13. _TEST = {
  14. 'url': 'http://www.hbo.com/video/video.html?autoplay=true&g=u&vid=1437839',
  15. 'md5': '1c33253f0c7782142c993c0ba62a8753',
  16. 'info_dict': {
  17. 'id': '1437839',
  18. 'ext': 'mp4',
  19. 'title': 'Ep. 64 Clip: Encryption',
  20. }
  21. }
  22. _FORMATS_INFO = {
  23. '1920': {
  24. 'width': 1280,
  25. 'height': 720,
  26. },
  27. '640': {
  28. 'width': 768,
  29. 'height': 432,
  30. },
  31. 'highwifi': {
  32. 'width': 640,
  33. 'height': 360,
  34. },
  35. 'high3g': {
  36. 'width': 640,
  37. 'height': 360,
  38. },
  39. 'medwifi': {
  40. 'width': 400,
  41. 'height': 224,
  42. },
  43. 'med3g': {
  44. 'width': 400,
  45. 'height': 224,
  46. },
  47. }
  48. def _real_extract(self, url):
  49. video_id = self._match_id(url)
  50. video_data = self._download_xml(
  51. 'http://render.lv3.hbo.com/data/content/global/videos/data/%s.xml' % video_id, video_id)
  52. title = xpath_text(video_data, 'title', 'title', True)
  53. formats = []
  54. for source in xpath_element(video_data, 'videos', 'sources', True):
  55. if source.tag == 'size':
  56. path = xpath_text(source, './/path')
  57. if not path:
  58. continue
  59. width = source.attrib.get('width')
  60. format_info = self._FORMATS_INFO.get(width, {})
  61. height = format_info.get('height')
  62. fmt = {
  63. 'url': path,
  64. 'format_id': 'http%s' % ('-%dp' % height if height else ''),
  65. 'width': format_info.get('width'),
  66. 'height': height,
  67. }
  68. rtmp = re.search(r'^(?P<url>rtmpe?://[^/]+/(?P<app>.+))/(?P<playpath>mp4:.+)$', path)
  69. if rtmp:
  70. fmt.update({
  71. 'url': rtmp.group('url'),
  72. 'play_path': rtmp.group('playpath'),
  73. 'app': rtmp.group('app'),
  74. 'ext': 'flv',
  75. 'format_id': fmt['format_id'].replace('http', 'rtmp'),
  76. })
  77. formats.append(fmt)
  78. else:
  79. video_url = source.text
  80. if not video_url:
  81. continue
  82. if source.tag == 'tarball':
  83. formats.extend(self._extract_m3u8_formats(
  84. video_url.replace('.tar', '/base_index_w8.m3u8'),
  85. video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False))
  86. else:
  87. format_info = self._FORMATS_INFO.get(source.tag, {})
  88. formats.append({
  89. 'format_id': 'http-%s' % source.tag,
  90. 'url': video_url,
  91. 'width': format_info.get('width'),
  92. 'height': format_info.get('height'),
  93. })
  94. self._sort_formats(formats, ('width', 'height', 'tbr', 'format_id'))
  95. thumbnails = []
  96. card_sizes = xpath_element(video_data, 'titleCardSizes')
  97. if card_sizes is not None:
  98. for size in card_sizes:
  99. path = xpath_text(size, 'path')
  100. if not path:
  101. continue
  102. width = int_or_none(size.get('width'))
  103. thumbnails.append({
  104. 'id': width,
  105. 'url': path,
  106. 'width': width,
  107. })
  108. return {
  109. 'id': video_id,
  110. 'title': title,
  111. 'duration': parse_duration(xpath_element(video_data, 'duration/tv14')),
  112. 'formats': formats,
  113. 'thumbnails': thumbnails,
  114. }