3 from .common
import InfoExtractor
4 from ..utils
import ExtractorError
, try_get
7 class GofileIE(InfoExtractor
):
8 _VALID_URL
= r
'https?://(?:www\.)?gofile\.io/d/(?P<id>[^/]+)'
10 'url': 'https://gofile.io/d/AMZyDw',
14 'playlist_mincount': 2,
17 'id': 'de571ac1-5edc-42e2-8ec2-bdac83ad4a31',
21 'release_timestamp': 1638338704,
22 'release_date': '20211201',
26 'url': 'https://gofile.io/d/is8lKr',
32 'skip': 'No video/audio found at provided URL.',
34 'url': 'https://gofile.io/d/TMjXd9',
40 'url': 'https://gofile.io/d/gqOtRf',
44 'playlist_mincount': 1,
46 'videopassword': 'password',
51 def _real_initialize(self
):
52 token
= self
._get
_cookies
('https://gofile.io/').get('accountToken')
54 self
._TOKEN
= token
.value
57 account_data
= self
._download
_json
(
58 'https://api.gofile.io/accounts', None, 'Getting a new guest account', data
=b
'{}')
59 self
._TOKEN
= account_data
['data']['token']
60 self
._set
_cookie
('.gofile.io', 'accountToken', self
._TOKEN
)
62 def _entries(self
, file_id
):
63 query_params
= {'wt': '4fd6sg89d7s6'}
# From https://gofile.io/dist/js/alljs.js
64 password
= self
.get_param('videopassword')
66 query_params
['password'] = hashlib
.sha256(password
.encode('utf-8')).hexdigest()
67 files
= self
._download
_json
(
68 f
'https://api.gofile.io/contents/{file_id}', file_id
, 'Getting filelist',
69 query
=query_params
, headers
={'Authorization': f'Bearer {self._TOKEN}
'})
71 status = files['status
']
72 if status == 'error
-passwordRequired
':
74 'This video
is protected by a password
, use the
--video
-password option
', expected=True)
76 raise ExtractorError(f'{self.IE_NAME} said
: status {status}
', expected=True)
79 for file in (try_get(files, lambda x: x['data
']['children
'], dict) or {}).values():
80 file_type, file_format = file.get('mimetype
').split('/', 1)
81 if file_type not in ('video
', 'audio
') and file_format != 'vnd
.mts
':
85 file_url = file.get('link
')
89 'title
': file['name
'].rsplit('.', 1)[0],
91 'filesize
': file.get('size
'),
92 'release_timestamp
': file.get('createTime
')
96 raise ExtractorError('No video
/audio found at provided URL
.', expected=True)
98 def _real_extract(self, url):
99 file_id = self._match_id(url)
100 return self.playlist_result(self._entries(file_id), playlist_id=file_id)