From 2256e6f2de7e6dde9cad71f073192db48df1fc11 Mon Sep 17 00:00:00 2001 From: sqozz Date: Fri, 29 Dec 2017 00:31:28 +0100 Subject: [PATCH] Add duplicate detection --- indexer.py | 25 ++++++++++++++++++------- templates/create.html | 2 +- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/indexer.py b/indexer.py index 4e68127..12fb3ee 100644 --- a/indexer.py +++ b/indexer.py @@ -64,6 +64,10 @@ def search(): elif field is "s": search_params += query.split(" ") search += " AND ".join(["torrents.subcategory LIKE (?)"] * len(query.split(" "))) + elif field is "h": + hashes = query.split(" ") + search_params += list(map(lambda x: x + "%", hashes)) + search += " AND ".join(["torrents.fileid LIKE (?)"] * len(query.split(" "))) print(search) c.execute("SELECT torrents.fileid, torrents.name, metadata.torrentsize FROM torrents LEFT JOIN metadata on metadata.fileid = torrents.fileid WHERE " + search, search_params) @@ -85,7 +89,7 @@ def init(): with open("settings.json") as settingsJson: settings = json.load(settingsJson) initDb() - scrapeAll() + #scrapeAll() def initDb(): connection = sqlite3.connect("torrentdb.sqlite") @@ -134,12 +138,19 @@ def createNewTorrent(reuqest): audioquality_description = request.form["audioquality_description"] videoquality_description = request.form["videoquality_description"] newTFile = TorrentFile(info_hash, name, category, subcategory, description, audioquality_description, videoquality_description) - connection = sqlite3.connect("torrentdb.sqlite") - newTFile.writeToDb(connection.cursor()) - newTFile.metadata.writeToDb(connection.cursor()) - connection.commit() - connection.close() - return ["Error1"] + try: + connection = sqlite3.connect("torrentdb.sqlite") + newTFile.writeToDb(connection.cursor()) + newTFile.metadata.writeToDb(connection.cursor()) + connection.commit() + connection.close() + return ["Success"] + except sqlite3.IntegrityError as e: + print(e) + return ["Torrent {} does already exist".format(info_hash, info_hash[:-20])] + except Exception as e: + print(e) + return ["Unknown error in creation"] class Metadata(): def __init__(self, fileid): diff --git a/templates/create.html b/templates/create.html index bfbef7d..28f708e 100644 --- a/templates/create.html +++ b/templates/create.html @@ -13,7 +13,7 @@ vim: ts=2 noexpandtab {% for error in errors %} {% endfor %} {% endif %}