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