2019-02-22-Python实现BaiduPCS-Go脚本生成

Python实现BaiduPCS-Go脚本生成

github地址:https://github.com/silas1037/db_file2cmd_list

之前写了一篇如何利用自己的网盘数据库生成支持BaiduPCS-Go秒传命令的文章,生成批处理脚本的过程实在是繁琐。干脆写了一个Python脚本,可以通过手动选择BaiduYunCacheFileV0.db文件生成批处理脚本。使用很简单就不说了。需要注意的是,生成的脚本是utf-8编码格式,可以通过先输入chcp 65001命令,进而调用批处理的方式,支持utf-8运行。

使用说明:

生成此脚本的作用: https://www.jianshu.com/p/8396a982e748
背景项目: https://github.com/iikira/BaiduPCS-Go

releases

为什么有些文件可以秒传有些不行?秒传是什么条件?
经本人测试,如果一个文件被两个账号上传过,则这个文件就进入了秒传的“高贵”行列。这时任意第三个账号均可以通过ru命令进行虚拟秒传,然后便可以被下载至本地。所以,我直接通过“秒传法”发布下面一个已经编译好的pe文件,给各位不方便编译的使用吧。

1
ru -length=8547037 -md5=C4F76103263BB44BCE152058054365B2 export_baiduyun_db.exe

程序窗体:

image1.png

Python代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63

#!/usr/bin/env python3
# -*- coding:utf-8 -*-

from tkinter import *
from tkinter.filedialog import askopenfilename
from tkinter.filedialog import asksaveasfilename
from tkinter.ttk import *
import sqlite3


def select_db_file():
db_file = askopenfilename(title="请选择BaiduYunCacheFileV0.db文件", filetypes=[('db', '*.db')])
db.set(db_file)


def select_save_file():
save_file = asksaveasfilename(filetypes=[('文件', '*.bat')])
f.set(save_file + ".bat")


def create_baiduyun_filelist():
conn = sqlite3.connect(db.get())
cursor = conn.cursor()
cursor.execute("select * from cache_file")
while True:
value = cursor.fetchone()
if not value:
break
path = value[2]
name = value[3]
size = value[4]
md5 = value[5]
if size!=0:
with open(f.get(), "a", encoding='utf-8') as fp:
fp.write('BaiduPCS-Go ru -length='+ str(size) + ' -md5=' + str(md5) + ' "' + str(path) + str(name) +'"'+'\n')


with open(f.get(), "a", encoding='utf-8') as fp:
fp.write('pause')
fp.close()




root = Tk()
root.title('百度云文件BaiduPCS-Go秒传批处理生成')
db_select = Button(root, text=' 选择DB文件 ', command=select_db_file)
db_select.grid(row=1, column=1, sticky=W, padx=(2, 0), pady=(2, 0))
db = StringVar()
db_path = Entry(root, width=80, textvariable=db)
db_path['state'] = 'readonly'
db_path.grid(row=1, column=2, padx=3, pady=3, sticky=W + E)
save_path = Button(root, text='选择保存地址', command=select_save_file)
save_path.grid(row=2, column=1, sticky=W, padx=(2, 0), pady=(2, 0))
f = StringVar()
file_path = Entry(root, width=80, textvariable=f)
file_path['state'] = 'readonly'
file_path.grid(row=2, column=2, padx=3, pady=3, sticky=W + E)
create_btn = Button(root, text='生成BaiduPCS-Go秒传批处理命令行', command=create_baiduyun_filelist)
create_btn.grid(row=3, column=1, columnspan=2, pady=(0, 2))
root.columnconfigure(2, weight=1)
root.mainloop()