This commit is contained in:
2026-02-04 05:59:17 +01:00
parent 3d11661997
commit aff7993093
2 changed files with 303 additions and 0 deletions

View File

@@ -0,0 +1,89 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import pymysql
import bencodepy
# ===============================
# DB CONFIG
# ===============================
DB_CONFIG = dict(
host="192.168.1.50",
user="root",
password="Vlado9674+",
database="torrents",
charset="utf8mb4"
)
LIMIT = 5 # kolik torrentů zobrazit
# ===============================
# TORRENT PARSER
# ===============================
def parse_torrent(blob):
data = bencodepy.decode(blob)
info = data[b'info']
files = []
# multi-file torrent
if b'files' in info:
for f in info[b'files']:
path = "/".join(p.decode(errors="ignore") for p in f[b'path'])
size = f[b'length']
files.append((path, size))
# single-file torrent
else:
name = info[b'name'].decode(errors="ignore")
size = info[b'length']
files.append((name, size))
return files
# ===============================
# MAIN
# ===============================
def main():
conn = pymysql.connect(**DB_CONFIG)
cur = conn.cursor()
cur.execute(f"""
SELECT id, title_visible, qb_savepath, torrent_content
FROM torrents
WHERE torrent_content IS NOT NULL
LIMIT {LIMIT}
""")
rows = cur.fetchall()
for tid, title, savepath, blob in rows:
print("\n" + "="*80)
print(f"Torrent ID : {tid}")
print(f"Title : {title}")
print(f"Savepath : {savepath}")
try:
files = parse_torrent(blob)
print(f"Files inside torrent: {len(files)}")
for path, size in files:
print(f" {size:>12} B {path}")
except Exception as e:
print("ERROR parsing torrent:", e)
cur.close()
conn.close()
if __name__ == "__main__":
main()