1
0
mirror of https://codeberg.org/polarisfm/youtube-dl synced 2024-11-23 08:54:33 +01:00
youtube-dl/youtube_dl/extractor/lnkgo.py

89 lines
3.1 KiB
Python
Raw Normal View History

2015-01-13 23:14:59 +01:00
# coding: utf-8
from __future__ import unicode_literals
import re
from .common import InfoExtractor
from ..utils import (
2019-11-06 23:14:26 +01:00
clean_html,
compat_str,
2015-01-13 23:14:59 +01:00
int_or_none,
2019-11-06 23:14:26 +01:00
parse_iso8601,
2015-01-13 23:14:59 +01:00
)
class LnkGoIE(InfoExtractor):
2019-11-06 23:14:26 +01:00
_VALID_URL = r'https?://(?:www\.)?lnk(?:go)?\.(?:alfa\.)?lt/(?:visi-video/[^/]+|video)/(?P<id>[A-Za-z0-9-]+)(?:/(?P<episode_id>\d+))?'
2015-01-13 23:14:59 +01:00
_TESTS = [{
2019-11-06 23:14:26 +01:00
'url': 'http://www.lnkgo.lt/visi-video/aktualai-pratesimas/ziurek-putka-trys-klausimai',
2015-01-13 23:14:59 +01:00
'info_dict': {
2019-11-06 23:14:26 +01:00
'id': '10809',
2015-01-13 23:14:59 +01:00
'ext': 'mp4',
2019-11-06 23:14:26 +01:00
'title': "Put'ka: Trys Klausimai",
'upload_date': '20161216',
'description': 'Seniai matytas Putka užduoda tris klausimėlius. Pabandykime surasti atsakymus.',
'age_limit': 18,
'duration': 117,
'thumbnail': r're:^https?://.*\.jpg$',
'timestamp': 1481904000,
2015-01-13 23:14:59 +01:00
},
'params': {
'skip_download': True, # HLS download
},
}, {
'url': 'http://lnkgo.alfa.lt/visi-video/aktualai-pratesimas/ziurek-nerdas-taiso-kompiuteri-2',
'info_dict': {
2019-11-06 23:14:26 +01:00
'id': '10467',
2015-01-13 23:14:59 +01:00
'ext': 'mp4',
'title': 'Nėrdas: Kompiuterio Valymas',
'upload_date': '20150113',
'description': 'md5:7352d113a242a808676ff17e69db6a69',
'age_limit': 18,
'duration': 346,
2019-11-06 23:14:26 +01:00
'thumbnail': r're:^https?://.*\.jpg$',
'timestamp': 1421164800,
2015-01-13 23:14:59 +01:00
},
'params': {
'skip_download': True, # HLS download
},
2017-10-06 18:59:09 +02:00
}, {
2019-11-06 23:14:26 +01:00
'url': 'https://lnk.lt/video/neigalieji-tv-bokste/37413',
2017-10-06 18:59:09 +02:00
'only_matching': True,
2015-01-13 23:14:59 +01:00
}]
_AGE_LIMITS = {
'N-7': 7,
'N-14': 14,
'S': 18,
}
2019-11-06 23:14:26 +01:00
_M3U8_TEMPL = 'https://vod.lnk.lt/lnk_vod/lnk/lnk/%s:%s/playlist.m3u8%s'
2015-01-13 23:14:59 +01:00
def _real_extract(self, url):
2019-11-06 23:14:26 +01:00
display_id, video_id = re.match(self._VALID_URL, url).groups()
2015-01-13 23:14:59 +01:00
2019-11-06 23:14:26 +01:00
video_info = self._download_json(
'https://lnk.lt/api/main/video-page/%s/%s/false' % (display_id, video_id or '0'),
display_id)['videoConfig']['videoInfo']
2015-01-13 23:14:59 +01:00
2019-11-06 23:14:26 +01:00
video_id = compat_str(video_info['id'])
title = video_info['title']
prefix = 'smil' if video_info.get('isQualityChangeAvailable') else 'mp4'
formats = self._extract_m3u8_formats(
self._M3U8_TEMPL % (prefix, video_info['videoUrl'], video_info.get('secureTokenParams') or ''),
video_id, 'mp4', 'm3u8_native')
2015-01-13 23:14:59 +01:00
self._sort_formats(formats)
2019-11-06 23:14:26 +01:00
poster_image = video_info.get('posterImage')
2015-01-13 23:14:59 +01:00
return {
'id': video_id,
'display_id': display_id,
'title': title,
'formats': formats,
2019-11-06 23:14:26 +01:00
'thumbnail': 'https://lnk.lt/all-images/' + poster_image if poster_image else None,
'duration': int_or_none(video_info.get('duration')),
'description': clean_html(video_info.get('htmlDescription')),
'age_limit': self._AGE_LIMITS.get(video_info.get('pgRating'), 0),
'timestamp': parse_iso8601(video_info.get('airDate')),
'view_count': int_or_none(video_info.get('viewsCount')),
2015-01-13 23:14:59 +01:00
}