diff --git a/indexer.py b/indexer.py index b3a63d0..a705793 100644 --- a/indexer.py +++ b/indexer.py @@ -115,4 +115,4 @@ if __name__ == "__main__": app.jinja_env.globals.update(getLocalString=getLocalString) app.jinja_env.globals.update(json=json) app.jinja_env.globals.update(sorted=sorted) - app.run(debug=True) + app.run(debug=False, host="0.0.0.0") diff --git a/static/css/create.css b/static/css/create.css index 36bd5d3..3ef76fc 100644 --- a/static/css/create.css +++ b/static/css/create.css @@ -117,6 +117,10 @@ body { display: inline; } +.detectedInfosGroup { + display: none; +} + .row { margin-bottom: 10px; } diff --git a/static/js/create.js b/static/js/create.js index 28ef678..aed1968 100644 --- a/static/js/create.js +++ b/static/js/create.js @@ -28,35 +28,71 @@ function fillDetectedFilelist(file) { fileList = document.querySelectorAll(".detectedFiles ul")[0] fileList.innerHTML = "" reader.onload = function() { + autodetectSuccess = false b = new bencode() - torrentObject = b.decode(reader.result) - for(var fileIndex = 0; fileIndex < torrentObject.info.files.length; fileIndex++){ - newListElement = document.createElement("li") - newListElement.innerHTML = torrentObject.info.files[fileIndex].path[0] - fileList.appendChild(newListElement) + try { + torrentObject = b.decode(reader.result) + } catch(err) { + } - document.querySelectorAll("input.name")[0].value = torrentObject.info.name + if(torrentObject.info.name) { + document.querySelectorAll("input.name")[0].value = torrentObject.info.name + } sizeGroup = document.querySelectorAll(".sizeGroup")[0] - if(torrentObject.info.pieces.length && torrentObject.info["piece length"]){ + if(torrentObject.info.pieces.length && torrentObject.info["piece length"]) { sizeGroup.style.display = "" - document.querySelectorAll(".detectedSize")[0].innerHTML = ((Math.round((torrentObject.info.pieces.length / 20) * torrentObject.info["piece length"]) / 1024 / 1024 * 100) / 100) + " MB" + size = (torrentObject.info.pieces.length / 20) * torrentObject.info["piece length"] + size = getNextUnit(size) + document.querySelectorAll(".detectedSize")[0].innerHTML = ((Math.round(size[0] * 100)) / 100) + " " + size[1] + autodetectSuccess = true } else { sizeGroup.style.display = "none" } trackerGroup = document.querySelectorAll(".trackerGroup")[0] - if(torrentObject.announce){ + if(torrentObject.announce) { trackerGroup.style.display = "" document.querySelectorAll(".detectedTracker")[0].innerHTML = torrentObject.announce + autodetectSuccess = true } else { trackerGroup.style.display = "none" } + + filesGroup = document.querySelectorAll(".filesGroup")[0] + if(torrentObject.info.files.length > 0) { + autodetectSuccess = true + for(var fileIndex = 0; fileIndex < torrentObject.info.files.length; fileIndex++){ + newListElement = document.createElement("li") + newListElement.innerHTML = torrentObject.info.files[fileIndex].path[0] + fileList.appendChild(newListElement) + } + } + + var detectInfosGroup = document.querySelectorAll(".detectedInfosGroup")[0] + if(autodetectSuccess) { + detectInfosGroup.style.display = "block" + } else { + detectInfosGroup.style.display = "none" + } } reader.readAsArrayBuffer(file) } +function getNextUnit(bSize) { + units = ["B", "kB", "MB", "GB", "TB", "PB", "To damn high"] + iters = 0 + size = bSize + do { + size /= 1024 + iters++ + } while(size >= 1) + size *= 1024 + if(iters > units.length) { iters = units.length } + return [size, units[iters - 1]] +} + // Fill a defined dropdown with values. // These values will be generated out of the categories.json function fillDropdownByValue(value, dropdownToFill) { diff --git a/strings.json b/strings.json index 4bf4af9..7972a01 100644 --- a/strings.json +++ b/strings.json @@ -38,6 +38,9 @@ "create_new_torrent" : "Create a new torrent", "description" : "Description", "audio_quality" : "Audio quality", - "video_quality" : "Video quality" + "video_quality" : "Video quality", + "size" : "Size", + "tracker" : "Tracker", + "detected_files" : "Detected files" } } diff --git a/templates/create.html b/templates/create.html index b524b9f..bfbef7d 100644 --- a/templates/create.html +++ b/templates/create.html @@ -21,22 +21,22 @@ vim: ts=2 noexpandtab
- +
-
+
-
Size:
-

123MB

+
{{ getLocalString(language, "size") }}:
+

-
Tracker:
-

http://foo.bar/tracker

+
{{ getLocalString(language, "tracker") }}:
+

-
Detected files:
+
{{ getLocalString(language, "detected_files") }}: