logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

lrt.py (2583B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. clean_html,
  7. merge_dicts,
  8. )
  9. class LRTIE(InfoExtractor):
  10. IE_NAME = 'lrt.lt'
  11. _VALID_URL = r'https?://(?:www\.)?lrt\.lt(?P<path>/mediateka/irasas/(?P<id>[0-9]+))'
  12. _TESTS = [{
  13. # m3u8 download
  14. 'url': 'https://www.lrt.lt/mediateka/irasas/2000127261/greita-ir-gardu-sicilijos-ikvepta-klasikiniu-makaronu-su-baklazanais-vakariene',
  15. 'md5': '85cb2bb530f31d91a9c65b479516ade4',
  16. 'info_dict': {
  17. 'id': '2000127261',
  18. 'ext': 'mp4',
  19. 'title': 'Greita ir gardu: Sicilijos įkvėpta klasikinių makaronų su baklažanais vakarienė',
  20. 'description': 'md5:ad7d985f51b0dc1489ba2d76d7ed47fa',
  21. 'duration': 3035,
  22. 'timestamp': 1604079000,
  23. 'upload_date': '20201030',
  24. },
  25. }, {
  26. # direct mp3 download
  27. 'url': 'http://www.lrt.lt/mediateka/irasas/1013074524/',
  28. 'md5': '389da8ca3cad0f51d12bed0c844f6a0a',
  29. 'info_dict': {
  30. 'id': '1013074524',
  31. 'ext': 'mp3',
  32. 'title': 'Kita tema 2016-09-05 15:05',
  33. 'description': 'md5:1b295a8fc7219ed0d543fc228c931fb5',
  34. 'duration': 3008,
  35. 'view_count': int,
  36. 'like_count': int,
  37. },
  38. }]
  39. def _extract_js_var(self, webpage, var_name, default):
  40. return self._search_regex(
  41. r'%s\s*=\s*(["\'])((?:(?!\1).)+)\1' % var_name,
  42. webpage, var_name.replace('_', ' '), default, group=2)
  43. def _real_extract(self, url):
  44. path, video_id = re.match(self._VALID_URL, url).groups()
  45. webpage = self._download_webpage(url, video_id)
  46. media_url = self._extract_js_var(webpage, 'main_url', path)
  47. media = self._download_json(self._extract_js_var(
  48. webpage, 'media_info_url',
  49. 'https://www.lrt.lt/servisai/stream_url/vod/media_info/'),
  50. video_id, query={'url': media_url})
  51. jw_data = self._parse_jwplayer_data(
  52. media['playlist_item'], video_id, base_url=url)
  53. json_ld_data = self._search_json_ld(webpage, video_id)
  54. tags = []
  55. for tag in (media.get('tags') or []):
  56. tag_name = tag.get('name')
  57. if not tag_name:
  58. continue
  59. tags.append(tag_name)
  60. clean_info = {
  61. 'description': clean_html(media.get('content')),
  62. 'tags': tags,
  63. }
  64. return merge_dicts(clean_info, jw_data, json_ld_data)