125 lines
4.4 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. js_to_json,
  7. unescapeHTML,
  8. ExtractorError,
  9. )
  10. class DVTVIE(InfoExtractor):
  11. IE_NAME = 'dvtv'
  12. IE_DESC = 'http://video.aktualne.cz/'
  13. _VALID_URL = r'http://video\.aktualne\.cz/(?:[^/]+/)+r~(?P<id>[0-9a-f]{32})'
  14. _TESTS = [{
  15. 'url': 'http://video.aktualne.cz/dvtv/vondra-o-ceskem-stoleti-pri-pohledu-na-havla-mi-bylo-trapne/r~e5efe9ca855511e4833a0025900fea04/',
  16. 'md5': '67cb83e4a955d36e1b5d31993134a0c2',
  17. 'info_dict': {
  18. 'id': 'dc0768de855511e49e4b0025900fea04',
  19. 'ext': 'mp4',
  20. 'title': 'Vondra o Českém století: Při pohledu na Havla mi bylo trapně',
  21. }
  22. }, {
  23. 'url': 'http://video.aktualne.cz/dvtv/stropnicky-policie-vrbetice-preventivne-nekontrolovala/r~82ed4322849211e4a10c0025900fea04/',
  24. 'md5': '6388f1941b48537dbd28791f712af8bf',
  25. 'info_dict': {
  26. 'id': '72c02230849211e49f60002590604f2e',
  27. 'ext': 'mp4',
  28. 'title': 'Stropnický: Policie Vrbětice preventivně nekontrolovala',
  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': '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. }
  43. }, {
  44. 'md5': '5f7652a08b05009c1292317b449ffea2',
  45. 'info_dict': {
  46. 'id': '420ad9ec854a11e4bdad0025900fea04',
  47. 'ext': 'mp4',
  48. 'title': 'Školní masakr možná změní boj s Talibanem, říká novinářka'
  49. }
  50. }, {
  51. 'md5': '498eb9dfa97169f409126c617e2a3d64',
  52. 'info_dict': {
  53. 'id': '95d35580846a11e4b6d20025900fea04',
  54. 'ext': 'mp4',
  55. 'title': 'Boj o kliniku: Veřejný zájem, nebo právo na majetek?'
  56. }
  57. }, {
  58. 'md5': 'b8dc6b744844032dab6ba3781a7274b9',
  59. 'info_dict': {
  60. 'id': '6fe14d66853511e4833a0025900fea04',
  61. 'ext': 'mp4',
  62. 'title': 'Pánek: Odmítání syrských uprchlíků je ostudou české vlády'
  63. }
  64. }],
  65. }, {
  66. 'url': 'http://video.aktualne.cz/v-cechach-poprve-zazni-zelenkova-zrestaurovana-mse/r~45b4b00483ec11e4883b002590604f2e/',
  67. 'only_matching': True,
  68. }]
  69. def _parse_video_metadata(self, js, video_id):
  70. metadata = self._parse_json(js, video_id, transform_source=js_to_json)
  71. formats = []
  72. for video in metadata['sources']:
  73. ext = video['type'][6:]
  74. formats.append({
  75. 'url': video['file'],
  76. 'ext': ext,
  77. 'format_id': '%s-%s' % (ext, video['label']),
  78. 'height': int(video['label'].rstrip('p')),
  79. 'fps': 25,
  80. })
  81. self._sort_formats(formats)
  82. return {
  83. 'id': metadata['mediaid'],
  84. 'title': unescapeHTML(metadata['title']),
  85. 'thumbnail': self._proto_relative_url(metadata['image'], 'http:'),
  86. 'formats': formats
  87. }
  88. def _real_extract(self, url):
  89. video_id = self._match_id(url)
  90. webpage = self._download_webpage(url, video_id)
  91. # single video
  92. item = self._search_regex(
  93. r"(?s)embedData[0-9a-f]{32}\['asset'\]\s*=\s*(\{.+?\});",
  94. webpage, 'video', default=None, fatal=False)
  95. if item:
  96. return self._parse_video_metadata(item, video_id)
  97. # playlist
  98. items = re.findall(
  99. r"(?s)BBX\.context\.assets\['[0-9a-f]{32}'\]\.push\(({.+?})\);",
  100. webpage)
  101. if items:
  102. return {
  103. '_type': 'playlist',
  104. 'id': video_id,
  105. 'title': self._og_search_title(webpage),
  106. 'entries': [self._parse_video_metadata(i, video_id) for i in items]
  107. }
  108. raise ExtractorError('Could not find neither video nor playlist')