aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLauren Liberda <laura@selfisekai.rocks>2021-10-23 01:46:56 +0200
committerpukkandan <pukkandan.ytdlp@gmail.com>2021-11-10 06:13:53 +0530
commited76230b3f61d3440da5b71170e243cd2bfe693b (patch)
treef0a518e86fe17a5b0a5ab0a7370e5bf7a76a005e
parent89fcdff5d8e62c6153763650f12ec4eb4453bdff (diff)
downloadhypervideo-pre-ed76230b3f61d3440da5b71170e243cd2bfe693b.tar.lz
hypervideo-pre-ed76230b3f61d3440da5b71170e243cd2bfe693b.tar.xz
hypervideo-pre-ed76230b3f61d3440da5b71170e243cd2bfe693b.zip
[polsatgo] Add extractor (#1386)
Authored by: selfisekai, sdomi Co-authored-by: Dominika Liberda <ja@sdomi.pl>
-rw-r--r--yt_dlp/extractor/extractors.py1
-rw-r--r--yt_dlp/extractor/polsatgo.py90
2 files changed, 91 insertions, 0 deletions
diff --git a/yt_dlp/extractor/extractors.py b/yt_dlp/extractor/extractors.py
index 741b9f021..bd0da2c38 100644
--- a/yt_dlp/extractor/extractors.py
+++ b/yt_dlp/extractor/extractors.py
@@ -1105,6 +1105,7 @@ from .pokemon import (
PokemonIE,
PokemonWatchIE,
)
+from .polsatgo import PolsatGoIE
from .polskieradio import (
PolskieRadioIE,
PolskieRadioCategoryIE,
diff --git a/yt_dlp/extractor/polsatgo.py b/yt_dlp/extractor/polsatgo.py
new file mode 100644
index 000000000..1e3f46c07
--- /dev/null
+++ b/yt_dlp/extractor/polsatgo.py
@@ -0,0 +1,90 @@
+# coding: utf-8
+from __future__ import unicode_literals
+
+from uuid import uuid4
+import json
+
+from .common import InfoExtractor
+from ..utils import (
+ int_or_none,
+ try_get,
+ url_or_none,
+ ExtractorError,
+)
+
+
+class PolsatGoIE(InfoExtractor):
+ _VALID_URL = r'https?://(?:www\.)?polsat(?:box)?go\.pl/.+/(?P<id>[0-9a-fA-F]+)(?:[/#?]|$)'
+ _TESTS = [{
+ 'url': 'https://polsatgo.pl/wideo/seriale/swiat-wedlug-kiepskich/5024045/sezon-1/5028300/swiat-wedlug-kiepskich-odcinek-88/4121',
+ 'info_dict': {
+ 'id': '4121',
+ 'ext': 'mp4',
+ 'title': 'Świat według Kiepskich - Odcinek 88',
+ 'age_limit': 12,
+ },
+ }]
+
+ def _extract_formats(self, sources, video_id):
+ for source in sources or []:
+ if not source.get('id'):
+ continue
+ url = url_or_none(self._call_api(
+ 'drm', video_id, 'getPseudoLicense',
+ {'mediaId': video_id, 'sourceId': source['id']}).get('url'))
+ if not url:
+ continue
+ yield {
+ 'url': url,
+ 'height': int_or_none(try_get(source, lambda x: x['quality'][:-1]))
+ }
+
+ def _real_extract(self, url):
+ video_id = self._match_id(url)
+ media = self._call_api('navigation', video_id, 'prePlayData', {'mediaId': video_id})['mediaItem']
+
+ formats = list(self._extract_formats(
+ try_get(media, lambda x: x['playback']['mediaSources']), video_id))
+ self._sort_formats(formats)
+
+ return {
+ 'id': video_id,
+ 'title': media['displayInfo']['title'],
+ 'formats': formats,
+ 'age_limit': int_or_none(media['displayInfo']['ageGroup'])
+ }
+
+ def _call_api(self, endpoint, media_id, method, params):
+ rand_uuid = str(uuid4())
+ res = self._download_json(
+ f'https://b2c-mobile.redefine.pl/rpc/{endpoint}/', media_id,
+ note=f'Downloading {method} JSON metadata',
+ data=json.dumps({
+ 'method': method,
+ 'id': '2137',
+ 'jsonrpc': '2.0',
+ 'params': {
+ **params,
+ 'userAgentData': {
+ 'deviceType': 'mobile',
+ 'application': 'native',
+ 'os': 'android',
+ 'build': 10003,
+ 'widevine': False,
+ 'portal': 'pg',
+ 'player': 'cpplayer',
+ },
+ 'deviceId': {
+ 'type': 'other',
+ 'value': rand_uuid,
+ },
+ 'clientId': rand_uuid,
+ 'cpid': 1,
+ },
+ }).encode('utf-8'),
+ headers={'Content-type': 'application/json'})
+ if not res.get('result'):
+ if res['error']['code'] == 13404:
+ raise ExtractorError('This video is either unavailable in your region or is DRM protected', expected=True)
+ raise ExtractorError(f'Solorz said: {res["error"]["message"]} - {res["error"]["data"]["userMessage"]}')
+ return res['result']