libdl.py
· 1.2 KiB · Python
Raw
#!/usr/bin/env -S python3 -i
from requests import post
from tabulate import tabulate
from sys import argv
lib = argv[1]
ROOT = "/mnt/storage/_live/{}library.db"
QBT = "http://localhost:8080"
import sqlite3
con = sqlite3.connect(ROOT.format(lib))
cur = con.cursor()
class SORT:
filename=0
size=1
pack=2
def add(hash,_id):
post(f"{QBT}/api/v2/torrents/filePrio", data={"hash": hash, "id": _id, "priority": 1})
post(f"{QBT}/api/v2/torrents/addTags", data={"hashes": hash, "tags": "attn"})
post(f"{QBT}/api/v2/torrents/start", data={"hashes": hash})
print(f"added {hash}:{_id}")
def search(query,*n,sort=SORT.pack):
rows = []
data = []
for a,b,c,d in cur.execute("select hash,`index`,name,size from file where name like ? order by name", (f"%{query}%",)):
_ = c.split("/")
rows.append([_[-1],f"{d/1024/1024:.2f}M",_[0],a,b])
outp = [[n, *row] for n,row in enumerate(sorted(rows,key=lambda row: row[sort]))]
for pick in n:
print(f"adding {outp[pick][1]}...")
add(*outp[pick][-2:])
# if x in n or "*" in n:
# add(a,b)
if not n: print(tabulate([row[:-2] for row in outp], headers=["n",f"filename{' ^' if sort==SORT.filename else ''}",f"size{' ^' if sort==SORT.size else ''}",f"pack{' ^' if sort==SORT.pack else ''}"]))
| 1 | #!/usr/bin/env -S python3 -i |
| 2 | from requests import post |
| 3 | from tabulate import tabulate |
| 4 | from sys import argv |
| 5 | lib = argv[1] |
| 6 | ROOT = "/mnt/storage/_live/{}library.db" |
| 7 | QBT = "http://localhost:8080" |
| 8 | |
| 9 | import sqlite3 |
| 10 | con = sqlite3.connect(ROOT.format(lib)) |
| 11 | cur = con.cursor() |
| 12 | |
| 13 | class SORT: |
| 14 | filename=0 |
| 15 | size=1 |
| 16 | pack=2 |
| 17 | |
| 18 | def add(hash,_id): |
| 19 | post(f"{QBT}/api/v2/torrents/filePrio", data={"hash": hash, "id": _id, "priority": 1}) |
| 20 | post(f"{QBT}/api/v2/torrents/addTags", data={"hashes": hash, "tags": "attn"}) |
| 21 | post(f"{QBT}/api/v2/torrents/start", data={"hashes": hash}) |
| 22 | print(f"added {hash}:{_id}") |
| 23 | |
| 24 | def search(query,*n,sort=SORT.pack): |
| 25 | rows = [] |
| 26 | data = [] |
| 27 | for a,b,c,d in cur.execute("select hash,`index`,name,size from file where name like ? order by name", (f"%{query}%",)): |
| 28 | _ = c.split("/") |
| 29 | rows.append([_[-1],f"{d/1024/1024:.2f}M",_[0],a,b]) |
| 30 | outp = [[n, *row] for n,row in enumerate(sorted(rows,key=lambda row: row[sort]))] |
| 31 | for pick in n: |
| 32 | print(f"adding {outp[pick][1]}...") |
| 33 | add(*outp[pick][-2:]) |
| 34 | # if x in n or "*" in n: |
| 35 | # add(a,b) |
| 36 | if not n: print(tabulate([row[:-2] for row in outp], headers=["n",f"filename{' ^' if sort==SORT.filename else ''}",f"size{' ^' if sort==SORT.size else ''}",f"pack{' ^' if sort==SORT.pack else ''}"])) |
libupdate.py
· 984 B · Python
Raw
#!/usr/bin/env python3
import sqlite3
from sys import argv
from requests import get,post
lib = argv[1]
ROOT = "/mnt/storage/_live/{}library.db"
QBT = "http://localhost:8080"
con = sqlite3.connect(ROOT.format(lib))
cur = con.cursor()
cur.execute("CREATE TABLE IF NOT EXISTS file(hash,'index',size,availability,priority,progress,name)")
j = get(f"{QBT}/api/v2/sync/maindata?rid=0").json()
torrents = {t:v for t,v in j["torrents"].items() if v["category"] == f"{lib}library" and "attn" in v["tags"]}
for n,hash in enumerate(torrents):
if "files" not in torrents[hash]:
torrents[hash]["files"] = get(f"{QBT}/api/v2/torrents/files",params={"hash": hash}).json()
print(n,len(torrents[hash]["files"]))
inp = []
for hash in torrents:
for file in torrents[hash]["files"]:
inp.append((hash,file['index'],file['size'],file['availability'],file['priority'],file['progress'],file['name']))
cur.executemany("INSERT INTO file VALUES(?,?,?,?,?,?,?)",inp)
con.commit()
con.close()
| 1 | #!/usr/bin/env python3 |
| 2 | import sqlite3 |
| 3 | from sys import argv |
| 4 | from requests import get,post |
| 5 | lib = argv[1] |
| 6 | ROOT = "/mnt/storage/_live/{}library.db" |
| 7 | QBT = "http://localhost:8080" |
| 8 | |
| 9 | con = sqlite3.connect(ROOT.format(lib)) |
| 10 | cur = con.cursor() |
| 11 | cur.execute("CREATE TABLE IF NOT EXISTS file(hash,'index',size,availability,priority,progress,name)") |
| 12 | |
| 13 | j = get(f"{QBT}/api/v2/sync/maindata?rid=0").json() |
| 14 | torrents = {t:v for t,v in j["torrents"].items() if v["category"] == f"{lib}library" and "attn" in v["tags"]} |
| 15 | |
| 16 | for n,hash in enumerate(torrents): |
| 17 | if "files" not in torrents[hash]: |
| 18 | torrents[hash]["files"] = get(f"{QBT}/api/v2/torrents/files",params={"hash": hash}).json() |
| 19 | print(n,len(torrents[hash]["files"])) |
| 20 | |
| 21 | inp = [] |
| 22 | for hash in torrents: |
| 23 | for file in torrents[hash]["files"]: |
| 24 | inp.append((hash,file['index'],file['size'],file['availability'],file['priority'],file['progress'],file['name'])) |
| 25 | |
| 26 | cur.executemany("INSERT INTO file VALUES(?,?,?,?,?,?,?)",inp) |
| 27 | con.commit() |
| 28 | con.close() |