From 83ebd9d0ff90c10e0632110fbf379ed4511fd74d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B2=9B=E9=A3=8E?= Date: Thu, 27 Jun 2024 01:38:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AD=90=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E7=9A=84=E9=94=99=E8=AF=AFurl=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- urls/main.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/urls/main.py b/urls/main.py index 2b1c9aa..9eae348 100644 --- a/urls/main.py +++ b/urls/main.py @@ -9,13 +9,11 @@ def natural_sort_key(s): """为了自然排序的辅助函数,将字符串中的数字部分转换成整数""" return [int(text) if text.isdigit() else text.lower() for text in re.split('([0-9]+)', s)] -def generate_urls(file_paths, base_url, sub_directory, min_size): - """根据文件路径、基础URL、子目录和最小文件大小生成URL链接""" +def generate_urls(file_paths, base_url, min_size): + """根据文件路径、基础URL和最小文件大小生成URL链接""" urls = {} if not base_url.endswith('/'): base_url += '/' - if sub_directory and not sub_directory.endswith('/'): - sub_directory += '/' current_timestamp = int(time.time()) # 移到循环外 for path in sorted(file_paths, key=natural_sort_key): file_size_bytes = os.path.getsize(path) @@ -23,7 +21,7 @@ def generate_urls(file_paths, base_url, sub_directory, min_size): continue relative_path = os.path.relpath(path, start='.') encoded_path = urllib.parse.quote(relative_path) - url = f"{base_url}{sub_directory}{encoded_path}" + url = f"{base_url}{encoded_path}" dir_name = os.path.dirname(relative_path) if dir_name not in urls: urls[dir_name] = [] @@ -69,7 +67,7 @@ def main(): current_script = os.path.basename(__file__) exclude_files = {current_script} # 排除当前脚本文件 file_paths = list_files_recursive('.', exclude_files) - urls = generate_urls(file_paths, args.base_url, args.dir, args.min_size) + urls = generate_urls(file_paths, args.base_url, args.min_size) save_urls(urls, args.output, args.rf) print(f"URL链接已保存到{args.output}")