playtvak.py 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. }, {
  72. 'url': 'http://www.playtvak.cz/embed.aspx?idvideo=V150729_141549_play-porad_kuko',
  73. 'only_matching': True,
  74. }]
  75. def _real_extract(self, url):
  76. video_id = self._match_id(url)
  77. webpage = self._download_webpage(url, video_id)
  78. info_url = self._html_search_regex(
  79. r'Misc\.videoFLV\(\s*{\s*data\s*:\s*"([^"]+)"', webpage, 'info url')
  80. parsed_url = compat_urlparse.urlparse(info_url)
  81. qs = compat_urlparse.parse_qs(parsed_url.query)
  82. qs.update({
  83. 'reklama': ['0'],
  84. 'type': ['js'],
  85. })
  86. info_url = compat_urlparse.urlunparse(
  87. parsed_url._replace(query = compat_urllib_parse.urlencode(qs, True)))
  88. json_info = self._download_json(
  89. info_url, video_id,
  90. transform_source=lambda s: s[s.index('{'):s.rindex('}') + 1])
  91. item = None
  92. for i in json_info['items']:
  93. if i.get('type') == 'video' or i.get('type') == 'stream':
  94. item = i
  95. break
  96. if not item:
  97. raise ExtractorError('No suitable stream found')
  98. quality = qualities(['low', 'middle', 'high'])
  99. formats = []
  100. for fmt in item['video']:
  101. video_url = fmt.get('file')
  102. if not video_url:
  103. continue
  104. format_ = fmt['format']
  105. format_id = '%s_%s' % (format_, fmt['quality'])
  106. preference = None
  107. if format_ in ['mp4', 'webm']:
  108. ext = format_
  109. elif format_ == 'rtmp':
  110. ext = 'flv'
  111. elif format_ == 'apple':
  112. ext = 'mp4'
  113. # Some streams have mp3 audio which does not play
  114. # well with ffmpeg filter aac_adtstoasc
  115. preference = -1
  116. elif format_ == 'adobe': # f4m manifest fails with 404 in 80% of requests
  117. continue
  118. else: # Other formats not supported yet
  119. continue
  120. formats.append({
  121. 'url': video_url,
  122. 'ext': ext,
  123. 'format_id': format_id,
  124. 'quality': quality(fmt.get('quality')),
  125. 'preference': preference,
  126. })
  127. self._sort_formats(formats)
  128. title = item['title']
  129. is_live = item['type'] == 'stream'
  130. if is_live:
  131. title = self._live_title(title)
  132. timestamp = None
  133. duration = None
  134. if not is_live:
  135. duration = int_or_none(item.get('length'))
  136. timestamp = item.get('published')
  137. if timestamp:
  138. timestamp = parse_iso8601(timestamp[:-5])
  139. return {
  140. 'id': video_id,
  141. 'title': title,
  142. 'description': self._og_search_description(webpage),
  143. 'thumbnail': item.get('image'),
  144. 'duration': duration,
  145. 'timestamp': timestamp,
  146. 'is_live': is_live,
  147. 'formats': formats,
  148. }