Rework categories and stuff
This commit is contained in:
parent
9faa532577
commit
2c220afced
31
indexer.py
31
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 <a href=\"/search?h={}\">{}</a>".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/<filename>")
|
||||
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)
|
||||
|
|
195
settings.json
195
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"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
|
|
@ -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($('<option value="-1" selected>--- Select Subcategory ---</selected>'))
|
||||
if (value >= 0) {
|
||||
var subcategories = null
|
||||
for(var i = 0; i < global_categories.length; i++) {
|
||||
if (global_categories[i]["id"] == value) {
|
||||
subcategories = global_categories[i]["subcategories"]
|
||||
break
|
||||
}
|
||||
}
|
||||
if(subcategories) {
|
||||
for(subcategoryIndex in subcategories) {
|
||||
var subcategoryId = subcategories[subcategoryIndex]["id"]
|
||||
var subcategoryLocalString = subcategories[subcategoryIndex]["label"]
|
||||
var node = $('<option value="'+subcategoryId+'">'+subcategoryLocalString+'</string>')
|
||||
subSelect.append(node)
|
||||
}
|
||||
}
|
||||
newEntry.appendChild(newEntryLink)
|
||||
dropdownToFillUl.appendChild(newEntry)
|
||||
}
|
||||
subSelect.prop('disabled', value < 0)
|
||||
}
|
||||
|
||||
// Hides the default browser-upload-form and replaces it by an button
|
||||
|
@ -129,19 +117,11 @@ function setButtonToFilename(event) {
|
|||
});
|
||||
}
|
||||
|
||||
// Sets the text of a given dropdown-button to a given value
|
||||
function setDropdownButtonText(text, dropdownButton) {
|
||||
var dropdownTextSpan = dropdownButton.getElementsByClassName("text")[0]
|
||||
dropdownHiddenValue = dropdownButton.getElementsByTagName("input")[0]
|
||||
dropdownHiddenValue.setAttribute("value", getDescriptorByLocalString("english", text))
|
||||
dropdownTextSpan.innerHTML = text
|
||||
}
|
||||
|
||||
function validateForm() {
|
||||
valid = true
|
||||
file = document.querySelectorAll("input.file")[0]
|
||||
category = document.querySelectorAll("input.category")[0]
|
||||
subcategory = document.querySelectorAll("input.subcategory")[0]
|
||||
category = document.querySelectorAll("#category")[0]
|
||||
subcategory = document.querySelectorAll("#subcategory")[0]
|
||||
torrentname = document.querySelectorAll("input.name")[0]
|
||||
description = document.querySelectorAll("textarea.description")[0]
|
||||
if(file.value.length <= 0) {
|
||||
|
@ -153,7 +133,7 @@ function validateForm() {
|
|||
file.parentElement.parentElement.classList.remove("has-error")
|
||||
}
|
||||
|
||||
if(category.value.length <= 0) {
|
||||
if(category.value < 0) {
|
||||
valid = false
|
||||
category.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.classList.add("has-error")
|
||||
category.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.classList.remove("has-success")
|
||||
|
@ -162,7 +142,7 @@ function validateForm() {
|
|||
category.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.classList.remove("has-error")
|
||||
}
|
||||
|
||||
if(subcategory.value.length <= 0) {
|
||||
if(subcategory.value < 0) {
|
||||
valid = false
|
||||
category.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.classList.add("has-error")
|
||||
category.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.classList.remove("has-success")
|
||||
|
|
|
@ -12,11 +12,11 @@ vim: ts=2 noexpandtab
|
|||
<div>
|
||||
<ul>
|
||||
<li>
|
||||
<a href="search?c={{ category }}">{{ category }}</a>
|
||||
<a href="search?c={{ category.id }}">{{ category.label }}</a>
|
||||
<ul>
|
||||
{% for sub_category in categories[category] %}
|
||||
{% for sub_category in category.subcategories %}
|
||||
<li>
|
||||
<a href="search?s={{ sub_category }}">{{ sub_category }}</a>
|
||||
<a href="search?s={{ sub_category.id }}">{{ sub_category.label }}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
|
|
@ -57,29 +57,17 @@ vim: ts=2 noexpandtab
|
|||
<div class="col-sm-9">
|
||||
<div class="row row-container">
|
||||
<div class="col-md-6 category-column">
|
||||
<div class="dropdown">
|
||||
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-expanded="true">
|
||||
<span class="text">{{ getLocalString(language, "category") }}</span>
|
||||
<span class="caret"></span>
|
||||
<input type="hidden" name="category" class="category">
|
||||
</button>
|
||||
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
|
||||
{% for category in sorted(categories.keys()) %}
|
||||
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">{{ getLocalString(language, category) }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
<select class="form-control dropdown" id="category" name="category">
|
||||
<option value="-1" selected>--- Select Category ---</option>
|
||||
{% for category in categories %}
|
||||
<option value="{{ category.id }}">{{ category.label }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-6 subcategory-column">
|
||||
<div class="dropdown">
|
||||
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-expanded="true" disabled>
|
||||
<span class="text">{{ getLocalString(language, "subcategory") }}</span>
|
||||
<span class="caret"></span>
|
||||
<input type="hidden" name="subcategory" class="subcategory">
|
||||
</button>
|
||||
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
|
||||
</ul>
|
||||
</div>
|
||||
<select class="form-control dropdown" id="subcategory" name="subcategory">
|
||||
<option value="-1" selected>--- Select Subcategory ---</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue