dvtv.py 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. determine_ext,
  7. ExtractorError,
  8. int_or_none,
  9. js_to_json,
  10. mimetype2ext,
  11. unescapeHTML,
  12. )
  13. class DVTVIE(InfoExtractor):
  14. IE_NAME = 'dvtv'
  15. IE_DESC = 'http://video.aktualne.cz/'
  16. _VALID_URL = r'https?://video\.aktualne\.cz/(?:[^/]+/)+r~(?P<id>[0-9a-f]{32})'
  17. _TESTS = [{
  18. 'url': 'http://video.aktualne.cz/dvtv/vondra-o-ceskem-stoleti-pri-pohledu-na-havla-mi-bylo-trapne/r~e5efe9ca855511e4833a0025900fea04/',
  19. 'md5': '67cb83e4a955d36e1b5d31993134a0c2',
  20. 'info_dict': {
  21. 'id': 'dc0768de855511e49e4b0025900fea04',
  22. 'ext': 'mp4',
  23. 'title': 'Vondra o Českém století: Při pohledu na Havla mi bylo trapně',
  24. 'duration': 1484,
  25. }
  26. }, {
  27. 'url': 'http://video.aktualne.cz/dvtv/dvtv-16-12-2014-utok-talibanu-boj-o-kliniku-uprchlici/r~973eb3bc854e11e498be002590604f2e/',
  28. 'info_dict': {
  29. 'title': r're:^DVTV 16\. 12\. 2014: útok Talibanu, boj o kliniku, uprchlíci',
  30. 'id': '973eb3bc854e11e498be002590604f2e',
  31. },
  32. 'playlist': [{
  33. 'md5': 'da7ca6be4935532241fa9520b3ad91e4',
  34. 'info_dict': {
  35. 'id': 'b0b40906854d11e4bdad0025900fea04',
  36. 'ext': 'mp4',
  37. 'title': 'Drtinová Veselovský TV 16. 12. 2014: Témata dne',
  38. 'description': 'md5:0916925dea8e30fe84222582280b47a0',
  39. 'timestamp': 1418760010,
  40. 'upload_date': '20141216',
  41. }
  42. }, {
  43. 'md5': '5f7652a08b05009c1292317b449ffea2',
  44. 'info_dict': {
  45. 'id': '420ad9ec854a11e4bdad0025900fea04',
  46. 'ext': 'mp4',
  47. 'title': 'Školní masakr možná změní boj s Talibanem, říká novinářka',
  48. 'description': 'md5:ff2f9f6de73c73d7cef4f756c1c1af42',
  49. 'timestamp': 1418760010,
  50. 'upload_date': '20141216',
  51. }
  52. }, {
  53. 'md5': '498eb9dfa97169f409126c617e2a3d64',
  54. 'info_dict': {
  55. 'id': '95d35580846a11e4b6d20025900fea04',
  56. 'ext': 'mp4',
  57. 'title': 'Boj o kliniku: Veřejný zájem, nebo právo na majetek?',
  58. 'description': 'md5:889fe610a70fee5511dc3326a089188e',
  59. 'timestamp': 1418760010,
  60. 'upload_date': '20141216',
  61. }
  62. }, {
  63. 'md5': 'b8dc6b744844032dab6ba3781a7274b9',
  64. 'info_dict': {
  65. 'id': '6fe14d66853511e4833a0025900fea04',
  66. 'ext': 'mp4',
  67. 'title': 'Pánek: Odmítání syrských uprchlíků je ostudou české vlády',
  68. 'description': 'md5:544f86de6d20c4815bea11bf2ac3004f',
  69. 'timestamp': 1418760010,
  70. 'upload_date': '20141216',
  71. }
  72. }],
  73. }, {
  74. 'url': 'https://video.aktualne.cz/dvtv/zeman-si-jen-leci-mindraky-sobotku-nenavidi-a-babis-se-mu-te/r~960cdb3a365a11e7a83b0025900fea04/',
  75. 'md5': 'f8efe9656017da948369aa099788c8ea',
  76. 'info_dict': {
  77. 'id': '3c496fec365911e7a6500025900fea04',
  78. 'ext': 'mp4',
  79. 'title': 'Zeman si jen léčí mindráky, Sobotku nenávidí a Babiš se mu teď hodí, tvrdí Kmenta',
  80. 'duration': 1103,
  81. },
  82. 'params': {
  83. 'skip_download': True,
  84. },
  85. }, {
  86. 'url': 'http://video.aktualne.cz/v-cechach-poprve-zazni-zelenkova-zrestaurovana-mse/r~45b4b00483ec11e4883b002590604f2e/',
  87. 'only_matching': True,
  88. }, {
  89. 'url': 'https://video.aktualne.cz/dvtv/babis-a-zeman-nesou-vinu-za-to-ze-nemame-jasno-v-tom-kdo-bud/r~026afb54fad711e79704ac1f6b220ee8/',
  90. 'md5': '87defe16681b1429c91f7a74809823c6',
  91. 'info_dict': {
  92. 'id': 'f5ae72f6fad611e794dbac1f6b220ee8',
  93. 'ext': 'mp4',
  94. 'title': 'Babiš a Zeman nesou vinu za to, že nemáme jasno v tom, kdo bude vládnout, říká Pekarová Adamová',
  95. },
  96. 'params': {
  97. 'skip_download': True,
  98. },
  99. }]
  100. def _parse_video_metadata(self, js, video_id, live_js=None):
  101. data = self._parse_json(js, video_id, transform_source=js_to_json)
  102. if live_js:
  103. data.update(self._parse_json(
  104. live_js, video_id, transform_source=js_to_json))
  105. title = unescapeHTML(data['title'])
  106. formats = []
  107. for video in data['sources']:
  108. video_url = video.get('file')
  109. if not video_url:
  110. continue
  111. video_type = video.get('type')
  112. ext = determine_ext(video_url, mimetype2ext(video_type))
  113. if video_type == 'application/vnd.apple.mpegurl' or ext == 'm3u8':
  114. formats.extend(self._extract_m3u8_formats(
  115. video_url, video_id, 'mp4', entry_protocol='m3u8_native',
  116. m3u8_id='hls', fatal=False))
  117. elif video_type == 'application/dash+xml' or ext == 'mpd':
  118. formats.extend(self._extract_mpd_formats(
  119. video_url, video_id, mpd_id='dash', fatal=False))
  120. else:
  121. label = video.get('label')
  122. height = self._search_regex(
  123. r'^(\d+)[pP]', label or '', 'height', default=None)
  124. format_id = ['http']
  125. for f in (ext, label):
  126. if f:
  127. format_id.append(f)
  128. formats.append({
  129. 'url': video_url,
  130. 'format_id': '-'.join(format_id),
  131. 'height': int_or_none(height),
  132. })
  133. self._sort_formats(formats)
  134. return {
  135. 'id': data.get('mediaid') or video_id,
  136. 'title': title,
  137. 'description': data.get('description'),
  138. 'thumbnail': data.get('image'),
  139. 'duration': int_or_none(data.get('duration')),
  140. 'timestamp': int_or_none(data.get('pubtime')),
  141. 'formats': formats
  142. }
  143. def _real_extract(self, url):
  144. video_id = self._match_id(url)
  145. webpage = self._download_webpage(url, video_id)
  146. # live content
  147. live_item = self._search_regex(
  148. r'(?s)embedData[0-9a-f]{32}\.asset\.liveStarter\s*=\s*(\{.+?\});',
  149. webpage, 'video', default=None)
  150. # single video
  151. item = self._search_regex(
  152. r'(?s)embedData[0-9a-f]{32}\[["\']asset["\']\]\s*=\s*(\{.+?\});',
  153. webpage, 'video', default=None)
  154. if item:
  155. return self._parse_video_metadata(item, video_id, live_item)
  156. # playlist
  157. items = re.findall(
  158. r"(?s)BBX\.context\.assets\['[0-9a-f]{32}'\]\.push\(({.+?})\);",
  159. webpage)
  160. if not items:
  161. items = re.findall(r'(?s)var\s+asset\s*=\s*({.+?});\n', webpage)
  162. if items:
  163. return {
  164. '_type': 'playlist',
  165. 'id': video_id,
  166. 'title': self._og_search_title(webpage),
  167. 'entries': [self._parse_video_metadata(i, video_id) for i in items]
  168. }
  169. raise ExtractorError('Could not find neither video nor playlist')