logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

dvtv.py (7657B)


  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. try_get,
  12. unescapeHTML,
  13. parse_iso8601,
  14. )
  15. class DVTVIE(InfoExtractor):
  16. IE_NAME = 'dvtv'
  17. IE_DESC = 'http://video.aktualne.cz/'
  18. _VALID_URL = r'https?://video\.aktualne\.cz/(?:[^/]+/)+r~(?P<id>[0-9a-f]{32})'
  19. _TESTS = [{
  20. 'url': 'http://video.aktualne.cz/dvtv/vondra-o-ceskem-stoleti-pri-pohledu-na-havla-mi-bylo-trapne/r~e5efe9ca855511e4833a0025900fea04/',
  21. 'md5': '67cb83e4a955d36e1b5d31993134a0c2',
  22. 'info_dict': {
  23. 'id': 'dc0768de855511e49e4b0025900fea04',
  24. 'ext': 'mp4',
  25. 'title': 'Vondra o Českém století: Při pohledu na Havla mi bylo trapně',
  26. 'duration': 1484,
  27. 'upload_date': '20141217',
  28. 'timestamp': 1418792400,
  29. }
  30. }, {
  31. 'url': 'http://video.aktualne.cz/dvtv/dvtv-16-12-2014-utok-talibanu-boj-o-kliniku-uprchlici/r~973eb3bc854e11e498be002590604f2e/',
  32. 'info_dict': {
  33. 'title': r'DVTV 16. 12. 2014: útok Talibanu, boj o kliniku, uprchlíci',
  34. 'id': '973eb3bc854e11e498be002590604f2e',
  35. },
  36. 'playlist': [{
  37. 'md5': 'da7ca6be4935532241fa9520b3ad91e4',
  38. 'info_dict': {
  39. 'id': 'b0b40906854d11e4bdad0025900fea04',
  40. 'ext': 'mp4',
  41. 'title': 'Drtinová Veselovský TV 16. 12. 2014: Témata dne',
  42. 'description': 'md5:0916925dea8e30fe84222582280b47a0',
  43. 'timestamp': 1418760010,
  44. 'upload_date': '20141216',
  45. }
  46. }, {
  47. 'md5': '5f7652a08b05009c1292317b449ffea2',
  48. 'info_dict': {
  49. 'id': '420ad9ec854a11e4bdad0025900fea04',
  50. 'ext': 'mp4',
  51. 'title': 'Školní masakr možná změní boj s Talibanem, říká novinářka',
  52. 'description': 'md5:ff2f9f6de73c73d7cef4f756c1c1af42',
  53. 'timestamp': 1418760010,
  54. 'upload_date': '20141216',
  55. }
  56. }, {
  57. 'md5': '498eb9dfa97169f409126c617e2a3d64',
  58. 'info_dict': {
  59. 'id': '95d35580846a11e4b6d20025900fea04',
  60. 'ext': 'mp4',
  61. 'title': 'Boj o kliniku: Veřejný zájem, nebo právo na majetek?',
  62. 'description': 'md5:889fe610a70fee5511dc3326a089188e',
  63. 'timestamp': 1418760010,
  64. 'upload_date': '20141216',
  65. }
  66. }, {
  67. 'md5': 'b8dc6b744844032dab6ba3781a7274b9',
  68. 'info_dict': {
  69. 'id': '6fe14d66853511e4833a0025900fea04',
  70. 'ext': 'mp4',
  71. 'title': 'Pánek: Odmítání syrských uprchlíků je ostudou české vlády',
  72. 'description': 'md5:544f86de6d20c4815bea11bf2ac3004f',
  73. 'timestamp': 1418760010,
  74. 'upload_date': '20141216',
  75. }
  76. }],
  77. }, {
  78. 'url': 'https://video.aktualne.cz/dvtv/zeman-si-jen-leci-mindraky-sobotku-nenavidi-a-babis-se-mu-te/r~960cdb3a365a11e7a83b0025900fea04/',
  79. 'md5': 'f8efe9656017da948369aa099788c8ea',
  80. 'info_dict': {
  81. 'id': '3c496fec365911e7a6500025900fea04',
  82. 'ext': 'mp4',
  83. 'title': 'Zeman si jen léčí mindráky, Sobotku nenávidí a Babiš se mu teď hodí, tvrdí Kmenta',
  84. 'duration': 1103,
  85. 'upload_date': '20170511',
  86. 'timestamp': 1494514200,
  87. },
  88. 'params': {
  89. 'skip_download': True,
  90. },
  91. }, {
  92. 'url': 'http://video.aktualne.cz/v-cechach-poprve-zazni-zelenkova-zrestaurovana-mse/r~45b4b00483ec11e4883b002590604f2e/',
  93. 'only_matching': True,
  94. }, {
  95. # Test live stream video (liveStarter) parsing
  96. 'url': 'https://video.aktualne.cz/dvtv/zive-mistryne-sveta-eva-samkova-po-navratu-ze-sampionatu/r~182654c2288811e990fd0cc47ab5f122/',
  97. 'md5': '2e552e483f2414851ca50467054f9d5d',
  98. 'info_dict': {
  99. 'id': '8d116360288011e98c840cc47ab5f122',
  100. 'ext': 'mp4',
  101. 'title': 'Živě: Mistryně světa Eva Samková po návratu ze šampionátu',
  102. 'upload_date': '20190204',
  103. 'timestamp': 1549289591,
  104. },
  105. 'params': {
  106. # Video content is no longer available
  107. 'skip_download': True,
  108. },
  109. }]
  110. def _parse_video_metadata(self, js, video_id, timestamp):
  111. data = self._parse_json(js, video_id, transform_source=js_to_json)
  112. title = unescapeHTML(data['title'])
  113. live_starter = try_get(data, lambda x: x['plugins']['liveStarter'], dict)
  114. if live_starter:
  115. data.update(live_starter)
  116. formats = []
  117. for tracks in data.get('tracks', {}).values():
  118. for video in tracks:
  119. video_url = video.get('src')
  120. if not video_url:
  121. continue
  122. video_type = video.get('type')
  123. ext = determine_ext(video_url, mimetype2ext(video_type))
  124. if video_type == 'application/vnd.apple.mpegurl' or ext == 'm3u8':
  125. formats.extend(self._extract_m3u8_formats(
  126. video_url, video_id, 'mp4', entry_protocol='m3u8_native',
  127. m3u8_id='hls', fatal=False))
  128. elif video_type == 'application/dash+xml' or ext == 'mpd':
  129. formats.extend(self._extract_mpd_formats(
  130. video_url, video_id, mpd_id='dash', fatal=False))
  131. else:
  132. label = video.get('label')
  133. height = self._search_regex(
  134. r'^(\d+)[pP]', label or '', 'height', default=None)
  135. format_id = ['http']
  136. for f in (ext, label):
  137. if f:
  138. format_id.append(f)
  139. formats.append({
  140. 'url': video_url,
  141. 'format_id': '-'.join(format_id),
  142. 'height': int_or_none(height),
  143. })
  144. self._sort_formats(formats)
  145. return {
  146. 'id': data.get('mediaid') or video_id,
  147. 'title': title,
  148. 'description': data.get('description'),
  149. 'thumbnail': data.get('image'),
  150. 'duration': int_or_none(data.get('duration')),
  151. 'timestamp': int_or_none(timestamp),
  152. 'formats': formats
  153. }
  154. def _real_extract(self, url):
  155. video_id = self._match_id(url)
  156. webpage = self._download_webpage(url, video_id)
  157. timestamp = parse_iso8601(self._html_search_meta(
  158. 'article:published_time', webpage, 'published time', default=None))
  159. items = re.findall(r'(?s)playlist\.push\(({.+?})\);', webpage)
  160. if items:
  161. return self.playlist_result(
  162. [self._parse_video_metadata(i, video_id, timestamp) for i in items],
  163. video_id, self._html_search_meta('twitter:title', webpage))
  164. item = self._search_regex(
  165. r'(?s)BBXPlayer\.setup\((.+?)\);',
  166. webpage, 'video', default=None)
  167. if item:
  168. # remove function calls (ex. htmldeentitize)
  169. # TODO this should be fixed in a general way in the js_to_json
  170. item = re.sub(r'\w+?\((.+)\)', r'\1', item)
  171. return self._parse_video_metadata(item, video_id, timestamp)
  172. raise ExtractorError('Could not find neither video nor playlist')