Fix use of proper file checksum
This commit is contained in:
parent
b86e6cb7cb
commit
c028559650
23
indexer.py
23
indexer.py
|
@ -1,6 +1,7 @@
|
|||
#!/usr/bin/python3
|
||||
#/* vim:set ts=2 set noexpandtab */
|
||||
import json, uuid, hashlib, sqlite3, base64
|
||||
from hashlib import sha1
|
||||
import bencoder
|
||||
import requests
|
||||
from flask import Flask, render_template, url_for, request, send_file
|
||||
|
@ -72,6 +73,7 @@ def search():
|
|||
def scrapeAll():
|
||||
TRACKER_URL = "http://tracker.lootbox.cf:6969/"
|
||||
statedump = requests.get(TRACKER_URL + "stats" + "?mode=statedump")
|
||||
|
||||
return
|
||||
|
||||
def init():
|
||||
|
@ -107,20 +109,19 @@ def createNewTorrent(reuqest):
|
|||
uploadfile = request.files["torrentFile"]
|
||||
filename = secure_filename(uploadfile.filename)
|
||||
|
||||
h = hashlib.sha256()
|
||||
h.update((str(uuid.uuid4()) + filename).encode())
|
||||
safeFilename = h.hexdigest()
|
||||
uploadfile.save("torrentFiles/" + safeFilename)
|
||||
import bencoder
|
||||
with open("torrentFiles/" + safeFilename, "rb") as content:
|
||||
content = content.read()
|
||||
content = request.files["torrentFile"].stream.read()
|
||||
bcoded = bencoder.decode(content)
|
||||
info_hash = sha1(bencoder.encode(bcoded[b'info'])).hexdigest()
|
||||
|
||||
with open("torrentFiles/" + info_hash, "wb") as torrent_file:
|
||||
torrent_file.write(content)
|
||||
|
||||
bcoded = bencoder.decode(content)
|
||||
size = ((len(bcoded[b'info'][b'pieces']) / 20) * bcoded[b'info'][b'piece length']) / 1024 / 1024
|
||||
|
||||
print("=== CREATE NEW TORRENT FILE ===")
|
||||
print( "Name: " + request.form["name"] )
|
||||
print( "Torrent file: " + safeFilename )
|
||||
print( "Torrent file: " + info_hash )
|
||||
print( "Category: " + request.form["category"] )
|
||||
print( "Subcategory: " + request.form["subcategory"] )
|
||||
print( "Description: " + request.form["description"] )
|
||||
|
@ -132,7 +133,7 @@ def createNewTorrent(reuqest):
|
|||
description = request.form["description"]
|
||||
audioquality_description = request.form["audioquality_description"]
|
||||
videoquality_description = request.form["videoquality_description"]
|
||||
newTFile = TorrentFile(safeFilename, name, category, subcategory, description, audioquality_description, 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())
|
||||
|
@ -157,8 +158,8 @@ class Metadata():
|
|||
def writeToDb(self, cursor):
|
||||
c = cursor
|
||||
b64created_by = base64.b64encode(self.created_by)
|
||||
b64announce_url = base64.b64encode(self.announce_url.encode()) if self.announce_url else ""
|
||||
b64source = base64.b64encode(self.source.encode()) if self.source 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)
|
||||
c.execute("INSERT INTO metadata(fileid, created_by, creation_date, announce_url, source, torrentsize, name, private) VALUES(:fileid, :created_by, :creation_date, :announce_url, :source, :torrentsize, :name, :private)", { 'fileid' : self.fileid, 'created_by' : b64created_by, 'creation_date' : self.creation_date, 'announce_url' : b64announce_url, 'source' : b64source , 'torrentsize' : self.torrentsize, 'name' : b64name, 'private' : self.private})
|
||||
|
||||
|
|
Loading…
Reference in a new issue