1- # 本程序仅用于 5.3 更新至 5.4
2- # 已完成:更新配置文件参数
3- # 待完成:迁移旧版下载记录
4-
5-
1+ from asyncio import run
62from json import dump
73from json import load
84from platform import system
95
106from src .config import Settings
117from src .custom import PROJECT_ROOT
8+ from src .manager import Database
129
1310SETTING_ROOT = PROJECT_ROOT .joinpath ("settings.json" )
1411ENCODE = "UTF-8-SIG" if system () == "Windows" else "UTF-8"
1512
1613
1714def about ():
18- print ("本程序仅用于 5 .3 更新至 5 .4!" )
15+ print ("本程序仅适用于 TikTokDownloader V5 .3 更新至 V5 .4!" )
1916 print ("请确保本程序放置于 main.py 或 main.exe 同级文件夹!" )
17+ print ("本程序功能:" )
18+ print ("更新配置文件参数" )
19+ print ("迁移旧版映射数据" )
20+ print ("迁移旧版下载记录" )
2021
2122
2223def update_params ():
@@ -28,11 +29,37 @@ def update_params():
2829 print ("已更新配置文件!" )
2930
3031
31- def main ():
32+ async def update_map (db ):
33+ with PROJECT_ROOT .joinpath ("cache/AccountCache.json" ).open ("r+" , encoding = "utf-8" ) as f :
34+ data = load (f )
35+ for i , j in data .items ():
36+ await db .update_mapping_data (i , j ["name" ], j ["mark" ])
37+ print ("写入映射" , i , j ["name" ], j ["mark" ])
38+ print ("已更新映射数据!" )
39+
40+
41+ async def update_record (db ):
42+ with PROJECT_ROOT .joinpath ("cache/IDRecorder.txt" ).open ("r+" , encoding = "utf-8" ) as f :
43+ data = {line .strip () for line in f }
44+ for i in data :
45+ await db .write_download_data (i )
46+ print ("写入记录" , i )
47+ print ("已更新下载记录!" )
48+
49+
50+ async def main ():
3251 about ()
52+ if input ("直接回车继续执行,输入任意内容结束运行:" ):
53+ return
3354 if not input ("即将更新配置文件,直接回车继续执行,输入任意内容跳过执行:" ):
3455 update_params ()
56+ async with Database () as db :
57+ if not input ("即将迁移映射数据,直接回车继续执行,输入任意内容跳过执行:" ):
58+ await update_map (db )
59+ if not input ("即将迁移下载记录,直接回车继续执行,输入任意内容跳过执行:" ):
60+ await update_record (db )
61+ print ("程序运行完成!" )
3562
3663
3764if __name__ == '__main__' :
38- main ()
65+ run ( main () )
0 commit comments