Add duplicate detection

This commit is contained in:
sqozz 2017-12-29 00:31:28 +01:00
parent 88b9a32b5f
commit 2256e6f2de
2 changed files with 19 additions and 8 deletions

View File

@ -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 <a href=\"/search?h={}\">{}</a> 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):

View File

@ -13,7 +13,7 @@ vim: ts=2 noexpandtab
{% for error in errors %}
<div class="alert alert-danger alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<span class="message">{{ error }}</span>
<span class="message">{{ error|safe }}</span>
</div>
{% endfor %}
{% endif %}