From d0e94572115d3673d531409fb37b1f77afe774d3 Mon Sep 17 00:00:00 2001 From: sqozz Date: Fri, 29 Dec 2017 06:26:22 +0100 Subject: [PATCH] Add details from database to details page --- indexer.py | 29 ++++++++++++++++++++++++++--- templates/details.html | 30 +++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/indexer.py b/indexer.py index fca7023..71f050c 100644 --- a/indexer.py +++ b/indexer.py @@ -91,8 +91,9 @@ def search(): @app.route("/details", methods=['GET']) def details(): info_hash = request.args["h"] - print(info_hash) - return render_template("details.html", categories=get_categories()) + tf = TorrentFile(fileid=info_hash) + tf.fromDb() + return render_template("details.html", categories=get_categories(), torrent=tf) def scrapeAll(): TRACKER_URL = "http://tracker.lootbox.cf:6969/" @@ -189,6 +190,7 @@ class TorrentFile(): description = None audioquality_description = None videoquality_description = None + def __init__(self, fileid=fileid, name=name, category=category, subcategory=subcategory, description=description, audioquality_description=audioquality_description, videoquality_description=videoquality_description): self.fileid = fileid self.name = name @@ -197,7 +199,8 @@ class TorrentFile(): self.description = description self.audioquality_description = audioquality_description self.videoquality_description = videoquality_description - self.metadata = Metadata(fileid) + if self.fileid: + self.metadata = Metadata(fileid) def writeToDb(self, cursor): c = cursor @@ -206,6 +209,26 @@ class TorrentFile(): b64videoquality_description = base64.b64encode(self.videoquality_description.encode()) c.execute("INSERT INTO torrents(fileid, name, category, subcategory, description, audioquality_description, videoquality_description) VALUES(:fileid, :name, :category, :subcategory, :description, :audioquality_description, :videoquality_description)", { 'fileid' : self.fileid, 'name' : self.name, 'category' : self.category, 'subcategory' : self.subcategory, 'description' : b64description , 'audioquality_description' : b64audioquality_description, 'videoquality_description' : b64videoquality_description}) + def fromDb(self): + def dict_factory(cursor, row): + d = {} + for idx, col in enumerate(cursor.description): + d[col[0]] = row[idx] + return d + + con = sqlite3.connect("torrentdb.sqlite") + con.row_factory = dict_factory + c = con.cursor() + res = c.execute("SELECT torrents.*, metadata.* FROM torrents LEFT JOIN metadata on metadata.fileid = torrents.fileid WHERE torrents.fileid LIKE :fileid", { "fileid" : self.fileid }) + res = res.fetchone() + self.fileid = res["fileid"] + self.name = (base64.b64decode(res["name"])).decode() + self.category = res["category"] + self.subcategory = res["subcategory"] + self.description = (base64.b64decode(res["description"])).decode() + self.audioquality_description = (base64.b64decode(res["audioquality_description"])).decode() + self.videoquality_description = (base64.b64decode(res["videoquality_description"])).decode() + @babel.localeselector def get_locale(): return request.accept_languages.best_match(LANGUAGES) diff --git a/templates/details.html b/templates/details.html index 03d8f55..7062b64 100644 --- a/templates/details.html +++ b/templates/details.html @@ -7,5 +7,33 @@ vim: ts=2 noexpandtab {% block content %} -

DETAILS

+

DETAILS

+
+Info ID: +{{ torrent.fileid }} +
+
+Name: +{{ torrent.name }} +
+
+Category: +{{ torrent.category }} +
+
+Subcategory: +{{ torrent.subcategory }} +
+
+Description: +{{ torrent.description }} +
+
+Audio quality: +{{ torrent.audioquality_description }} +
+
+Video quality: +{{ torrent.videoquality_description }} +
{% endblock content%}