81 lines
3.0 KiB
Python
Raw Normal View History

2014-09-30 02:26:16 +03:00
# coding: utf-8
from __future__ import unicode_literals
from .common import InfoExtractor
from ..utils import (
2019-09-16 17:22:11 -07:00
unified_timestamp,
clean_html,
ExtractorError,
try_get,
2014-09-30 02:26:16 +03:00
)
class LRTIE(InfoExtractor):
IE_NAME = 'lrt.lt'
_VALID_URL = r'https?://(?:www\.)?lrt\.lt/mediateka/irasas/(?P<id>[0-9]+)'
_TESTS = [{
# m3u8 download
2019-09-16 17:22:11 -07:00
'url': 'https://www.lrt.lt/mediateka/irasas/2000078895/loterija-keno-loto',
# md5 for first 10240 bytes of content
'md5': '8e6f0121ccacc17d91f98837c66853f0',
2014-09-30 02:26:16 +03:00
'info_dict': {
2019-09-16 17:22:11 -07:00
'id': '2000078895',
2014-09-30 02:26:16 +03:00
'ext': 'mp4',
2019-09-16 17:52:47 -07:00
'title': 'Loterija \u201eKeno Loto\u201c',
'description': 'Tira\u017eo nr.: 7993.',
2019-09-16 17:22:11 -07:00
'timestamp': 1568658420,
2019-09-16 17:52:47 -07:00
'tags': ['Loterija \u201eKeno Loto\u201c', 'LRT TELEVIZIJA'],
2019-09-16 17:22:11 -07:00
'upload_date': '20190916',
2014-09-30 02:26:16 +03:00
},
}, {
2019-09-16 17:22:11 -07:00
# m4a download
'url': 'https://www.lrt.lt/mediateka/irasas/2000068931/vakaro-pasaka-bebriukas',
# md5 for first 11297 bytes of content
'md5': 'f02072fb3c416c1c8f5969ea7b70f53b',
'info_dict': {
2019-09-16 17:22:11 -07:00
'id': '2000068931',
'ext': 'm4a',
2019-09-16 17:52:47 -07:00
'title': 'Vakaro pasaka. Bebriukas',
'description': 'Est\u0173 pasaka \u201eBebriukas\u201d. Skaito aktorius Antanas \u0160urna.',
2019-09-16 17:22:11 -07:00
'timestamp': 1558461780,
2019-09-16 17:52:47 -07:00
'tags': ['LRT RADIJAS', 'Vakaro pasaka', 'Bebriukas'],
2019-09-16 17:22:11 -07:00
'upload_date': '20190521',
2014-09-30 02:26:16 +03:00
},
}]
2014-09-30 02:26:16 +03:00
2019-09-16 17:22:11 -07:00
MEDIA_INFO_URL = 'https://www.lrt.lt/servisai/stream_url/vod/media_info/'
THUMBNAIL_URL = 'https://www.lrt.lt'
QUERY_URL = '/mediateka/irasas/'
2014-09-30 02:26:16 +03:00
def _real_extract(self, url):
2014-10-27 02:27:49 +01:00
video_id = self._match_id(url)
2019-09-16 17:22:11 -07:00
media_info = self._download_json(self.MEDIA_INFO_URL, video_id, query={'url': self.QUERY_URL + video_id})
2014-09-30 02:26:16 +03:00
2019-09-16 17:22:11 -07:00
video_id = try_get(media_info, lambda x: x.get('id'), int)
if not video_id:
raise ExtractorError("Unable to fetch media info")
2019-09-16 17:22:11 -07:00
playlist_item = media_info.get('playlist_item', {})
file = playlist_item.get('file')
if not file:
raise ExtractorError("Media info did not contain m3u8 file url")
2015-12-27 12:16:55 +06:00
2019-09-16 17:22:11 -07:00
if ".m4a" in file:
# audio only content
formats = [{'url': file, 'vcodec': 'none', 'ext': 'm4a'}]
else:
formats = self._extract_m3u8_formats(file, video_id, 'mp4', entry_protocol='m3u8_native')
2014-09-30 02:26:16 +03:00
2019-09-16 17:22:11 -07:00
# adjust media datetime to youtube_dl supported datetime format
timestamp = unified_timestamp(media_info.get('date').replace('.', '-') + '+02:00')
2015-12-27 12:26:48 +06:00
2014-09-30 02:26:16 +03:00
return {
2019-09-16 17:22:11 -07:00
'id': str(video_id).decode('utf-8'),
'title': playlist_item.get('title', 'unknown title'),
2014-09-30 02:26:16 +03:00
'formats': formats,
2019-09-16 17:22:11 -07:00
'thumbnail': self.THUMBNAIL_URL + playlist_item.get('image', '/images/default-img.svg'),
'description': clean_html(media_info.get('content', 'unknown description')),
'timestamp': timestamp,
'tags': [i['name'] for i in media_info.get('tags')] if media_info.get('tags') else [],
2014-09-30 02:26:16 +03:00
}