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.

69 lines
2.0 KiB

  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. determine_ext,
  8. js_to_json,
  9. parse_duration,
  10. remove_end,
  11. )
  12. class LRTIE(InfoExtractor):
  13. IE_NAME = 'lrt.lt'
  14. _VALID_URL = r'https?://(?:www\.)?lrt\.lt/mediateka/irasas/(?P<id>[0-9]+)'
  15. _TEST = {
  16. 'url': 'http://www.lrt.lt/mediateka/irasas/54391/',
  17. 'info_dict': {
  18. 'id': '54391',
  19. 'ext': 'mp4',
  20. 'title': 'Septynios Kauno dienos',
  21. 'description': 'Kauno miesto ir apskrities naujienos',
  22. 'duration': 1783,
  23. },
  24. 'params': {
  25. 'skip_download': True, # HLS download
  26. },
  27. }
  28. def _real_extract(self, url):
  29. mobj = re.match(self._VALID_URL, url)
  30. video_id = mobj.group('id')
  31. webpage = self._download_webpage(url, video_id)
  32. title = remove_end(self._og_search_title(webpage), ' - LRT')
  33. thumbnail = self._og_search_thumbnail(webpage)
  34. description = self._og_search_description(webpage)
  35. duration = parse_duration(self._search_regex(
  36. r"'duration':\s*'([^']+)',", webpage,
  37. 'duration', fatal=False, default=None))
  38. formats = []
  39. for js in re.findall(r'(?s)config:\s*(\{.*?\})', webpage):
  40. data = json.loads(js_to_json(js))
  41. if data['provider'] == 'rtmp':
  42. formats.append({
  43. 'format_id': 'rtmp',
  44. 'ext': determine_ext(data['file']),
  45. 'url': data['streamer'],
  46. 'play_path': 'mp4:%s' % data['file'],
  47. 'preference': -1,
  48. })
  49. else:
  50. formats.extend(
  51. self._extract_m3u8_formats(data['file'], video_id, 'mp4'))
  52. return {
  53. 'id': video_id,
  54. 'title': title,
  55. 'formats': formats,
  56. 'thumbnail': thumbnail,
  57. 'description': description,
  58. 'duration': duration,
  59. }