]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/extractor/gofile.py
[misc] Add `hatch`, `ruff`, `pre-commit` and improve dev docs (#7409)
[yt-dlp.git] / yt_dlp / extractor / gofile.py
index 858bac52c3a2810a5809b1c2f7c134d73522fd49..fac08846213986d9beb71ab3a80be32d90c56eeb 100644 (file)
@@ -1,9 +1,7 @@
-# coding: utf-8
+import hashlib
+
 from .common import InfoExtractor
-from ..utils import (
-    ExtractorError,
-    try_get
-)
+from ..utils import ExtractorError, try_get
 
 
 class GofileIE(InfoExtractor):
@@ -38,6 +36,15 @@ class GofileIE(InfoExtractor):
             'id': 'TMjXd9',
         },
         'playlist_count': 1,
+    }, {
+        'url': 'https://gofile.io/d/gqOtRf',
+        'info_dict': {
+            'id': 'gqOtRf',
+        },
+        'playlist_mincount': 1,
+        'params': {
+            'videopassword': 'password',
+        },
     }]
     _TOKEN = None
 
@@ -48,23 +55,28 @@ def _real_initialize(self):
             return
 
         account_data = self._download_json(
-            'https://api.gofile.io/createAccount', None, note='Getting a new guest account')
+            'https://api.gofile.io/accounts', None, 'Getting a new guest account', data=b'{}')
         self._TOKEN = account_data['data']['token']
-        self._set_cookie('gofile.io', 'accountToken', self._TOKEN)
+        self._set_cookie('.gofile.io', 'accountToken', self._TOKEN)
 
     def _entries(self, file_id):
-        files = self._download_json('https://api.gofile.io/getContent', 'Gofile', note='Getting filelist', query={
-            'contentId': file_id,
-            'token': self._TOKEN,
-            'websiteToken': 12345,
-        })
+        query_params = {'wt': '4fd6sg89d7s6'}  # From https://gofile.io/dist/js/alljs.js
+        password = self.get_param('videopassword')
+        if password:
+            query_params['password'] = hashlib.sha256(password.encode('utf-8')).hexdigest()
+        files = self._download_json(
+            f'https://api.gofile.io/contents/{file_id}', file_id, 'Getting filelist',
+            query=query_params, headers={'Authorization': f'Bearer {self._TOKEN}'})
 
         status = files['status']
-        if status != 'ok':
+        if status == 'error-passwordRequired':
+            raise ExtractorError(
+                'This video is protected by a password, use the --video-password option', expected=True)
+        elif status != 'ok':
             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():
+        for file in (try_get(files, lambda x: x['data']['children'], 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