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.

181 lines
6.6 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,
  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:f93d398691044d303bc4a3de62f3e976',
  25. 'thumbnail': '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:^Přímý přenos iDNES.cz [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. 'thumbnail': 're:(?i)^https?://.*\.(?:jpg|png)$',
  39. 'is_live': True,
  40. },
  41. 'params': {
  42. 'skip_download': True, # requires rtmpdump
  43. },
  44. }, { # idnes.cz
  45. 'url': 'http://zpravy.idnes.cz/pes-zavreny-v-aute-rozbijeni-okynek-v-aute-fj5-/domaci.aspx?c=A150809_104116_domaci_pku',
  46. 'md5': '819832ba33cd7016e58a6658577fe289',
  47. 'info_dict': {
  48. 'id': 'A150809_104116_domaci_pku',
  49. 'ext': 'mp4',
  50. 'title': 'Zavřeli jsme mraženou pizzu do auta. Upekla se',
  51. 'description': 'md5:01e73f02329e2e5760bd5eed4d42e3c2',
  52. 'thumbnail': 're:(?i)^https?://.*\.(?:jpg|png)$',
  53. 'duration': 39,
  54. 'timestamp': 1438969140,
  55. 'upload_date': '20150807',
  56. 'is_live': False,
  57. }
  58. }, { # lidovky.cz
  59. 'url': 'http://www.lidovky.cz/dalsi-demonstrace-v-praze-o-migraci-duq-/video.aspx?c=A150808_214044_ln-video_ELE',
  60. 'md5': 'c7209ac4ba9d234d4ad5bab7485bcee8',
  61. 'info_dict': {
  62. 'id': 'A150808_214044_ln-video_ELE',
  63. 'ext': 'mp4',
  64. 'title': 'Táhni! Demonstrace proti imigrantům budila emoce',
  65. 'description': 'md5:97c81d589a9491fbfa323c9fa3cca72c',
  66. 'thumbnail': 're:(?i)^https?://.*\.(?:jpg|png)$',
  67. 'timestamp': 1439052180,
  68. 'upload_date': '20150808',
  69. 'is_live': False,
  70. }
  71. }, { # metro.cz
  72. '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',
  73. 'md5': '84fc1deedcac37b7d4a6ccae7c716668',
  74. 'info_dict': {
  75. 'id': 'A141111_173251_metro-extra_row',
  76. 'ext': 'mp4',
  77. 'title': 'Recesisté udělali z billboardu kolotoč',
  78. 'description': 'md5:7369926049588c3989a66c9c1a043c4c',
  79. 'thumbnail': 're:(?i)^https?://.*\.(?:jpg|png)$',
  80. 'timestamp': 1415725500,
  81. 'upload_date': '20141111',
  82. 'is_live': False,
  83. }
  84. }, {
  85. 'url': 'http://www.playtvak.cz/embed.aspx?idvideo=V150729_141549_play-porad_kuko',
  86. 'only_matching': True,
  87. }]
  88. def _real_extract(self, url):
  89. video_id = self._match_id(url)
  90. webpage = self._download_webpage(url, video_id)
  91. info_url = self._html_search_regex(
  92. r'Misc\.videoFLV\(\s*{\s*data\s*:\s*"([^"]+)"', webpage, 'info url')
  93. parsed_url = compat_urlparse.urlparse(info_url)
  94. qs = compat_urlparse.parse_qs(parsed_url.query)
  95. qs.update({
  96. 'reklama': ['0'],
  97. 'type': ['js'],
  98. })
  99. info_url = compat_urlparse.urlunparse(
  100. parsed_url._replace(query = compat_urllib_parse.urlencode(qs, True)))
  101. json_info = self._download_json(
  102. info_url, video_id,
  103. transform_source=lambda s: s[s.index('{'):s.rindex('}') + 1])
  104. item = None
  105. for i in json_info['items']:
  106. if i.get('type') == 'video' or i.get('type') == 'stream':
  107. item = i
  108. break
  109. if not item:
  110. raise ExtractorError('No suitable stream found')
  111. quality = qualities(('low', 'middle', 'high'))
  112. formats = []
  113. for fmt in item['video']:
  114. video_url = fmt.get('file')
  115. if not video_url:
  116. continue
  117. format_ = fmt['format']
  118. format_id = '%s_%s' % (format_, fmt['quality'])
  119. preference = None
  120. if format_ in ('mp4', 'webm'):
  121. ext = format_
  122. elif format_ == 'rtmp':
  123. ext = 'flv'
  124. elif format_ == 'apple':
  125. ext = 'mp4'
  126. # Some streams have mp3 audio which does not play
  127. # well with ffmpeg filter aac_adtstoasc
  128. preference = -1
  129. elif format_ == 'adobe': # f4m manifest fails with 404 in 80% of requests
  130. continue
  131. else: # Other formats not supported yet
  132. continue
  133. formats.append({
  134. 'url': video_url,
  135. 'ext': ext,
  136. 'format_id': format_id,
  137. 'quality': quality(fmt.get('quality')),
  138. 'preference': preference,
  139. })
  140. self._sort_formats(formats)
  141. title = item['title']
  142. is_live = item['type'] == 'stream'
  143. if is_live:
  144. title = self._live_title(title)
  145. description = self._og_search_description(webpage, default=None) or self._html_search_meta(
  146. 'description', webpage, 'description')
  147. timestamp = None
  148. duration = None
  149. if not is_live:
  150. duration = int_or_none(item.get('length'))
  151. timestamp = item.get('published')
  152. if timestamp:
  153. timestamp = parse_iso8601(timestamp[:-5])
  154. return {
  155. 'id': video_id,
  156. 'title': title,
  157. 'description': description,
  158. 'thumbnail': item.get('image'),
  159. 'duration': duration,
  160. 'timestamp': timestamp,
  161. 'is_live': is_live,
  162. 'formats': formats,
  163. }