]>
Commit | Line | Data |
---|---|---|
e08585b0 | 1 | import hashlib |
2 | ||
b1aaf1c0 J |
3 | from .common import InfoExtractor |
4 | from ..utils import ( | |
5 | ExtractorError, | |
6 | try_get | |
7 | ) | |
8 | ||
9 | ||
10 | class GofileIE(InfoExtractor): | |
11 | _VALID_URL = r'https?://(?:www\.)?gofile\.io/d/(?P<id>[^/]+)' | |
12 | _TESTS = [{ | |
13 | 'url': 'https://gofile.io/d/AMZyDw', | |
14 | 'info_dict': { | |
15 | 'id': 'AMZyDw', | |
16 | }, | |
17 | 'playlist_mincount': 2, | |
18 | 'playlist': [{ | |
19 | 'info_dict': { | |
20 | 'id': 'de571ac1-5edc-42e2-8ec2-bdac83ad4a31', | |
21 | 'filesize': 928116, | |
22 | 'ext': 'mp4', | |
fcdb8d6e | 23 | 'title': 'nuuh', |
24 | 'release_timestamp': 1638338704, | |
25 | 'release_date': '20211201', | |
b1aaf1c0 J |
26 | } |
27 | }] | |
fcdb8d6e | 28 | }, { |
29 | 'url': 'https://gofile.io/d/is8lKr', | |
b1aaf1c0 | 30 | 'info_dict': { |
fcdb8d6e | 31 | 'id': 'TMjXd9', |
32 | 'ext': 'mp4', | |
b1aaf1c0 J |
33 | }, |
34 | 'playlist_count': 0, | |
35 | 'skip': 'No video/audio found at provided URL.', | |
fcdb8d6e | 36 | }, { |
37 | 'url': 'https://gofile.io/d/TMjXd9', | |
38 | 'info_dict': { | |
39 | 'id': 'TMjXd9', | |
40 | }, | |
41 | 'playlist_count': 1, | |
e08585b0 | 42 | }, { |
43 | 'url': 'https://gofile.io/d/gqOtRf', | |
44 | 'info_dict': { | |
45 | 'id': 'gqOtRf', | |
46 | }, | |
47 | 'playlist_mincount': 1, | |
48 | 'params': { | |
49 | 'videopassword': 'password', | |
50 | }, | |
b1aaf1c0 J |
51 | }] |
52 | _TOKEN = None | |
53 | ||
54 | def _real_initialize(self): | |
55 | token = self._get_cookies('https://gofile.io/').get('accountToken') | |
56 | if token: | |
57 | self._TOKEN = token.value | |
58 | return | |
59 | ||
60 | account_data = self._download_json( | |
61 | 'https://api.gofile.io/createAccount', None, note='Getting a new guest account') | |
62 | self._TOKEN = account_data['data']['token'] | |
0730d5a9 | 63 | self._set_cookie('.gofile.io', 'accountToken', self._TOKEN) |
b1aaf1c0 J |
64 | |
65 | def _entries(self, file_id): | |
e08585b0 | 66 | query_params = { |
fcdb8d6e | 67 | 'contentId': file_id, |
68 | 'token': self._TOKEN, | |
77c2472c | 69 | 'wt': '4fd6sg89d7s6', # From https://gofile.io/dist/js/alljs.js |
e08585b0 | 70 | } |
71 | password = self.get_param('videopassword') | |
72 | if password: | |
73 | query_params['password'] = hashlib.sha256(password.encode('utf-8')).hexdigest() | |
74 | files = self._download_json( | |
75 | 'https://api.gofile.io/getContent', file_id, note='Getting filelist', query=query_params) | |
b1aaf1c0 J |
76 | |
77 | status = files['status'] | |
e08585b0 | 78 | if status == 'error-passwordRequired': |
79 | raise ExtractorError( | |
80 | 'This video is protected by a password, use the --video-password option', expected=True) | |
81 | elif status != 'ok': | |
b1aaf1c0 J |
82 | raise ExtractorError(f'{self.IE_NAME} said: status {status}', expected=True) |
83 | ||
84 | found_files = False | |
85 | for file in (try_get(files, lambda x: x['data']['contents'], dict) or {}).values(): | |
86 | file_type, file_format = file.get('mimetype').split('/', 1) | |
87 | if file_type not in ('video', 'audio') and file_format != 'vnd.mts': | |
88 | continue | |
89 | ||
90 | found_files = True | |
fcdb8d6e | 91 | file_url = file.get('link') |
b1aaf1c0 J |
92 | if file_url: |
93 | yield { | |
94 | 'id': file['id'], | |
95 | 'title': file['name'].rsplit('.', 1)[0], | |
96 | 'url': file_url, | |
97 | 'filesize': file.get('size'), | |
98 | 'release_timestamp': file.get('createTime') | |
99 | } | |
100 | ||
101 | if not found_files: | |
102 | raise ExtractorError('No video/audio found at provided URL.', expected=True) | |
103 | ||
104 | def _real_extract(self, url): | |
105 | file_id = self._match_id(url) | |
106 | return self.playlist_result(self._entries(file_id), playlist_id=file_id) |