]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/laola1tv.py
[extractor] Use classmethod/property where possible
[yt-dlp.git] / yt_dlp / extractor / laola1tv.py
1 import json
2 import re
3
4 from .common import InfoExtractor
5 from ..utils import (
6 ExtractorError,
7 unified_strdate,
8 urlencode_postdata,
9 xpath_element,
10 xpath_text,
11 update_url_query,
12 js_to_json,
13 )
14
15
16 class Laola1TvEmbedIE(InfoExtractor):
17 IE_NAME = 'laola1tv:embed'
18 _VALID_URL = r'https?://(?:www\.)?laola1\.tv/titanplayer\.php\?.*?\bvideoid=(?P<id>\d+)'
19 _TESTS = [{
20 # flashvars.premium = "false";
21 'url': 'https://www.laola1.tv/titanplayer.php?videoid=708065&type=V&lang=en&portal=int&customer=1024',
22 'info_dict': {
23 'id': '708065',
24 'ext': 'mp4',
25 'title': 'MA Long CHN - FAN Zhendong CHN',
26 'uploader': 'ITTF - International Table Tennis Federation',
27 'upload_date': '20161211',
28 },
29 }]
30
31 def _extract_token_url(self, stream_access_url, video_id, data):
32 return self._download_json(
33 self._proto_relative_url(stream_access_url, 'https:'), video_id,
34 headers={
35 'Content-Type': 'application/json',
36 }, data=json.dumps(data).encode())['data']['stream-access'][0]
37
38 def _extract_formats(self, token_url, video_id):
39 token_doc = self._download_xml(
40 token_url, video_id, 'Downloading token',
41 headers=self.geo_verification_headers())
42
43 token_attrib = xpath_element(token_doc, './/token').attrib
44
45 if token_attrib['status'] != '0':
46 raise ExtractorError(
47 'Token error: %s' % token_attrib['comment'], expected=True)
48
49 formats = self._extract_akamai_formats(
50 '%s?hdnea=%s' % (token_attrib['url'], token_attrib['auth']),
51 video_id)
52 self._sort_formats(formats)
53 return formats
54
55 def _real_extract(self, url):
56 video_id = self._match_id(url)
57 webpage = self._download_webpage(url, video_id)
58 flash_vars = self._search_regex(
59 r'(?s)flashvars\s*=\s*({.+?});', webpage, 'flash vars')
60
61 def get_flashvar(x, *args, **kwargs):
62 flash_var = self._search_regex(
63 r'%s\s*:\s*"([^"]+)"' % x,
64 flash_vars, x, default=None)
65 if not flash_var:
66 flash_var = self._search_regex([
67 r'flashvars\.%s\s*=\s*"([^"]+)"' % x,
68 r'%s\s*=\s*"([^"]+)"' % x],
69 webpage, x, *args, **kwargs)
70 return flash_var
71
72 hd_doc = self._download_xml(
73 'http://www.laola1.tv/server/hd_video.php', video_id, query={
74 'play': get_flashvar('streamid'),
75 'partner': get_flashvar('partnerid'),
76 'portal': get_flashvar('portalid'),
77 'lang': get_flashvar('sprache'),
78 'v5ident': '',
79 })
80
81 _v = lambda x, **k: xpath_text(hd_doc, './/video/' + x, **k)
82 title = _v('title', fatal=True)
83
84 token_url = None
85 premium = get_flashvar('premium', default=None)
86 if premium:
87 token_url = update_url_query(
88 _v('url', fatal=True), {
89 'timestamp': get_flashvar('timestamp'),
90 'auth': get_flashvar('auth'),
91 })
92 else:
93 data_abo = urlencode_postdata(
94 dict((i, v) for i, v in enumerate(_v('req_liga_abos').split(','))))
95 stream_access_url = update_url_query(
96 'https://club.laola1.tv/sp/laola1/api/v3/user/session/premium/player/stream-access', {
97 'videoId': _v('id'),
98 'target': self._search_regex(r'vs_target = (\d+);', webpage, 'vs target'),
99 'label': _v('label'),
100 'area': _v('area'),
101 })
102 token_url = self._extract_token_url(stream_access_url, video_id, data_abo)
103
104 formats = self._extract_formats(token_url, video_id)
105
106 categories_str = _v('meta_sports')
107 categories = categories_str.split(',') if categories_str else []
108 is_live = _v('islive') == 'true'
109
110 return {
111 'id': video_id,
112 'title': title,
113 'upload_date': unified_strdate(_v('time_date')),
114 'uploader': _v('meta_organisation'),
115 'categories': categories,
116 'is_live': is_live,
117 'formats': formats,
118 }
119
120
121 class Laola1TvBaseIE(Laola1TvEmbedIE):
122 def _extract_video(self, url):
123 display_id = self._match_id(url)
124 webpage = self._download_webpage(url, display_id)
125
126 if 'Dieser Livestream ist bereits beendet.' in webpage:
127 raise ExtractorError('This live stream has already finished.', expected=True)
128
129 conf = self._parse_json(self._search_regex(
130 r'(?s)conf\s*=\s*({.+?});', webpage, 'conf'),
131 display_id,
132 transform_source=lambda s: js_to_json(re.sub(r'shareurl:.+,', '', s)))
133 video_id = conf['videoid']
134
135 config = self._download_json(conf['configUrl'], video_id, query={
136 'videoid': video_id,
137 'partnerid': conf['partnerid'],
138 'language': conf.get('language', ''),
139 'portal': conf.get('portalid', ''),
140 })
141 error = config.get('error')
142 if error:
143 raise ExtractorError('%s said: %s' % (self.IE_NAME, error), expected=True)
144
145 video_data = config['video']
146 title = video_data['title']
147 is_live = video_data.get('isLivestream') and video_data.get('isLive')
148 meta = video_data.get('metaInformation')
149 sports = meta.get('sports')
150 categories = sports.split(',') if sports else []
151
152 token_url = self._extract_token_url(
153 video_data['streamAccess'], video_id,
154 video_data['abo']['required'])
155
156 formats = self._extract_formats(token_url, video_id)
157
158 return {
159 'id': video_id,
160 'display_id': display_id,
161 'title': title,
162 'description': video_data.get('description'),
163 'thumbnail': video_data.get('image'),
164 'categories': categories,
165 'formats': formats,
166 'is_live': is_live,
167 }
168
169
170 class Laola1TvIE(Laola1TvBaseIE):
171 IE_NAME = 'laola1tv'
172 _VALID_URL = r'https?://(?:www\.)?laola1\.tv/[a-z]+-[a-z]+/[^/]+/(?P<id>[^/?#&]+)'
173
174 _TESTS = [{
175 'url': 'http://www.laola1.tv/de-de/video/straubing-tigers-koelner-haie/227883.html',
176 'info_dict': {
177 'id': '227883',
178 'display_id': 'straubing-tigers-koelner-haie',
179 'ext': 'flv',
180 'title': 'Straubing Tigers - Kölner Haie',
181 'upload_date': '20140912',
182 'is_live': False,
183 'categories': ['Eishockey'],
184 },
185 'params': {
186 'skip_download': True,
187 },
188 }, {
189 'url': 'http://www.laola1.tv/de-de/video/straubing-tigers-koelner-haie',
190 'info_dict': {
191 'id': '464602',
192 'display_id': 'straubing-tigers-koelner-haie',
193 'ext': 'flv',
194 'title': 'Straubing Tigers - Kölner Haie',
195 'upload_date': '20160129',
196 'is_live': False,
197 'categories': ['Eishockey'],
198 },
199 'params': {
200 'skip_download': True,
201 },
202 }, {
203 'url': 'http://www.laola1.tv/de-de/livestream/2016-03-22-belogorie-belgorod-trentino-diatec-lde',
204 'info_dict': {
205 'id': '487850',
206 'display_id': '2016-03-22-belogorie-belgorod-trentino-diatec-lde',
207 'ext': 'flv',
208 'title': 'Belogorie BELGOROD - TRENTINO Diatec',
209 'upload_date': '20160322',
210 'uploader': 'CEV - Europäischer Volleyball Verband',
211 'is_live': True,
212 'categories': ['Volleyball'],
213 },
214 'params': {
215 'skip_download': True,
216 },
217 'skip': 'This live stream has already finished.',
218 }]
219
220 def _real_extract(self, url):
221 return self._extract_video(url)
222
223
224 class EHFTVIE(Laola1TvBaseIE):
225 IE_NAME = 'ehftv'
226 _VALID_URL = r'https?://(?:www\.)?ehftv\.com/[a-z]+(?:-[a-z]+)?/[^/]+/(?P<id>[^/?#&]+)'
227
228 _TESTS = [{
229 'url': 'https://www.ehftv.com/int/video/paris-saint-germain-handball-pge-vive-kielce/1166761',
230 'info_dict': {
231 'id': '1166761',
232 'display_id': 'paris-saint-germain-handball-pge-vive-kielce',
233 'ext': 'mp4',
234 'title': 'Paris Saint-Germain Handball - PGE Vive Kielce',
235 'is_live': False,
236 'categories': ['Handball'],
237 },
238 'params': {
239 'skip_download': True,
240 },
241 }]
242
243 def _real_extract(self, url):
244 return self._extract_video(url)
245
246
247 class ITTFIE(InfoExtractor):
248 _VALID_URL = r'https?://tv\.ittf\.com/video/[^/]+/(?P<id>\d+)'
249 _TEST = {
250 'url': 'https://tv.ittf.com/video/peng-wang-wei-matsudaira-kenta/951802',
251 'only_matching': True,
252 }
253
254 def _real_extract(self, url):
255 return self.url_result(
256 update_url_query('https://www.laola1.tv/titanplayer.php', {
257 'videoid': self._match_id(url),
258 'type': 'V',
259 'lang': 'en',
260 'portal': 'int',
261 'customer': 1024,
262 }), Laola1TvEmbedIE.ie_key())