]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/laola1tv.py
[cleanup] Misc
[yt-dlp.git] / yt_dlp / extractor / laola1tv.py
CommitLineData
4fe14732 1import json
faac1c1f 2import re
4fe14732 3
e5193599 4from .common import InfoExtractor
9dcefb23 5from ..utils import (
3037b91e 6 ExtractorError,
5e19323e
JW
7 unified_strdate,
8 urlencode_postdata,
9dcefb23
S
9 xpath_element,
10 xpath_text,
e029c43b 11 update_url_query,
4fe14732 12 js_to_json,
3037b91e 13)
e5193599
PH
14
15
b42a0bf3 16class Laola1TvEmbedIE(InfoExtractor):
e029c43b 17 IE_NAME = 'laola1tv:embed'
b42a0bf3 18 _VALID_URL = r'https?://(?:www\.)?laola1\.tv/titanplayer\.php\?.*?\bvideoid=(?P<id>\d+)'
7f09e523 19 _TESTS = [{
e029c43b
RA
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 },
7f09e523 29 }]
b42a0bf3 30
4fe14732
RA
31 def _extract_token_url(self, stream_access_url, video_id, data):
32 return self._download_json(
6895ea4d
S
33 self._proto_relative_url(stream_access_url, 'https:'), video_id,
34 headers={
4fe14732
RA
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
b42a0bf3
RA
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')
e029c43b
RA
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
b42a0bf3
RA
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
e029c43b
RA
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(','))))
4fe14732
RA
95 stream_access_url = update_url_query(
96 'https://club.laola1.tv/sp/laola1/api/v3/user/session/premium/player/stream-access', {
e029c43b
RA
97 'videoId': _v('id'),
98 'target': self._search_regex(r'vs_target = (\d+);', webpage, 'vs target'),
99 'label': _v('label'),
100 'area': _v('area'),
4fe14732
RA
101 })
102 token_url = self._extract_token_url(stream_access_url, video_id, data_abo)
b42a0bf3 103
4fe14732 104 formats = self._extract_formats(token_url, video_id)
b42a0bf3
RA
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,
39ca3b5c 112 'title': title,
b42a0bf3
RA
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
6368e2e6 121class Laola1TvBaseIE(Laola1TvEmbedIE): # XXX: Do not subclass from concrete IE
faac1c1f
AS
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,
39ca3b5c 161 'title': title,
faac1c1f
AS
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
170class Laola1TvIE(Laola1TvBaseIE):
e029c43b 171 IE_NAME = 'laola1tv'
b42a0bf3 172 _VALID_URL = r'https?://(?:www\.)?laola1\.tv/[a-z]+-[a-z]+/[^/]+/(?P<id>[^/?#&]+)'
faac1c1f 173
5e19323e 174 _TESTS = [{
3037b91e 175 'url': 'http://www.laola1.tv/de-de/video/straubing-tigers-koelner-haie/227883.html',
e5193599 176 'info_dict': {
3037b91e 177 'id': '227883',
9dcefb23
S
178 'display_id': 'straubing-tigers-koelner-haie',
179 'ext': 'flv',
3037b91e 180 'title': 'Straubing Tigers - Kölner Haie',
5e19323e 181 'upload_date': '20140912',
9dcefb23
S
182 'is_live': False,
183 'categories': ['Eishockey'],
5e19323e
JW
184 },
185 'params': {
186 'skip_download': True,
2beeb286 187 },
5e19323e
JW
188 }, {
189 'url': 'http://www.laola1.tv/de-de/video/straubing-tigers-koelner-haie',
190 'info_dict': {
5e19323e 191 'id': '464602',
9dcefb23
S
192 'display_id': 'straubing-tigers-koelner-haie',
193 'ext': 'flv',
5e19323e
JW
194 'title': 'Straubing Tigers - Kölner Haie',
195 'upload_date': '20160129',
9dcefb23
S
196 'is_live': False,
197 'categories': ['Eishockey'],
e5193599
PH
198 },
199 'params': {
200 'skip_download': True,
2beeb286
S
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 },
d1c4e4ba 217 'skip': 'This live stream has already finished.',
5e19323e 218 }]
e5193599
PH
219
220 def _real_extract(self, url):
faac1c1f 221 return self._extract_video(url)
e5193599 222
9dcefb23 223
faac1c1f
AS
224class EHFTVIE(Laola1TvBaseIE):
225 IE_NAME = 'ehftv'
6895ea4d 226 _VALID_URL = r'https?://(?:www\.)?ehftv\.com/[a-z]+(?:-[a-z]+)?/[^/]+/(?P<id>[^/?#&]+)'
4fe14732 227
faac1c1f
AS
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 }]
e5193599 242
faac1c1f
AS
243 def _real_extract(self, url):
244 return self._extract_video(url)
f5469da9
S
245
246
247class 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())