shenxianmq / Auto_Symlink

实时监控文件夹,创建与更新软链接/strm文件,自动复制与更新元数据,清空无效文件夹,清空无效软链接
535 stars 57 forks source link

下载模式老是缺少一些目录,只下载strm也是 #16

Closed J666Z closed 2 months ago

J666Z commented 7 months ago

我手动下载小雅的元数据,替换了IP地址,但是他这个地址编码和你你的不一样,有什么办法换成你那种%字符的吗

J666Z commented 7 months ago

用GPT写的代码,部分文件没问题,有些文件名称路径不对,编码也不对,放弃了,只用原来的元数据,STRM还是老老实实的用你的同步 import urllib.parse import os

def encode_strm_files_in_directory(directory_path): for root, dirs, files in os.walk(directory_path): for file_name in files: if file_name.endswith(".strm"): file_path = os.path.join(root, file_name) encode_strm_file(file_path)

def encode_strm_file(file_path): try: with open(file_path, 'r', encoding='utf-8') as file: content = file.read()

        # Encode URI without encoding special symbols
        encoded_content = urllib.parse.quote(content, safe='::/?#[]@!$&\'()*+,;=')

    with open(file_path, 'w', encoding='utf-8') as file:
        file.write(encoded_content)

    print(f"Content in {file_path} has been URL encoded without encoding special symbols.")
except Exception as e:
    print(f"An error occurred processing {file_path}: {e}")

Replace "/path/to/your/directory" with the actual path to your root directory

root_directory = "/media/Lecoo/ZZZ" encode_strm_files_in_directory(root_directory)

102757017 commented 7 months ago

要使用urlparse对路径进行编码。