From 2c220afced34cda8eae3964677b1fb4fc5785a48 Mon Sep 17 00:00:00 2001 From: sqozz Date: Fri, 29 Dec 2017 04:57:37 +0100 Subject: [PATCH] Rework categories and stuff --- indexer.py | 31 +++--- settings.json | 195 ++++++++++++++++++++++++++++++++++++-- static/js/create.js | 74 ++++++--------- templates/categories.html | 6 +- templates/create.html | 30 ++---- 5 files changed, 242 insertions(+), 94 deletions(-) diff --git a/indexer.py b/indexer.py index aae0300..6c5cf2e 100644 --- a/indexer.py +++ b/indexer.py @@ -11,26 +11,29 @@ app = Flask(__name__) strings = None settings = None +def get_categories(): + return settings["categories"] + @app.route("/") def index(): - return render_template("search.html", language="english", categories=settings["categories"], strings=strings) + return render_template("search.html", language="english", categories=get_categories(), strings=strings) @app.route("/categories") def categorys(): global strings - return render_template("categories.html", categories=settings["categories"], strings=strings) + return render_template("categories.html", categories=get_categories(), strings=strings) @app.route("/create", methods=['GET','POST']) def create(): if request.method == "GET": - return render_template("create.html", language="english", categories=settings["categories"], strings=strings, errors=None) + return render_template("create.html", language="english", categories=get_categories(), strings=strings, errors=None) elif request.method == "POST": newTorrent = createNewTorrent(request) if len(newTorrent.errors) == 0: message = "Successfully created torrent {}".format(newTorrent.fileid, newTorrent.fileid[:-20]) - return render_template("create.html", language="english", categories=settings["categories"], strings=strings, messages=[message]) + return render_template("create.html", language="english", categories=get_categories(), strings=strings, messages=[message]) else: - return render_template("create.html", language="english", categories=settings["categories"], strings=strings, errors=newTorrent.errors) + return render_template("create.html", language="english", categories=get_categories(), strings=strings, errors=newTorrent.errors) @app.route("/download/") def download(filename): @@ -72,20 +75,18 @@ def search(): 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) - #results = c.fetchall() results = list() for row in c.execute("SELECT torrents.fileid, torrents.name, metadata.torrentsize FROM torrents LEFT JOIN metadata on metadata.fileid = torrents.fileid WHERE " + search, search_params): r = row[0:2] + (size(float(row[2])) , ) + row[3:] results.append(r) - return render_template("result.html", results=results, strings=strings, language="english", categories=settings["categories"]) + return render_template("result.html", results=results, strings=strings, language="english", categories=get_categories()) @app.route("/details", methods=['GET']) def details(): info_hash = request.args["h"] print(info_hash) - return render_template("details.html", strings=strings, language="english", categories=settings["categories"]) + return render_template("details.html", strings=strings, language="english", categories=get_categories()) def scrapeAll(): TRACKER_URL = "http://tracker.lootbox.cf:6969/" @@ -171,17 +172,17 @@ class Metadata(): torrent = f.read() self.fileid = fileid self.bcoded = bencoder.decode(torrent) - self.created_by = self.bcoded.get(b'created by', "") - self.creation_date = self.bcoded.get(b'creation date', "") + self.created_by = self.bcoded.get(b'created by', b"") + self.creation_date = self.bcoded.get(b'creation date', b"") self.announce_url = self.bcoded.get(b'info', dict()).get(b'', "") - self.source = self.bcoded.get(b'info', dict()).get(b'source', "") + self.source = self.bcoded.get(b'info', dict()).get(b'source', b"") self.torrentsize = ((len(self.bcoded.get(b'info', dict()).get(b'pieces', "")) / 20) * self.bcoded.get(b'info', dict()).get(b'piece length')) - self.name = self.bcoded.get(b'info', dict()).get(b'name', "") - self.private = self.bcoded.get(b'info', dict()).get(b'private', "") + self.name = self.bcoded.get(b'info', dict()).get(b'name', b"") + self.private = self.bcoded.get(b'info', dict()).get(b'private', b"") def writeToDb(self, cursor): c = cursor - b64created_by = base64.b64encode(self.created_by) + b64created_by = base64.b64encode(self.created_by) if self.created_by else "" b64announce_url = base64.b64encode(self.announce_url.decode()) if self.announce_url else "" b64source = base64.b64encode(self.source) if self.source else "" b64name = base64.b64encode(self.name) diff --git a/settings.json b/settings.json index dd9b7a3..8463f41 100644 --- a/settings.json +++ b/settings.json @@ -1,10 +1,189 @@ { - "categories": { - "audio" : [ "lossless", "lossy", "audiobooks", "other" ], - "video" : [ "movies_3d", "movies_4k", "movies_hd", "movies_sd", "series_hd", "series_sd", "clips", "other" ], - "porn" : [ "movies_3d", "movies_4k", "movies_hd", "movies_sd", "series_hd", "series_sd", "clips", "pictures", "other" ], - "games" : [ "pc", "mac", "ios", "android", "consoles", "other" ], - "applications" : [ "windows", "mac", "unix", "ios", "android", "other" ], - "other" : [ "ebooks", "comics", "pictures", "other" ] - } + "categories": [ + { + "id": 1, + "label": "Audio", + "subcategories": [ + { + "id": 1, + "label": "Lossless" + }, + { + "id": 2, + "label": "Lossy" + }, + { + "id": 3, + "label": "Audio book" + }, + { + "id": 4, + "label": "Other" + } + ] + }, + { + "id": 2, + "label": "Video", + "subcategories": [ + { + "id": 5, + "label": "3D Movie" + }, + { + "id": 6, + "label": "4k Movie" + }, + { + "id": 7, + "label": "HD Movie" + }, + { + "id": 8, + "label": "SD Movie" + }, + { + "id": 9, + "label": "HD Series" + }, + { + "id": 10, + "label": "SD Series" + }, + { + "id": 11, + "label": "Clip" + }, + { + "id": 12, + "label": "Other" + } + ] + }, + { + "id": 3, + "label": "Porn", + "subcategories": [ + { + "id": 13, + "label": "3D Movie" + }, + { + "id": 14, + "label": "4k Movie" + }, + { + "id": 15, + "label": "HD Movie" + }, + { + "id": 16, + "label": "SD Movie" + }, + { + "id": 17, + "label": "HD Series" + }, + { + "id": 18, + "label": "SD Series" + }, + { + "id": 19, + "label": "Clip" + }, + { + "id": 20, + "label": "Pictures" + }, + { + "id": 21, + "label": "Other" + } + ] + }, + { + "id": 4, + "label": "Games", + "subcategories": [ + { + "id": 22, + "label": "Windows" + }, + { + "id": 23, + "label": "Mac" + }, + { + "id": 24, + "label": "iOS" + }, + { + "id": 25, + "label": "Android" + }, + { + "id": 26, + "label": "Consoles" + }, + { + "id": 27, + "label": "Other" + } + ] + }, + { + "id": 5, + "label": "Application", + "subcategories": [ + { + "id": 28, + "label": "Windows" + }, + { + "id": 29, + "label": "Mac" + }, + { + "id": 30, + "label": "*nix" + }, + { + "id": 31, + "label": "iOS" + }, + { + "id": 32, + "label": "Android" + }, + { + "id": 33, + "label": "Other" + } + ] + }, + { + "id": 6, + "label": "Other", + "subcategories": [ + { + "id": 34, + "label": "eBook" + }, + { + "id": 35, + "label": "Comic" + }, + { + "id": 36, + "label": "Picture" + }, + { + "id": 37, + "label": "Other" + } + ] + } + ] } + diff --git a/static/js/create.js b/static/js/create.js index 9482624..6029207 100644 --- a/static/js/create.js +++ b/static/js/create.js @@ -1,19 +1,12 @@ window.onload = function () { - $('.dropdown li > a').click(function(e){ - setDropdownButtonText(this.innerHTML, this.parentElement.parentElement.parentElement) //set the display-text to the selected value - fillDropdownByValue(this.innerHTML, $(".dropdown")["1"]) - this.parentElement.parentElement.parentElement.classList.remove("open"); - return false; + $('#subcategory').prop('disabled', true); + $('#category').change(function() { + fillSubcategory(this.value) }); customizeUploadButton() } -function setDropdownButtonText(text, dropdownButton) { - var dropdownTextSpan = dropdownButton.getElementsByClassName("text")[0] - dropdownTextSpan.innerHTML = text -} - function sortCategories(categories) { var sortedCategories = [] for(var key in categories) { @@ -80,33 +73,28 @@ function fillDetectedFilelist(file) { reader.readAsArrayBuffer(file) } -// Fill a defined dropdown with values. -// These values will be generated out of the categories.json -function fillDropdownByValue(value, dropdownToFill) { - dropdownToFill.getElementsByTagName("button")[0].disabled = false - dropdownToFill.getElementsByClassName("text")[0].innerHTML = "Subcategorie" - var dropdownToFillUl = dropdownToFill.getElementsByClassName("dropdown-menu")[0] - dropdownToFillUl.innerHTML = "" - valueDescriptor = getDescriptorByLocalString("english", value) - subcategories = global_categories[valueDescriptor] - subcategories = sortCategories(subcategories) - for(subcategoryIndex in subcategories) { - subcategoryLocalString = getLocalString("english", subcategories[subcategoryIndex]) - var newEntry = document.createElement("li") - var newEntryLink = document.createElement("a") - newEntry.setAttribute("role", "presentation") - newEntryLink.setAttribute("role", "menuitem") - newEntryLink.tabIndex = -1 - newEntryLink.href = "#" - newEntryLink.innerHTML = subcategoryLocalString - newEntryLink.onclick = function(e){ - setDropdownButtonText(this.innerHTML, this.parentElement.parentElement.parentElement) - this.parentElement.parentElement.parentElement.classList.remove("open"); - return false; +function fillSubcategory(value) { + var subSelect = $('#subcategory') + subSelect.empty(); + subSelect.append($('