Skip to content

Commit

Permalink
Fix filename processing
Browse files Browse the repository at this point in the history
  • Loading branch information
fireattack committed Oct 18, 2024
1 parent d226b14 commit 6f53dc9
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions gfile/gfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def get_download_page(self):
return self.data['url']


def download(self, filename=None):
def download(self, output=None):
m = re.search(r'^https?:\/\/\d+?\.gigafile\.nu\/([a-z0-9-]+)$', self.uri)
if not m:
print('Invalid URL.')
Expand Down Expand Up @@ -258,12 +258,15 @@ def download(self, filename=None):

for idx, (web_name, size_str, file_id) in enumerate(files_info, 1):
print(f'Name: {web_name}, size: {size_str}, id: {file_id}')
# only sanitize web filename. User provided ones are on their own.
if not filename:
# only sanitize web filename. User provided output string(s) are on their own.
if not output:
filename = re.sub(r'[\\/:*?"<>|]', '_', web_name)
elif len(files_info) > 1:
# if there are more than one files, append idx to the filename
filename = filename + f'_{idx}'
else:
if len(files_info) > 1:
# if there are more than one files, append idx to the filename
filename = output + f'_{idx}'
else:
filename = output

download_url = self.uri.rsplit('/', 1)[0] + '/download.php?file=' + file_id
if self.key:
Expand All @@ -289,7 +292,7 @@ def download(self, filename=None):
if self.pbar: self.pbar.close()

filesize_downloaded = Path(temp).stat().st_size
print(f'Filesize check: expected: {filesize}; actual: {filesize_downloaded}')
print(f'Filesize check: expected: {filesize}; actual: {filesize_downloaded}', end=' ')
if filesize == filesize_downloaded:
print("Succeeded.")
rename(temp, filename)
Expand Down

0 comments on commit 6f53dc9

Please sign in to comment.