From 3a6a98123d4e23358d33813ff7988978885f90fd Mon Sep 17 00:00:00 2001 From: nyaasuki Date: Tue, 20 Feb 2024 18:49:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=87=E4=BB=B6=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- urls/main.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/urls/main.py b/urls/main.py index 68be196..ea06199 100644 --- a/urls/main.py +++ b/urls/main.py @@ -2,6 +2,7 @@ import os import urllib.parse import argparse import re +import time def natural_sort_key(s): """为了自然排序的辅助函数,将字符串中的数字部分转换成整数""" @@ -15,10 +16,14 @@ def generate_urls(file_names, base_url, sub_directory): base_url += '/' if not sub_directory.endswith('/'): sub_directory += '/' + current_timestamp = int(time.time()) # 获取当前时间的时间戳,转换为整数 for name in sorted(file_names, key=natural_sort_key): # 使用自定义排序 + file_path = os.path.join('.', name) + file_size_bytes = os.path.getsize(file_path) # 获取文件大小(字节),为整数 # 对文件名进行URL编码 encoded_name = urllib.parse.quote(name) - urls.append(f"{base_url}{sub_directory}{encoded_name}") + url = f"{base_url}{sub_directory}{encoded_name}" + urls.append(f"{file_size_bytes}:{current_timestamp}:{url}") return urls def save_urls(urls, output_file):