]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/playplustv.py
[extractor] Deprecate `_sort_formats`
[yt-dlp.git] / yt_dlp / extractor / playplustv.py
CommitLineData
4ad159c7 1import json
4ad159c7
RA
2
3from .common import InfoExtractor
4from ..compat import compat_HTTPError
5from ..utils import (
6 clean_html,
7 ExtractorError,
8 int_or_none,
9 PUTRequest,
10)
11
12
13class PlayPlusTVIE(InfoExtractor):
c469e880 14 _VALID_URL = r'https?://(?:www\.)?playplus\.(?:com|tv)/VOD/(?P<project_id>[0-9]+)/(?P<id>[0-9a-f]{32})'
4ad159c7
RA
15 _TEST = {
16 'url': 'https://www.playplus.tv/VOD/7572/db8d274a5163424e967f35a30ddafb8e',
17 'md5': 'd078cb89d7ab6b9df37ce23c647aef72',
18 'info_dict': {
19 'id': 'db8d274a5163424e967f35a30ddafb8e',
20 'ext': 'mp4',
21 'title': 'CapĂ­tulo 179 - Final',
22 'description': 'md5:01085d62d8033a1e34121d3c3cabc838',
23 'timestamp': 1529992740,
24 'upload_date': '20180626',
25 },
26 'skip': 'Requires account credential',
27 }
28 _NETRC_MACHINE = 'playplustv'
29 _GEO_COUNTRIES = ['BR']
30 _token = None
31 _profile_id = None
32
33 def _call_api(self, resource, video_id=None, query=None):
34 return self._download_json('https://api.playplus.tv/api/media/v2/get' + resource, video_id, headers={
35 'Authorization': 'Bearer ' + self._token,
36 }, query=query)
37
52efa4b3 38 def _perform_login(self, username, password):
4ad159c7
RA
39 req = PUTRequest(
40 'https://api.playplus.tv/api/web/login', json.dumps({
52efa4b3 41 'email': username,
4ad159c7
RA
42 'password': password,
43 }).encode(), {
44 'Content-Type': 'application/json; charset=utf-8',
45 })
46
47 try:
48 self._token = self._download_json(req, None)['token']
49 except ExtractorError as e:
50 if isinstance(e.cause, compat_HTTPError) and e.cause.code == 401:
51 raise ExtractorError(self._parse_json(
52 e.cause.read(), None)['errorMessage'], expected=True)
53 raise
54
55 self._profile = self._call_api('Profiles')['list'][0]['_id']
56
52efa4b3 57 def _real_initialize(self):
58 if not self._token:
59 self.raise_login_required(method='password')
60
4ad159c7 61 def _real_extract(self, url):
5ad28e7f 62 project_id, media_id = self._match_valid_url(url).groups()
4ad159c7
RA
63 media = self._call_api(
64 'Media', media_id, {
65 'profileId': self._profile,
66 'projectId': project_id,
67 'mediaId': media_id,
68 })['obj']
69 title = media['title']
70
71 formats = []
72 for f in media.get('files', []):
73 f_url = f.get('url')
74 if not f_url:
75 continue
76 file_info = f.get('fileInfo') or {}
77 formats.append({
78 'url': f_url,
79 'width': int_or_none(file_info.get('width')),
80 'height': int_or_none(file_info.get('height')),
81 })
4ad159c7
RA
82
83 thumbnails = []
84 for thumb in media.get('thumbs', []):
85 thumb_url = thumb.get('url')
86 if not thumb_url:
87 continue
88 thumbnails.append({
89 'url': thumb_url,
90 'width': int_or_none(thumb.get('width')),
91 'height': int_or_none(thumb.get('height')),
92 })
93
94 return {
95 'id': media_id,
96 'title': title,
97 'formats': formats,
98 'thumbnails': thumbnails,
99 'description': clean_html(media.get('description')) or media.get('shortDescription'),
100 'timestamp': int_or_none(media.get('publishDate'), 1000),
101 'view_count': int_or_none(media.get('numberOfViews')),
102 'comment_count': int_or_none(media.get('numberOfComments')),
103 'tags': media.get('tags'),
104 }