]>
Commit | Line | Data |
---|---|---|
b1aaf1c0 J |
1 | # coding: utf-8 |
2 | from .common import InfoExtractor | |
3 | from ..utils import ( | |
4 | ExtractorError, | |
5 | try_get | |
6 | ) | |
7 | ||
8 | ||
9 | class GofileIE(InfoExtractor): | |
10 | _VALID_URL = r'https?://(?:www\.)?gofile\.io/d/(?P<id>[^/]+)' | |
11 | _TESTS = [{ | |
12 | 'url': 'https://gofile.io/d/AMZyDw', | |
13 | 'info_dict': { | |
14 | 'id': 'AMZyDw', | |
15 | }, | |
16 | 'playlist_mincount': 2, | |
17 | 'playlist': [{ | |
18 | 'info_dict': { | |
19 | 'id': 'de571ac1-5edc-42e2-8ec2-bdac83ad4a31', | |
20 | 'filesize': 928116, | |
21 | 'ext': 'mp4', | |
22 | 'title': 'nuuh' | |
23 | } | |
24 | }] | |
25 | }, { # URL to test mixed file types | |
26 | 'url': 'https://gofile.io/d/avt34h', | |
27 | 'info_dict': { | |
28 | 'id': 'avt34h', | |
29 | }, | |
30 | 'playlist_mincount': 1, | |
31 | }, { # URL to test no video/audio error | |
32 | 'url': 'https://gofile.io/d/aB03lZ', | |
33 | 'info_dict': { | |
34 | 'id': 'aB03lZ', | |
35 | }, | |
36 | 'playlist_count': 0, | |
37 | 'skip': 'No video/audio found at provided URL.', | |
38 | }] | |
39 | _TOKEN = None | |
40 | ||
41 | def _real_initialize(self): | |
42 | token = self._get_cookies('https://gofile.io/').get('accountToken') | |
43 | if token: | |
44 | self._TOKEN = token.value | |
45 | return | |
46 | ||
47 | account_data = self._download_json( | |
48 | 'https://api.gofile.io/createAccount', None, note='Getting a new guest account') | |
49 | self._TOKEN = account_data['data']['token'] | |
50 | self._set_cookie('gofile.io', 'accountToken', self._TOKEN) | |
51 | ||
52 | def _entries(self, file_id): | |
53 | files = self._download_json( | |
54 | f'https://api.gofile.io/getContent?contentId={file_id}&token={self._TOKEN}&websiteToken=websiteToken&cache=true', | |
55 | 'Gofile', note='Getting filelist') | |
56 | ||
57 | status = files['status'] | |
58 | if status != 'ok': | |
59 | raise ExtractorError(f'{self.IE_NAME} said: status {status}', expected=True) | |
60 | ||
61 | found_files = False | |
62 | for file in (try_get(files, lambda x: x['data']['contents'], dict) or {}).values(): | |
63 | file_type, file_format = file.get('mimetype').split('/', 1) | |
64 | if file_type not in ('video', 'audio') and file_format != 'vnd.mts': | |
65 | continue | |
66 | ||
67 | found_files = True | |
68 | file_url = file.get('directLink') | |
69 | if file_url: | |
70 | yield { | |
71 | 'id': file['id'], | |
72 | 'title': file['name'].rsplit('.', 1)[0], | |
73 | 'url': file_url, | |
74 | 'filesize': file.get('size'), | |
75 | 'release_timestamp': file.get('createTime') | |
76 | } | |
77 | ||
78 | if not found_files: | |
79 | raise ExtractorError('No video/audio found at provided URL.', expected=True) | |
80 | ||
81 | def _real_extract(self, url): | |
82 | file_id = self._match_id(url) | |
83 | return self.playlist_result(self._entries(file_id), playlist_id=file_id) |