2022-04-20 09:43:15 +00:00
|
|
|
import hashlib
|
|
|
|
|
2021-12-09 12:25:30 +00:00
|
|
|
from .common import InfoExtractor
|
|
|
|
from ..utils import (
|
|
|
|
ExtractorError,
|
|
|
|
try_get
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class GofileIE(InfoExtractor):
|
|
|
|
_VALID_URL = r'https?://(?:www\.)?gofile\.io/d/(?P<id>[^/]+)'
|
|
|
|
_TESTS = [{
|
|
|
|
'url': 'https://gofile.io/d/AMZyDw',
|
|
|
|
'info_dict': {
|
|
|
|
'id': 'AMZyDw',
|
|
|
|
},
|
|
|
|
'playlist_mincount': 2,
|
|
|
|
'playlist': [{
|
|
|
|
'info_dict': {
|
|
|
|
'id': 'de571ac1-5edc-42e2-8ec2-bdac83ad4a31',
|
|
|
|
'filesize': 928116,
|
|
|
|
'ext': 'mp4',
|
2022-04-11 04:29:19 +00:00
|
|
|
'title': 'nuuh',
|
|
|
|
'release_timestamp': 1638338704,
|
|
|
|
'release_date': '20211201',
|
2021-12-09 12:25:30 +00:00
|
|
|
}
|
|
|
|
}]
|
2022-04-11 04:29:19 +00:00
|
|
|
}, {
|
|
|
|
'url': 'https://gofile.io/d/is8lKr',
|
2021-12-09 12:25:30 +00:00
|
|
|
'info_dict': {
|
2022-04-11 04:29:19 +00:00
|
|
|
'id': 'TMjXd9',
|
|
|
|
'ext': 'mp4',
|
2021-12-09 12:25:30 +00:00
|
|
|
},
|
|
|
|
'playlist_count': 0,
|
|
|
|
'skip': 'No video/audio found at provided URL.',
|
2022-04-11 04:29:19 +00:00
|
|
|
}, {
|
|
|
|
'url': 'https://gofile.io/d/TMjXd9',
|
|
|
|
'info_dict': {
|
|
|
|
'id': 'TMjXd9',
|
|
|
|
},
|
|
|
|
'playlist_count': 1,
|
2022-04-20 09:43:15 +00:00
|
|
|
}, {
|
|
|
|
'url': 'https://gofile.io/d/gqOtRf',
|
|
|
|
'info_dict': {
|
|
|
|
'id': 'gqOtRf',
|
|
|
|
},
|
|
|
|
'playlist_mincount': 1,
|
|
|
|
'params': {
|
|
|
|
'videopassword': 'password',
|
|
|
|
},
|
2021-12-09 12:25:30 +00:00
|
|
|
}]
|
|
|
|
_TOKEN = None
|
|
|
|
|
|
|
|
def _real_initialize(self):
|
|
|
|
token = self._get_cookies('https://gofile.io/').get('accountToken')
|
|
|
|
if token:
|
|
|
|
self._TOKEN = token.value
|
|
|
|
return
|
|
|
|
|
|
|
|
account_data = self._download_json(
|
|
|
|
'https://api.gofile.io/createAccount', None, note='Getting a new guest account')
|
|
|
|
self._TOKEN = account_data['data']['token']
|
2023-10-04 17:44:13 +00:00
|
|
|
self._set_cookie('.gofile.io', 'accountToken', self._TOKEN)
|
2021-12-09 12:25:30 +00:00
|
|
|
|
|
|
|
def _entries(self, file_id):
|
2022-04-20 09:43:15 +00:00
|
|
|
query_params = {
|
2022-04-11 04:29:19 +00:00
|
|
|
'contentId': file_id,
|
|
|
|
'token': self._TOKEN,
|
2023-09-05 19:58:02 +00:00
|
|
|
'websiteToken': '7fd94ds12fds4', # From https://gofile.io/dist/js/alljs.js
|
2022-04-20 09:43:15 +00:00
|
|
|
}
|
|
|
|
password = self.get_param('videopassword')
|
|
|
|
if password:
|
|
|
|
query_params['password'] = hashlib.sha256(password.encode('utf-8')).hexdigest()
|
|
|
|
files = self._download_json(
|
|
|
|
'https://api.gofile.io/getContent', file_id, note='Getting filelist', query=query_params)
|
2021-12-09 12:25:30 +00:00
|
|
|
|
|
|
|
status = files['status']
|
2022-04-20 09:43:15 +00:00
|
|
|
if status == 'error-passwordRequired':
|
|
|
|
raise ExtractorError(
|
|
|
|
'This video is protected by a password, use the --video-password option', expected=True)
|
|
|
|
elif status != 'ok':
|
2021-12-09 12:25:30 +00:00
|
|
|
raise ExtractorError(f'{self.IE_NAME} said: status {status}', expected=True)
|
|
|
|
|
|
|
|
found_files = False
|
|
|
|
for file in (try_get(files, lambda x: x['data']['contents'], dict) or {}).values():
|
|
|
|
file_type, file_format = file.get('mimetype').split('/', 1)
|
|
|
|
if file_type not in ('video', 'audio') and file_format != 'vnd.mts':
|
|
|
|
continue
|
|
|
|
|
|
|
|
found_files = True
|
2022-04-11 04:29:19 +00:00
|
|
|
file_url = file.get('link')
|
2021-12-09 12:25:30 +00:00
|
|
|
if file_url:
|
|
|
|
yield {
|
|
|
|
'id': file['id'],
|
|
|
|
'title': file['name'].rsplit('.', 1)[0],
|
|
|
|
'url': file_url,
|
|
|
|
'filesize': file.get('size'),
|
|
|
|
'release_timestamp': file.get('createTime')
|
|
|
|
}
|
|
|
|
|
|
|
|
if not found_files:
|
|
|
|
raise ExtractorError('No video/audio found at provided URL.', expected=True)
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
|
|
|
file_id = self._match_id(url)
|
|
|
|
return self.playlist_result(self._entries(file_id), playlist_id=file_id)
|