Skip to content

Commit

Permalink
Update main.py
Browse files Browse the repository at this point in the history
  • Loading branch information
AlphaSlayer1964 committed Feb 10, 2022
1 parent 582b00d commit d07e22a
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,9 @@ def _download_attachments(self):
broken_file_name = re.search(r'https://www\.patreon\.com/media-u/([^/]+)',attachment['name'])
if broken_file_name:
logger.warning(f"Report this file to kemono.party for having a URL as a file name! file URL: {file_url}")
file_name = os.path.join(self.current_post_path, clean_file_name(f"[{index_string}]_{broken_file_name.group(1)}.{attachment['path'].rsplit('.', 1)[-1]}"))
file_name = os.path.join(self.current_post_path, clean_file_name(f"[{index_string}]_{attachment['name']}.{attachment['path'].rsplit('.', 1)[-1]}"))
if args['no_indexing']:
file_name = os.path.join(self.current_post_path, clean_file_name(f"{broken_file_name.group(1)}.{attachment['path'].rsplit('.', 1)[-1]}"))
file_name = os.path.join(self.current_post_path, clean_file_name(f"{attachment['name']}.{attachment['path'].rsplit('.', 1)[-1]}"))
else:
file_name = os.path.join(self.current_post_path, clean_file_name(f"[{index_string}]_{attachment['name']}"))
if args['no_indexing']:
Expand Down Expand Up @@ -675,10 +675,20 @@ def print_download_bar(total:int, downloaded:int, resumed:int, start):
print(f'[{bar_fill}{bar_empty}] {downloaded}/{total[0]} {total[1]} at {rate[0]} {rate[1]}/s ETA {eta}{overlap_buffer}', end='\r')

def clean_file_name(string:str):
file_split = string.rsplit('.', 1)
if len(file_split) == 1:
file_name = file_split[0]
file_extention = ''
else:
file_name = file_split[0]
file_extention = f".{file_split[1]}"
if args['restrict_names']:
string = restrict_names(string)
file_name = restrict_names(file_name)
file_extention = restrict_names(file_extention)
# if OS_NAME == 'Windows':
return re.sub(r'[\\/:\"*?<>|\n\t\b]','_',string)[:255]
file_extention = re.sub(r'[\\/:\"*?<>|\n\t\b]','_',file_extention)
file_name = re.sub(r'[\\/:\"*?<>|\n\t\b]','_',file_name)[:255-len(file_extention)]
return f"{file_name}{file_extention}"

def clean_folder_name(string:str):
if args['restrict_names']:
Expand Down

0 comments on commit d07e22a

Please sign in to comment.