1
0
Fork 0
mirror of https://gitlab.com/SIGBUS/nyaa.git synced 2024-11-05 11:25:54 +00:00
nyaa/utils/infodict_mysql2file.py
nyaadev f38d7e0707 remove broken offset option from infodict_mysql2file.py
could've probably fixed it with ORDER BY but lazy
2018-02-03 21:05:24 +01:00

47 lines
1 KiB
Python
Executable file

#!/usr/bin/python
import os
import sys
import MySQLdb
import MySQLdb.cursors
if len(sys.argv) != 3:
print("Usage: {0} <prefix(nyaa|sukebei)> <outdir(info_dicts)>".format(sys.argv[0]))
sys.exit(1)
prefix = sys.argv[1]
outdir = sys.argv[2]
if not os.path.exists(outdir):
os.makedirs(outdir)
db = MySQLdb.connect(host='localhost',
user='test',
passwd='test123',
db='nyaav2',
cursorclass=MySQLdb.cursors.SSCursor)
cur = db.cursor()
cur.execute(
"""SELECT
id,
info_hash,
info_dict
FROM
{0}_torrents
JOIN {0}_torrents_info ON torrent_id = id
""".format(prefix))
for row in cur:
id = row[0]
info_hash = row[1].hex().lower()
info_dict = row[2]
path = os.path.join(outdir, info_hash[0:2], info_hash[2:4])
if not os.path.exists(path):
os.makedirs(path)
path = os.path.join(path, info_hash)
with open(path, 'wb') as fp:
fp.write(info_dict)