]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/lnkgo.py
[thestar] Add new extractor(closes #5955)
[youtube-dl] / 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     int_or_none,
9     unified_strdate,
10 )
11
12
13 class LnkGoIE(InfoExtractor):
14     _VALID_URL = r'https?://(?:www\.)?lnkgo\.alfa\.lt/visi-video/(?P<show>[^/]+)/ziurek-(?P<id>[A-Za-z0-9-]+)'
15     _TESTS = [{
16         'url': 'http://lnkgo.alfa.lt/visi-video/yra-kaip-yra/ziurek-yra-kaip-yra-162',
17         'info_dict': {
18             'id': '46712',
19             'ext': 'mp4',
20             'title': 'Yra kaip yra',
21             'upload_date': '20150107',
22             'description': 'md5:d82a5e36b775b7048617f263a0e3475e',
23             'age_limit': 7,
24             'duration': 3019,
25             'thumbnail': 're:^https?://.*\.jpg$'
26         },
27         'params': {
28             'skip_download': True,  # HLS download
29         },
30     }, {
31         'url': 'http://lnkgo.alfa.lt/visi-video/aktualai-pratesimas/ziurek-nerdas-taiso-kompiuteri-2',
32         'info_dict': {
33             'id': '47289',
34             'ext': 'mp4',
35             'title': 'Nėrdas: Kompiuterio Valymas',
36             'upload_date': '20150113',
37             'description': 'md5:7352d113a242a808676ff17e69db6a69',
38             'age_limit': 18,
39             'duration': 346,
40             'thumbnail': 're:^https?://.*\.jpg$'
41         },
42         'params': {
43             'skip_download': True,  # HLS download
44         },
45     }]
46     _AGE_LIMITS = {
47         'N-7': 7,
48         'N-14': 14,
49         'S': 18,
50     }
51
52     def _real_extract(self, url):
53         display_id = self._match_id(url)
54
55         webpage = self._download_webpage(
56             url, display_id, 'Downloading player webpage')
57
58         video_id = self._search_regex(
59             r'data-ep="([^"]+)"', webpage, 'video ID')
60         title = self._og_search_title(webpage)
61         description = self._og_search_description(webpage)
62         upload_date = unified_strdate(self._search_regex(
63             r'class="[^"]*meta-item[^"]*air-time[^"]*">.*?<strong>([^<]+)</strong>', webpage, 'upload date', fatal=False))
64
65         thumbnail_w = int_or_none(
66             self._og_search_property('image:width', webpage, 'thumbnail width', fatal=False))
67         thumbnail_h = int_or_none(
68             self._og_search_property('image:height', webpage, 'thumbnail height', fatal=False))
69         thumbnail = {
70             'url': self._og_search_thumbnail(webpage),
71         }
72         if thumbnail_w and thumbnail_h:
73             thumbnail.update({
74                 'width': thumbnail_w,
75                 'height': thumbnail_h,
76             })
77
78         config = self._parse_json(self._search_regex(
79             r'episodePlayer\((\{.*?\}),\s*\{', webpage, 'sources'), video_id)
80
81         if config.get('pGeo'):
82             self.report_warning(
83                 'This content might not be available in your country due to copyright reasons')
84
85         formats = [{
86             'format_id': 'hls',
87             'ext': 'mp4',
88             'url': config['EpisodeVideoLink_HLS'],
89         }]
90
91         m = re.search(r'^(?P<url>rtmp://[^/]+/(?P<app>[^/]+))/(?P<play_path>.+)$', config['EpisodeVideoLink'])
92         if m:
93             formats.append({
94                 'format_id': 'rtmp',
95                 'ext': 'flv',
96                 'url': m.group('url'),
97                 'play_path': m.group('play_path'),
98                 'page_url': url,
99             })
100
101         self._sort_formats(formats)
102
103         return {
104             'id': video_id,
105             'display_id': display_id,
106             'title': title,
107             'formats': formats,
108             'thumbnails': [thumbnail],
109             'duration': int_or_none(config.get('VideoTime')),
110             'description': description,
111             'age_limit': self._AGE_LIMITS.get(config.get('PGRating'), 0),
112             'upload_date': upload_date,
113         }