]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/lnkgo.py
d/p/skip-style-checks-for-flake8: Add metadata to please lintian.
[youtubedl] / youtube_dl / extractor / lnkgo.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8 clean_html,
9 compat_str,
10 int_or_none,
11 parse_iso8601,
12 )
13
14
15 class LnkGoIE(InfoExtractor):
16 _VALID_URL = r'https?://(?:www\.)?lnk(?:go)?\.(?:alfa\.)?lt/(?:visi-video/[^/]+|video)/(?P<id>[A-Za-z0-9-]+)(?:/(?P<episode_id>\d+))?'
17 _TESTS = [{
18 'url': 'http://www.lnkgo.lt/visi-video/aktualai-pratesimas/ziurek-putka-trys-klausimai',
19 'info_dict': {
20 'id': '10809',
21 'ext': 'mp4',
22 'title': "Put'ka: Trys Klausimai",
23 'upload_date': '20161216',
24 'description': 'Seniai matytas Put’ka užduoda tris klausimėlius. Pabandykime surasti atsakymus.',
25 'age_limit': 18,
26 'duration': 117,
27 'thumbnail': r're:^https?://.*\.jpg$',
28 'timestamp': 1481904000,
29 },
30 'params': {
31 'skip_download': True, # HLS download
32 },
33 }, {
34 'url': 'http://lnkgo.alfa.lt/visi-video/aktualai-pratesimas/ziurek-nerdas-taiso-kompiuteri-2',
35 'info_dict': {
36 'id': '10467',
37 'ext': 'mp4',
38 'title': 'Nėrdas: Kompiuterio Valymas',
39 'upload_date': '20150113',
40 'description': 'md5:7352d113a242a808676ff17e69db6a69',
41 'age_limit': 18,
42 'duration': 346,
43 'thumbnail': r're:^https?://.*\.jpg$',
44 'timestamp': 1421164800,
45 },
46 'params': {
47 'skip_download': True, # HLS download
48 },
49 }, {
50 'url': 'https://lnk.lt/video/neigalieji-tv-bokste/37413',
51 'only_matching': True,
52 }]
53 _AGE_LIMITS = {
54 'N-7': 7,
55 'N-14': 14,
56 'S': 18,
57 }
58 _M3U8_TEMPL = 'https://vod.lnk.lt/lnk_vod/lnk/lnk/%s:%s/playlist.m3u8%s'
59
60 def _real_extract(self, url):
61 display_id, video_id = re.match(self._VALID_URL, url).groups()
62
63 video_info = self._download_json(
64 'https://lnk.lt/api/main/video-page/%s/%s/false' % (display_id, video_id or '0'),
65 display_id)['videoConfig']['videoInfo']
66
67 video_id = compat_str(video_info['id'])
68 title = video_info['title']
69 prefix = 'smil' if video_info.get('isQualityChangeAvailable') else 'mp4'
70 formats = self._extract_m3u8_formats(
71 self._M3U8_TEMPL % (prefix, video_info['videoUrl'], video_info.get('secureTokenParams') or ''),
72 video_id, 'mp4', 'm3u8_native')
73 self._sort_formats(formats)
74
75 poster_image = video_info.get('posterImage')
76
77 return {
78 'id': video_id,
79 'display_id': display_id,
80 'title': title,
81 'formats': formats,
82 'thumbnail': 'https://lnk.lt/all-images/' + poster_image if poster_image else None,
83 'duration': int_or_none(video_info.get('duration')),
84 'description': clean_html(video_info.get('htmlDescription')),
85 'age_limit': self._AGE_LIMITS.get(video_info.get('pgRating'), 0),
86 'timestamp': parse_iso8601(video_info.get('airDate')),
87 'view_count': int_or_none(video_info.get('viewsCount')),
88 }