]>
Commit | Line | Data |
---|---|---|
ed76230b LL |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | from uuid import uuid4 | |
5 | import json | |
6 | ||
7 | from .common import InfoExtractor | |
8 | from ..utils import ( | |
9 | int_or_none, | |
10 | try_get, | |
11 | url_or_none, | |
12 | ExtractorError, | |
13 | ) | |
14 | ||
15 | ||
16 | class PolsatGoIE(InfoExtractor): | |
17 | _VALID_URL = r'https?://(?:www\.)?polsat(?:box)?go\.pl/.+/(?P<id>[0-9a-fA-F]+)(?:[/#?]|$)' | |
18 | _TESTS = [{ | |
19 | 'url': 'https://polsatgo.pl/wideo/seriale/swiat-wedlug-kiepskich/5024045/sezon-1/5028300/swiat-wedlug-kiepskich-odcinek-88/4121', | |
20 | 'info_dict': { | |
21 | 'id': '4121', | |
22 | 'ext': 'mp4', | |
23 | 'title': 'Świat według Kiepskich - Odcinek 88', | |
24 | 'age_limit': 12, | |
25 | }, | |
26 | }] | |
27 | ||
28 | def _extract_formats(self, sources, video_id): | |
29 | for source in sources or []: | |
30 | if not source.get('id'): | |
31 | continue | |
32 | url = url_or_none(self._call_api( | |
33 | 'drm', video_id, 'getPseudoLicense', | |
34 | {'mediaId': video_id, 'sourceId': source['id']}).get('url')) | |
35 | if not url: | |
36 | continue | |
37 | yield { | |
38 | 'url': url, | |
39 | 'height': int_or_none(try_get(source, lambda x: x['quality'][:-1])) | |
40 | } | |
41 | ||
42 | def _real_extract(self, url): | |
43 | video_id = self._match_id(url) | |
44 | media = self._call_api('navigation', video_id, 'prePlayData', {'mediaId': video_id})['mediaItem'] | |
45 | ||
46 | formats = list(self._extract_formats( | |
47 | try_get(media, lambda x: x['playback']['mediaSources']), video_id)) | |
48 | self._sort_formats(formats) | |
49 | ||
50 | return { | |
51 | 'id': video_id, | |
52 | 'title': media['displayInfo']['title'], | |
53 | 'formats': formats, | |
54 | 'age_limit': int_or_none(media['displayInfo']['ageGroup']) | |
55 | } | |
56 | ||
57 | def _call_api(self, endpoint, media_id, method, params): | |
58 | rand_uuid = str(uuid4()) | |
59 | res = self._download_json( | |
60 | f'https://b2c-mobile.redefine.pl/rpc/{endpoint}/', media_id, | |
61 | note=f'Downloading {method} JSON metadata', | |
62 | data=json.dumps({ | |
63 | 'method': method, | |
64 | 'id': '2137', | |
65 | 'jsonrpc': '2.0', | |
66 | 'params': { | |
67 | **params, | |
68 | 'userAgentData': { | |
69 | 'deviceType': 'mobile', | |
70 | 'application': 'native', | |
71 | 'os': 'android', | |
72 | 'build': 10003, | |
73 | 'widevine': False, | |
74 | 'portal': 'pg', | |
75 | 'player': 'cpplayer', | |
76 | }, | |
77 | 'deviceId': { | |
78 | 'type': 'other', | |
79 | 'value': rand_uuid, | |
80 | }, | |
81 | 'clientId': rand_uuid, | |
82 | 'cpid': 1, | |
83 | }, | |
84 | }).encode('utf-8'), | |
85 | headers={'Content-type': 'application/json'}) | |
86 | if not res.get('result'): | |
87 | if res['error']['code'] == 13404: | |
88 | raise ExtractorError('This video is either unavailable in your region or is DRM protected', expected=True) | |
89 | raise ExtractorError(f'Solorz said: {res["error"]["message"]} - {res["error"]["data"]["userMessage"]}') | |
90 | return res['result'] |