dvtv.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. import json
  5. from .common import InfoExtractor
  6. from ..utils import (
  7. ExtractorError,
  8. js_to_json,
  9. unescapeHTML
  10. )
  11. class DVTVIE(InfoExtractor):
  12. IE_NAME = 'dvtv'
  13. IE_DESC = 'http://video.aktualne.cz/dvtv/'
  14. _VALID_URL = r'http://video\.aktualne\.cz/dvtv/(?P<id>[a-z0-9-]+/r~[0-9a-f]{32})/?'
  15. _TESTS = [{
  16. 'url': 'http://video.aktualne.cz/dvtv/vondra-o-ceskem-stoleti-pri-pohledu-na-havla-mi-bylo-trapne/r~e5efe9ca855511e4833a0025900fea04/',
  17. 'md5': '75800f964fa0f82939a2914563301f72',
  18. 'info_dict': {
  19. 'id': 'e5efe9ca855511e4833a0025900fea04',
  20. 'ext': 'webm',
  21. 'title': 'Vondra o Českém století: Při pohledu na Havla mi bylo trapně'
  22. }
  23. }, {
  24. 'url': 'http://video.aktualne.cz/dvtv/stropnicky-policie-vrbetice-preventivne-nekontrolovala/r~82ed4322849211e4a10c0025900fea04/',
  25. 'md5': 'd50455195a67a94c57f931360cc68a1b',
  26. 'info_dict': {
  27. 'id': '82ed4322849211e4a10c0025900fea04',
  28. 'ext': 'webm',
  29. 'title': 'Stropnický: Policie Vrbětice preventivně nekontrolovala'
  30. }
  31. }]
  32. def _real_extract(self, url):
  33. video_id = self._match_id(url)
  34. webpage = self._download_webpage(url, video_id)
  35. code = self._search_regex(r'embedData[0-9a-f]{32}\[\'asset\'\] = (\{.+?\});', webpage, 'video JSON', flags=re.DOTALL)
  36. payload = self._parse_json(code, video_id, transform_source=js_to_json)
  37. formats = []
  38. for source in payload['sources']:
  39. formats.append({
  40. 'url': source['file'],
  41. 'ext': source['type'][6:],
  42. 'format': '%s %s' % (source['type'][6:], source['label']),
  43. 'format_id': '%s-%s' % (source['type'][6:], source['label']),
  44. 'resolution': source['label'],
  45. 'fps': 25,
  46. 'preference': -1 if source['type'][6:] == 'mp4' and source['label'] == '720p' else -2
  47. })
  48. return {
  49. 'id': video_id[-32:],
  50. 'display_id': video_id[:-35],
  51. 'title': unescapeHTML(payload['title']),
  52. 'thumbnail': 'http:%s' % payload['image'],
  53. 'formats': formats
  54. }