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