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.

191 lines
7.1 KiB

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