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.

67 lines
2.0 KiB

10 years ago
  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': 'md5:24d84534c7dc76581e59f5689462411a',
  22. 'duration': 1783,
  23. },
  24. 'params': {
  25. 'skip_download': True, # HLS download
  26. },
  27. }
  28. def _real_extract(self, url):
  29. video_id = self._match_id(url)
  30. webpage = self._download_webpage(url, video_id)
  31. title = remove_end(self._og_search_title(webpage), ' - LRT')
  32. thumbnail = self._og_search_thumbnail(webpage)
  33. description = self._og_search_description(webpage)
  34. duration = parse_duration(self._search_regex(
  35. r"'duration':\s*'([^']+)',", webpage,
  36. 'duration', fatal=False, default=None))
  37. formats = []
  38. for js in re.findall(r'(?s)config:\s*(\{.*?\})', webpage):
  39. data = json.loads(js_to_json(js))
  40. if data['provider'] == 'rtmp':
  41. formats.append({
  42. 'format_id': 'rtmp',
  43. 'ext': determine_ext(data['file']),
  44. 'url': data['streamer'],
  45. 'play_path': 'mp4:%s' % data['file'],
  46. 'preference': -1,
  47. })
  48. else:
  49. formats.extend(
  50. self._extract_m3u8_formats(data['file'], video_id, 'mp4'))
  51. return {
  52. 'id': video_id,
  53. 'title': title,
  54. 'formats': formats,
  55. 'thumbnail': thumbnail,
  56. 'description': description,
  57. 'duration': duration,
  58. }