playtvak.py 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. import urllib.parse
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. ExtractorError,
  5. int_or_none,
  6. parse_iso8601,
  7. qualities,
  8. )
  9. class PlaytvakIE(InfoExtractor):
  10. IE_DESC = 'Playtvak.cz, iDNES.cz and Lidovky.cz'
  11. _VALID_URL = r'https?://(?:.+?\.)?(?:playtvak|idnes|lidovky|metro)\.cz/.*\?(?:c|idvideo)=(?P<id>[^&]+)'
  12. _TESTS = [{
  13. 'url': 'http://www.playtvak.cz/vyzente-vosy-a-srsne-ze-zahrady-dn5-/hodinovy-manzel.aspx?c=A150730_150323_hodinovy-manzel_kuko',
  14. 'md5': '4525ae312c324b4be2f4603cc78ceb4a',
  15. 'info_dict': {
  16. 'id': 'A150730_150323_hodinovy-manzel_kuko',
  17. 'ext': 'mp4',
  18. 'title': 'Vyžeňte vosy a sršně ze zahrady',
  19. 'description': 'md5:4436e61b7df227a093778efb7e373571',
  20. 'thumbnail': r're:(?i)^https?://.*\.(?:jpg|png)$',
  21. 'duration': 279,
  22. 'timestamp': 1438732860,
  23. 'upload_date': '20150805',
  24. 'is_live': False,
  25. },
  26. }, { # live video test
  27. 'url': 'http://slowtv.playtvak.cz/planespotting-0pr-/planespotting.aspx?c=A150624_164934_planespotting_cat',
  28. 'info_dict': {
  29. 'id': 'A150624_164934_planespotting_cat',
  30. 'ext': 'flv',
  31. 'title': 're:^Planespotting [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
  32. 'description': 'Sledujte provoz na ranveji Letiště Václava Havla v Praze',
  33. 'is_live': True,
  34. },
  35. 'params': {
  36. 'skip_download': True, # requires rtmpdump
  37. },
  38. }, { # another live stream, this one without Misc.videoFLV
  39. 'url': 'https://slowtv.playtvak.cz/zive-sledujte-vlaky-v-primem-prenosu-dwi-/hlavni-nadrazi.aspx?c=A151218_145728_hlavni-nadrazi_plap',
  40. 'info_dict': {
  41. 'id': 'A151218_145728_hlavni-nadrazi_plap',
  42. 'ext': 'flv',
  43. 'title': 're:^Hlavní nádraží [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
  44. 'is_live': True,
  45. },
  46. 'params': {
  47. 'skip_download': True, # requires rtmpdump
  48. },
  49. }, { # idnes.cz
  50. 'url': 'http://zpravy.idnes.cz/pes-zavreny-v-aute-rozbijeni-okynek-v-aute-fj5-/domaci.aspx?c=A150809_104116_domaci_pku',
  51. 'md5': '819832ba33cd7016e58a6658577fe289',
  52. 'info_dict': {
  53. 'id': 'A150809_104116_domaci_pku',
  54. 'ext': 'mp4',
  55. 'title': 'Zavřeli jsme mraženou pizzu do auta. Upekla se',
  56. 'description': 'md5:01e73f02329e2e5760bd5eed4d42e3c2',
  57. 'thumbnail': r're:(?i)^https?://.*\.(?:jpg|png)$',
  58. 'duration': 39,
  59. 'timestamp': 1438969140,
  60. 'upload_date': '20150807',
  61. 'is_live': False,
  62. },
  63. }, { # lidovky.cz
  64. 'url': 'http://www.lidovky.cz/dalsi-demonstrace-v-praze-o-migraci-duq-/video.aspx?c=A150808_214044_ln-video_ELE',
  65. 'md5': 'c7209ac4ba9d234d4ad5bab7485bcee8',
  66. 'info_dict': {
  67. 'id': 'A150808_214044_ln-video_ELE',
  68. 'ext': 'mp4',
  69. 'title': 'Táhni! Demonstrace proti imigrantům budila emoce',
  70. 'description': 'md5:97c81d589a9491fbfa323c9fa3cca72c',
  71. 'thumbnail': r're:(?i)^https?://.*\.(?:jpg|png)$',
  72. 'timestamp': 1439052180,
  73. 'upload_date': '20150808',
  74. 'is_live': False,
  75. },
  76. }, { # metro.cz
  77. 'url': 'http://www.metro.cz/video-pod-billboardem-se-na-vltavske-roztocil-kolotoc-deti-vozil-jen-par-hodin-1hx-/metro-extra.aspx?c=A141111_173251_metro-extra_row',
  78. 'md5': '84fc1deedcac37b7d4a6ccae7c716668',
  79. 'info_dict': {
  80. 'id': 'A141111_173251_metro-extra_row',
  81. 'ext': 'mp4',
  82. 'title': 'Recesisté udělali z billboardu kolotoč',
  83. 'description': 'md5:7369926049588c3989a66c9c1a043c4c',
  84. 'thumbnail': r're:(?i)^https?://.*\.(?:jpg|png)$',
  85. 'timestamp': 1415725500,
  86. 'upload_date': '20141111',
  87. 'is_live': False,
  88. },
  89. }, {
  90. 'url': 'http://www.playtvak.cz/embed.aspx?idvideo=V150729_141549_play-porad_kuko',
  91. 'only_matching': True,
  92. }]
  93. def _real_extract(self, url):
  94. video_id = self._match_id(url)
  95. webpage = self._download_webpage(url, video_id)
  96. info_url = self._html_search_regex(
  97. r'Misc\.video(?:FLV)?\(\s*{\s*data\s*:\s*"([^"]+)"', webpage, 'info url')
  98. parsed_url = urllib.parse.urlparse(info_url)
  99. qs = urllib.parse.parse_qs(parsed_url.query)
  100. qs.update({
  101. 'reklama': ['0'],
  102. 'type': ['js'],
  103. })
  104. info_url = urllib.parse.urlunparse(
  105. parsed_url._replace(query=urllib.parse.urlencode(qs, True)))
  106. json_info = self._download_json(
  107. info_url, video_id,
  108. transform_source=lambda s: s[s.index('{'):s.rindex('}') + 1])
  109. item = None
  110. for i in json_info['items']:
  111. if i.get('type') == 'video' or i.get('type') == 'stream':
  112. item = i
  113. break
  114. if not item:
  115. raise ExtractorError('No suitable stream found')
  116. quality = qualities(('low', 'middle', 'high'))
  117. formats = []
  118. for fmt in item['video']:
  119. video_url = fmt.get('file')
  120. if not video_url:
  121. continue
  122. format_ = fmt['format']
  123. format_id = '{}_{}'.format(format_, fmt['quality'])
  124. preference = None
  125. if format_ in ('mp4', 'webm'):
  126. ext = format_
  127. elif format_ == 'rtmp':
  128. ext = 'flv'
  129. elif format_ == 'apple':
  130. ext = 'mp4'
  131. # Some streams have mp3 audio which does not play
  132. # well with ffmpeg filter aac_adtstoasc
  133. preference = -10
  134. elif format_ == 'adobe': # f4m manifest fails with 404 in 80% of requests
  135. continue
  136. else: # Other formats not supported yet
  137. continue
  138. formats.append({
  139. 'url': video_url,
  140. 'ext': ext,
  141. 'format_id': format_id,
  142. 'quality': quality(fmt.get('quality')),
  143. 'preference': preference,
  144. })
  145. title = item['title']
  146. is_live = item['type'] == 'stream'
  147. description = self._og_search_description(webpage, default=None) or self._html_search_meta(
  148. 'description', webpage, 'description', default=None)
  149. timestamp = None
  150. duration = None
  151. if not is_live:
  152. duration = int_or_none(item.get('length'))
  153. timestamp = item.get('published')
  154. if timestamp:
  155. timestamp = parse_iso8601(timestamp[:-5])
  156. return {
  157. 'id': video_id,
  158. 'title': title,
  159. 'description': description,
  160. 'thumbnail': item.get('image'),
  161. 'duration': duration,
  162. 'timestamp': timestamp,
  163. 'is_live': is_live,
  164. 'formats': formats,
  165. }