添加文件信息处理
This commit is contained in:
parent
df8c2ff25b
commit
3a6a98123d
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user