1.需求:
在excel中,一列是MP4的下载地址,一列是mp4对应的视频名称,使用迅雷把mp4和名字对应并且下载
2.环境配置:
win10 专业版64位
python3.7
迅雷10
3.代码实现:
from win32com.client import Dispatch
import xlrd
# thunder = Dispatch("ThunderAgent.Agent64.1")
thunder = Dispatch("ThunderAgent.Agent.1")
def to_select(res_src):
book = xlrd.open_workbook(res_src)
table = book.sheet_by_name("Sheet1")
keys = table.col_values(2) # 这是第3列数据,作为字典的key值
vals = table.col_values(1) # 作为值
keys2 = []
vals2 = []
for k in keys:
k = k.strip()
keys2.append(k)
for v in vals:
v = v.strip()
vals2.append(v)
return dict(zip(keys2, vals2))
def to_down(dic, down_src):
print(dic)
for t_src in dic.keys():
# AddTask("下载地址", "另存文件名", "保存目录","任务注释","引用地址","开始模式", "只从原始地址下载","从原始地址下载线程数")
thunder.AddTask(t_src, dic[t_src]+".mp4", down_src, "", "", -1, 0, 5)
thunder.CommitTasks()
if __name__ == "__main__":
res_path = r"D:\中文字幕.xlsx"
down_path = r"E:\Temp\TempVideo"
dic = to_select(res_path)
to_down(dic, down_path)
4.说明:
转载请说明出处!!!