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.

68 lines
2.1 KiB

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