Merge branch 'master' of https://git.geekify.de/sqozz/TorrentIndexer
This commit is contained in:
commit
f759d92f89
61
indexer.py
61
indexer.py
|
@ -15,33 +15,48 @@ LANGUAGES = ['en', 'de']
|
||||||
|
|
||||||
settings = None
|
settings = None
|
||||||
|
|
||||||
def get_categories():
|
|
||||||
cats = settings["categories"]
|
class Categories():
|
||||||
for c in cats:
|
def __init__(self):
|
||||||
c["label"] = str(lazy_gettext(c["label"]))
|
|
||||||
for s in c["subcategories"]:
|
self.categories = settings["categories"]
|
||||||
s["label"] = str(lazy_gettext(s["label"]))
|
for c in self.categories:
|
||||||
return cats
|
c["label"] = str(lazy_gettext(c["label"]))
|
||||||
|
for s in c["subcategories"]:
|
||||||
|
s["label"] = str(lazy_gettext(s["label"]))
|
||||||
|
|
||||||
|
def find(self, category, subcategory = None):
|
||||||
|
cat_name = ""
|
||||||
|
sub_name = ""
|
||||||
|
for cat in self.categories:
|
||||||
|
if cat["id"] == category:
|
||||||
|
cat_name = cat["label"]
|
||||||
|
if subcategory != None:
|
||||||
|
for sub in cat["subcategories"]:
|
||||||
|
if sub["id"] == subcategory:
|
||||||
|
sub_name = sub["label"]
|
||||||
|
return (cat_name, sub_name)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def index():
|
def index():
|
||||||
return render_template("search.html", categories=get_categories())
|
return render_template("search.html", categories=categories.categories)
|
||||||
|
|
||||||
@app.route("/categories")
|
@app.route("/categories")
|
||||||
def categorys():
|
def categorys():
|
||||||
return render_template("categories.html", categories=get_categories())
|
return render_template("categories.html", categories=categories.categories)
|
||||||
|
|
||||||
@app.route("/create", methods=['GET','POST'])
|
@app.route("/create", methods=['GET','POST'])
|
||||||
def create():
|
def create():
|
||||||
if request.method == "GET":
|
if request.method == "GET":
|
||||||
return render_template("create.html", categories=get_categories(), errors=None)
|
return render_template("create.html", categories=categories.categories, errors=None)
|
||||||
elif request.method == "POST":
|
elif request.method == "POST":
|
||||||
newTorrent = createNewTorrent(request)
|
newTorrent = createNewTorrent(request)
|
||||||
if len(newTorrent.errors) == 0:
|
if len(newTorrent.errors) == 0:
|
||||||
message = _("Successfully created torrent <a href=\"/search?h={}\">{}</a>").format(newTorrent.fileid, newTorrent.fileid[:-20])
|
message = _("Successfully created torrent <a href=\"/search?h={}\">{}</a>").format(newTorrent.fileid, newTorrent.fileid[:-20])
|
||||||
return render_template("create.html", categories=get_categories(), messages=[message])
|
return render_template("create.html", categories=categories.categories, messages=[message])
|
||||||
else:
|
else:
|
||||||
return render_template("create.html", categories=get_categories(), errors=newTorrent.errors)
|
return render_template("create.html", categories=categories.categories, errors=newTorrent.errors)
|
||||||
|
|
||||||
@app.route("/download/<filename>")
|
@app.route("/download/<filename>")
|
||||||
def download(filename):
|
def download(filename):
|
||||||
|
@ -86,17 +101,17 @@ def search():
|
||||||
r = row[0:2] + (size(float(row[2])) , ) + row[3:]
|
r = row[0:2] + (size(float(row[2])) , ) + row[3:]
|
||||||
results.append(r)
|
results.append(r)
|
||||||
|
|
||||||
return render_template("result.html", results=results, categories=get_categories())
|
return render_template("result.html", results=results, categories=categories.categories)
|
||||||
|
|
||||||
@app.route("/details", methods=['GET'])
|
@app.route("/details", methods=['GET'])
|
||||||
def details():
|
def details():
|
||||||
info_hash = request.args["h"]
|
info_hash = request.args["h"]
|
||||||
tf = TorrentFile(fileid=info_hash)
|
tf = TorrentFile(fileid=info_hash)
|
||||||
tf.fromDb()
|
tf.fromDb()
|
||||||
return render_template("details.html", categories=get_categories(), torrent=tf)
|
return render_template("details.html", categories=categories.categories, torrent=tf)
|
||||||
|
|
||||||
def scrapeAll():
|
def scrapeAll():
|
||||||
TRACKER_URL = "http://tracker.lootbox.cf:6969/"
|
TRACKER_URL = ""
|
||||||
statedump = requests.get(TRACKER_URL + "stats" + "?mode=statedump")
|
statedump = requests.get(TRACKER_URL + "stats" + "?mode=statedump")
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -106,6 +121,8 @@ def init():
|
||||||
with open("settings.json") as settingsJson:
|
with open("settings.json") as settingsJson:
|
||||||
settings = json.load(settingsJson)
|
settings = json.load(settingsJson)
|
||||||
initDb()
|
initDb()
|
||||||
|
global categories
|
||||||
|
categories = Categories()
|
||||||
#scrapeAll()
|
#scrapeAll()
|
||||||
|
|
||||||
def initDb():
|
def initDb():
|
||||||
|
@ -142,10 +159,11 @@ def createNewTorrent(reuqest):
|
||||||
|
|
||||||
is_ours = False
|
is_ours = False
|
||||||
for a in announce:
|
for a in announce:
|
||||||
if a in [b'udp://tracker.lootbox.cf:6969/announce', b'udp://tracker.lootbox.cf:6969/announce/',b'udp://tracker.lootbox.cf/announce',b'udp://tracker.lootbox.cf/announce/']:
|
a = a.decode("utf-8", "ignore")
|
||||||
|
if a in settings["valid_tracker"]:
|
||||||
is_ours = True
|
is_ours = True
|
||||||
break
|
break
|
||||||
|
|
||||||
if not is_ours:
|
if not is_ours:
|
||||||
newTFile.errors = ["Rejecting torrent <a href=\"/search?h={}\">{}</a>, as it does not use our tracker".format(info_hash, info_hash[:-20])]
|
newTFile.errors = ["Rejecting torrent <a href=\"/search?h={}\">{}</a>, as it does not use our tracker".format(info_hash, info_hash[:-20])]
|
||||||
return newTFile
|
return newTFile
|
||||||
|
@ -195,13 +213,13 @@ class Metadata():
|
||||||
return
|
return
|
||||||
self.fileid = fileid
|
self.fileid = fileid
|
||||||
self.bcoded = bencoder.decode(torrent)
|
self.bcoded = bencoder.decode(torrent)
|
||||||
self.created_by = self.bcoded.get(b'created by', b"")
|
self.created_by = self.bcoded.get(b'created by', b"").decode("utf-8", "ignore")
|
||||||
self.creation_date = self.bcoded.get(b'creation date', b"")
|
self.creation_date = self.bcoded.get(b'creation date', b"").decode("utf-8", "ignore")
|
||||||
self.announce_url = self.bcoded.get(b'info', dict()).get(b'', "")
|
self.announce_url = self.bcoded.get(b'info', dict()).get(b'', "")
|
||||||
self.source = self.bcoded.get(b'info', dict()).get(b'source', b"")
|
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.torrentsize = ((len(self.bcoded.get(b'info', dict()).get(b'pieces', "")) / 20) * self.bcoded.get(b'info', dict()).get(b'piece length'))
|
||||||
self.torrentsize_human = size(self.torrentsize)
|
self.torrentsize_human = size(self.torrentsize)
|
||||||
self.name = self.bcoded.get(b'info', dict()).get(b'name', b"")
|
self.name = self.bcoded.get(b'info', dict()).get(b'name', b"").decode("utf-8", "ignore")
|
||||||
self.private = self.bcoded.get(b'info', dict()).get(b'private', b"")
|
self.private = self.bcoded.get(b'info', dict()).get(b'private', b"")
|
||||||
|
|
||||||
def writeToDb(self, cursor):
|
def writeToDb(self, cursor):
|
||||||
|
@ -256,6 +274,7 @@ class TorrentFile():
|
||||||
self.name = (base64.b64decode(res["name"])).decode()
|
self.name = (base64.b64decode(res["name"])).decode()
|
||||||
self.category = res["category"]
|
self.category = res["category"]
|
||||||
self.subcategory = res["subcategory"]
|
self.subcategory = res["subcategory"]
|
||||||
|
self.category_string, self.subcategory_string = categories.find(int(self.category), int(self.subcategory))
|
||||||
self.description = (base64.b64decode(res["description"])).decode()
|
self.description = (base64.b64decode(res["description"])).decode()
|
||||||
self.audioquality_description = (base64.b64decode(res["audioquality_description"])).decode()
|
self.audioquality_description = (base64.b64decode(res["audioquality_description"])).decode()
|
||||||
self.videoquality_description = (base64.b64decode(res["videoquality_description"])).decode()
|
self.videoquality_description = (base64.b64decode(res["videoquality_description"])).decode()
|
||||||
|
@ -269,6 +288,6 @@ if __name__ == "__main__":
|
||||||
init()
|
init()
|
||||||
app.jinja_env.globals.update(json=json)
|
app.jinja_env.globals.update(json=json)
|
||||||
app.jinja_env.globals.update(sorted=sorted)
|
app.jinja_env.globals.update(sorted=sorted)
|
||||||
app.run(debug=True, host="127.0.0.1")
|
app.run(debug=False, host="127.0.0.1")
|
||||||
|
|
||||||
# vim: set ts=2 sts=2 sw=2 noexpandtab:
|
# vim: set ts=2 sts=2 sw=2 noexpandtab:
|
||||||
|
|
|
@ -184,6 +184,11 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
|
||||||
|
"valid_tracker" : [
|
||||||
|
"udp://tracker.lootbox.cf:6969/announce",
|
||||||
|
"udp://tracker.lootbox.cf:6969/announce/"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ vim: ts=2 noexpandtab
|
||||||
<link href="{{ url_for("static", filename="css/details.css") }}" rel="stylesheet">
|
<link href="{{ url_for("static", filename="css/details.css") }}" rel="stylesheet">
|
||||||
<script src="{{ url_for("static", filename="js/main.js") }}"></script>
|
<script src="{{ url_for("static", filename="js/main.js") }}"></script>
|
||||||
<div id="torrent" class="clearfix">
|
<div id="torrent" class="clearfix">
|
||||||
<h4>{{ torrent.category }} » {{ torrent.subcategory}} » {{ torrent.name }}</h4>
|
<h4><a href="/search?c={{ torrent.category }}">{{ torrent.category_string }}</a> » <a href="/search?s={{ torrent.subcategory }}">{{ torrent.subcategory_string }}</a> » <span id="name">{{ torrent.name }}</span></h4>
|
||||||
<div id="details" class="clearfix">
|
<div id="details" class="clearfix">
|
||||||
<div class="detailrow clearfix">
|
<div class="detailrow clearfix">
|
||||||
<div>.torrent-file:</div>
|
<div>.torrent-file:</div>
|
||||||
|
|
Loading…
Reference in a new issue