Skip to content

Commit

Permalink
Add support for dlkey (use --key)
Browse files Browse the repository at this point in the history
  • Loading branch information
fireattack committed Aug 22, 2024
1 parent 875e02a commit f9210f6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions gfile/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def main():
parser.add_argument('-s', '--chunk-size', dest='chunk_size', default="100MB", help='chunk size per upload in bytes; note: chunk_size*thread will be loaded into memory [default: 100MB]')
parser.add_argument('-m', '--copy-size', dest='chunk_copy_size', default="1MB", help='specifies size to copy the main file into pieces [default: 1MB]')
parser.add_argument('-t', '--timeout', type=int, default=10, help='specifies timeout time (in seconds) [default: 10]')
parser.add_argument('-k', '--key', '--password', dest='key', default=None, help='specifies the key/password for the file')

args = parser.parse_args()

Expand Down
5 changes: 4 additions & 1 deletion gfile/gfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def split_file(input_file, out, target_size=None, start=0, chunk_copy_size=1024*


class GFile:
def __init__(self, uri, progress=False, thread_num=4, chunk_size=1024*1024*10, chunk_copy_size=1024*1024, timeout=10, aria2=False, **kwargs) -> None:
def __init__(self, uri, progress=False, thread_num=4, chunk_size=1024*1024*10, chunk_copy_size=1024*1024, timeout=10, aria2=False, key=None, **kwargs) -> None:
self.uri = uri
self.chunk_size = size_str_to_bytes(chunk_size)
self.chunk_copy_size = size_str_to_bytes(chunk_copy_size)
Expand All @@ -94,6 +94,7 @@ def __init__(self, uri, progress=False, thread_num=4, chunk_size=1024*1024*10, c
self.cookies = None
self.current_chunk = 0
self.aria2 = aria2
self.key = key


def upload_chunk(self, chunk_no, chunks):
Expand Down Expand Up @@ -247,6 +248,8 @@ def download(self, filename=None):
# only sanitize web filename. User provided ones are on their own.
filename = re.sub(r'[\\/:*?"<>|]', '_', web_name)
download_url = self.uri.rsplit('/', 1)[0] + '/download.php?file=' + file_id
if self.key:
download_url += f'&dlkey={self.key}'
if self.aria2:
cookie_str = "; ".join([f"{cookie.name}={cookie.value}" for cookie in self.session.cookies])
cmd = ['aria2c', download_url, '--header', f'Cookie: {cookie_str}', '-o', filename]
Expand Down

0 comments on commit f9210f6

Please sign in to comment.