Add duplicate detection
This commit is contained in:
parent
88b9a32b5f
commit
2256e6f2de
15
indexer.py
15
indexer.py
|
@ -64,6 +64,10 @@ def search():
|
||||||
elif field is "s":
|
elif field is "s":
|
||||||
search_params += query.split(" ")
|
search_params += query.split(" ")
|
||||||
search += " AND ".join(["torrents.subcategory LIKE (?)"] * len(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)
|
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)
|
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:
|
with open("settings.json") as settingsJson:
|
||||||
settings = json.load(settingsJson)
|
settings = json.load(settingsJson)
|
||||||
initDb()
|
initDb()
|
||||||
scrapeAll()
|
#scrapeAll()
|
||||||
|
|
||||||
def initDb():
|
def initDb():
|
||||||
connection = sqlite3.connect("torrentdb.sqlite")
|
connection = sqlite3.connect("torrentdb.sqlite")
|
||||||
|
@ -134,12 +138,19 @@ def createNewTorrent(reuqest):
|
||||||
audioquality_description = request.form["audioquality_description"]
|
audioquality_description = request.form["audioquality_description"]
|
||||||
videoquality_description = request.form["videoquality_description"]
|
videoquality_description = request.form["videoquality_description"]
|
||||||
newTFile = TorrentFile(info_hash, name, category, subcategory, description, audioquality_description, videoquality_description)
|
newTFile = TorrentFile(info_hash, name, category, subcategory, description, audioquality_description, videoquality_description)
|
||||||
|
try:
|
||||||
connection = sqlite3.connect("torrentdb.sqlite")
|
connection = sqlite3.connect("torrentdb.sqlite")
|
||||||
newTFile.writeToDb(connection.cursor())
|
newTFile.writeToDb(connection.cursor())
|
||||||
newTFile.metadata.writeToDb(connection.cursor())
|
newTFile.metadata.writeToDb(connection.cursor())
|
||||||
connection.commit()
|
connection.commit()
|
||||||
connection.close()
|
connection.close()
|
||||||
return ["Error1"]
|
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():
|
class Metadata():
|
||||||
def __init__(self, fileid):
|
def __init__(self, fileid):
|
||||||
|
|
|
@ -13,7 +13,7 @@ vim: ts=2 noexpandtab
|
||||||
{% for error in errors %}
|
{% for error in errors %}
|
||||||
<div class="alert alert-danger alert-dismissible" role="alert">
|
<div class="alert alert-danger alert-dismissible" role="alert">
|
||||||
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
|
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||||
<span class="message">{{ error }}</span>
|
<span class="message">{{ error|safe }}</span>
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
Loading…
Reference in a new issue