1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-23 03:02:50 +01:00

[gofile] add basic password support (#4056)

This commit is contained in:
Mike Fährmann 2023-05-13 15:46:29 +02:00
parent 790dd365e1
commit e41e45ff6b
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

View File

@ -7,6 +7,7 @@
from .common import Extractor, Message from .common import Extractor, Message
from .. import text, exception from .. import text, exception
from ..cache import memcache from ..cache import memcache
import hashlib
class GofileFolderExtractor(Extractor): class GofileFolderExtractor(Extractor):
@ -66,6 +67,7 @@ class GofileFolderExtractor(Extractor):
def items(self): def items(self):
recursive = self.config("recursive") recursive = self.config("recursive")
password = self.config("password")
token = self.config("api-token") token = self.config("api-token")
if not token: if not token:
@ -78,7 +80,7 @@ class GofileFolderExtractor(Extractor):
token = self._get_website_token() token = self._get_website_token()
self.website_token = token self.website_token = token
folder = self._get_content(self.content_id) folder = self._get_content(self.content_id, password)
yield Message.Directory, folder yield Message.Directory, folder
num = 0 num = 0
@ -115,11 +117,14 @@ class GofileFolderExtractor(Extractor):
page = self.request(self.root + "/contents/files.html").text page = self.request(self.root + "/contents/files.html").text
return text.extract(page, "websiteToken:", ",")[0].strip("\" ") return text.extract(page, "websiteToken:", ",")[0].strip("\" ")
def _get_content(self, content_id): def _get_content(self, content_id, password=None):
if password is not None:
password = hashlib.sha256(password.encode()).hexdigest()
return self._api_request("getContent", { return self._api_request("getContent", {
"contentId" : content_id, "contentId" : content_id,
"token" : self.api_token, "token" : self.api_token,
"websiteToken": self.website_token, "websiteToken": self.website_token,
"password" : password,
}) })
def _api_request(self, endpoint, params=None): def _api_request(self, endpoint, params=None):