Add duplicate detection
This commit is contained in:
		
							
								
								
									
										25
									
								
								indexer.py
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								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 <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):
 | 
			
		||||
 
 | 
			
		||||
@@ -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">×</span></button>
 | 
			
		||||
			<span class="message">{{ error }}</span>
 | 
			
		||||
			<span class="message">{{ error|safe }}</span>
 | 
			
		||||
		</div>
 | 
			
		||||
		{% endfor %}
 | 
			
		||||
		{% endif %}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user