]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/extractor/gofile.py
[cleanup] Misc
[yt-dlp.git] / yt_dlp / extractor / gofile.py
index 62d778cfec5813a0b34ebdb58112343c682ddaf3..ddbce2ee8f2c247cf9836813a32f94cc4eae3eb3 100644 (file)
@@ -1,4 +1,5 @@
-# coding: utf-8
+import hashlib
+
 from .common import InfoExtractor
 from ..utils import (
     ExtractorError,
@@ -19,22 +20,34 @@ class GofileIE(InfoExtractor):
                 'id': 'de571ac1-5edc-42e2-8ec2-bdac83ad4a31',
                 'filesize': 928116,
                 'ext': 'mp4',
-                'title': 'nuuh'
+                'title': 'nuuh',
+                'release_timestamp': 1638338704,
+                'release_date': '20211201',
             }
         }]
-    }, {  # URL to test mixed file types
-        'url': 'https://gofile.io/d/avt34h',
+    }, {
+        'url': 'https://gofile.io/d/is8lKr',
         'info_dict': {
-            'id': 'avt34h',
-        },
-        'playlist_mincount': 1,
-    }, {  # URL to test no video/audio error
-        'url': 'https://gofile.io/d/aB03lZ',
-        'info_dict': {
-            'id': 'aB03lZ',
+            'id': 'TMjXd9',
+            'ext': 'mp4',
         },
         'playlist_count': 0,
         'skip': 'No video/audio found at provided URL.',
+    }, {
+        'url': 'https://gofile.io/d/TMjXd9',
+        'info_dict': {
+            'id': 'TMjXd9',
+        },
+        'playlist_count': 1,
+    }, {
+        'url': 'https://gofile.io/d/gqOtRf',
+        'info_dict': {
+            'id': 'gqOtRf',
+        },
+        'playlist_mincount': 1,
+        'params': {
+            'videopassword': 'password',
+        },
     }]
     _TOKEN = None
 
@@ -50,12 +63,22 @@ def _real_initialize(self):
         self._set_cookie('gofile.io', 'accountToken', self._TOKEN)
 
     def _entries(self, file_id):
+        query_params = {
+            'contentId': file_id,
+            'token': self._TOKEN,
+            'websiteToken': 12345,
+        }
+        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/getContent?contentId={file_id}&token={self._TOKEN}&websiteToken=websiteToken&cache=true',
-            'Gofile', note='Getting filelist')
+            'https://api.gofile.io/getContent', file_id, note='Getting filelist', query=query_params)
 
         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
@@ -65,7 +88,7 @@ def _entries(self, file_id):
                 continue
 
             found_files = True
-            file_url = file.get('directLink')
+            file_url = file.get('link')
             if file_url:
                 yield {
                     'id': file['id'],