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
|
#!/usr/bin/python3
|
||||||
#/* vim:set ts=2 set noexpandtab */
|
#/* vim:set ts=2 set noexpandtab */
|
||||||
import json, uuid, hashlib, sqlite3, base64
|
import json, uuid, hashlib, sqlite3, base64
|
||||||
|
from hashlib import sha1
|
||||||
import bencoder
|
import bencoder
|
||||||
import requests
|
import requests
|
||||||
from flask import Flask, render_template, url_for, request, send_file
|
from flask import Flask, render_template, url_for, request, send_file
|
||||||
@ -72,6 +73,7 @@ def search():
|
|||||||
def scrapeAll():
|
def scrapeAll():
|
||||||
TRACKER_URL = "http://tracker.lootbox.cf:6969/"
|
TRACKER_URL = "http://tracker.lootbox.cf:6969/"
|
||||||
statedump = requests.get(TRACKER_URL + "stats" + "?mode=statedump")
|
statedump = requests.get(TRACKER_URL + "stats" + "?mode=statedump")
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def init():
|
def init():
|
||||||
@ -107,20 +109,19 @@ def createNewTorrent(reuqest):
|
|||||||
uploadfile = request.files["torrentFile"]
|
uploadfile = request.files["torrentFile"]
|
||||||
filename = secure_filename(uploadfile.filename)
|
filename = secure_filename(uploadfile.filename)
|
||||||
|
|
||||||
h = hashlib.sha256()
|
content = request.files["torrentFile"].stream.read()
|
||||||
h.update((str(uuid.uuid4()) + filename).encode())
|
bcoded = bencoder.decode(content)
|
||||||
safeFilename = h.hexdigest()
|
info_hash = sha1(bencoder.encode(bcoded[b'info'])).hexdigest()
|
||||||
uploadfile.save("torrentFiles/" + safeFilename)
|
|
||||||
import bencoder
|
with open("torrentFiles/" + info_hash, "wb") as torrent_file:
|
||||||
with open("torrentFiles/" + safeFilename, "rb") as content:
|
torrent_file.write(content)
|
||||||
content = content.read()
|
|
||||||
|
|
||||||
bcoded = bencoder.decode(content)
|
bcoded = bencoder.decode(content)
|
||||||
size = ((len(bcoded[b'info'][b'pieces']) / 20) * bcoded[b'info'][b'piece length']) / 1024 / 1024
|
size = ((len(bcoded[b'info'][b'pieces']) / 20) * bcoded[b'info'][b'piece length']) / 1024 / 1024
|
||||||
|
|
||||||
print("=== CREATE NEW TORRENT FILE ===")
|
print("=== CREATE NEW TORRENT FILE ===")
|
||||||
print( "Name: " + request.form["name"] )
|
print( "Name: " + request.form["name"] )
|
||||||
print( "Torrent file: " + safeFilename )
|
print( "Torrent file: " + info_hash )
|
||||||
print( "Category: " + request.form["category"] )
|
print( "Category: " + request.form["category"] )
|
||||||
print( "Subcategory: " + request.form["subcategory"] )
|
print( "Subcategory: " + request.form["subcategory"] )
|
||||||
print( "Description: " + request.form["description"] )
|
print( "Description: " + request.form["description"] )
|
||||||
@ -132,7 +133,7 @@ def createNewTorrent(reuqest):
|
|||||||
description = request.form["description"]
|
description = request.form["description"]
|
||||||
audioquality_description = request.form["audioquality_description"]
|
audioquality_description = request.form["audioquality_description"]
|
||||||
videoquality_description = request.form["videoquality_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")
|
connection = sqlite3.connect("torrentdb.sqlite")
|
||||||
newTFile.writeToDb(connection.cursor())
|
newTFile.writeToDb(connection.cursor())
|
||||||
newTFile.metadata.writeToDb(connection.cursor())
|
newTFile.metadata.writeToDb(connection.cursor())
|
||||||
@ -157,8 +158,8 @@ class Metadata():
|
|||||||
def writeToDb(self, cursor):
|
def writeToDb(self, cursor):
|
||||||
c = cursor
|
c = cursor
|
||||||
b64created_by = base64.b64encode(self.created_by)
|
b64created_by = base64.b64encode(self.created_by)
|
||||||
b64announce_url = base64.b64encode(self.announce_url.encode()) if self.announce_url else ""
|
b64announce_url = base64.b64encode(self.announce_url.decode()) if self.announce_url else ""
|
||||||
b64source = base64.b64encode(self.source.encode()) if self.source else ""
|
b64source = base64.b64encode(self.source) if self.source else ""
|
||||||
b64name = base64.b64encode(self.name)
|
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})
|
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 New Issue
Block a user