mirror of
https://github.com/jiojciojsioe3/a3cjroijsiojiorj.git
synced 2024-11-15 07:21:50 +08:00
Add various tools
This commit is contained in:
parent
1759772831
commit
0d13f14f45
4
tools/get_version.bat
Normal file
4
tools/get_version.bat
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
@echo off
|
||||||
|
(
|
||||||
|
git log -1 --pretty="format:{\"commit\": \"%%H\", \"commit_short\": \"%%h\", \"version\": \"%%ad\", \"url\": \"https://github.com/bui/taiko-web/\"}" --date="format:%%y.%%m.%%d"
|
||||||
|
) > ../version.json
|
1
tools/get_version.sh
Normal file
1
tools/get_version.sh
Normal file
@ -0,0 +1 @@
|
|||||||
|
git log -1 --pretty="format:{\"commit\": \"%H\", \"commit_short\": \"%h\", \"version\": \"%ad\", \"url\": \"https://github.com/bui/taiko-web/\"}" --date="format:%y.%m.%d" > ../version.json
|
196
tools/merge_image.htm
Normal file
196
tools/merge_image.htm
Normal file
@ -0,0 +1,196 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Merge Image</title>
|
||||||
|
<style>
|
||||||
|
body{
|
||||||
|
transition: background-color 0.5s;
|
||||||
|
background-color: #fff;
|
||||||
|
font-family: sans-serif;
|
||||||
|
font-size: 20px;
|
||||||
|
}
|
||||||
|
input[type=number]{
|
||||||
|
font-family: monospace;
|
||||||
|
font-size: 18px;
|
||||||
|
padding: 5px;
|
||||||
|
}
|
||||||
|
#settings{
|
||||||
|
display: flex;
|
||||||
|
margin-bottom: 18px;
|
||||||
|
height: 40px;
|
||||||
|
}
|
||||||
|
label{
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
label:not(:first-child){
|
||||||
|
margin-left: 10px;
|
||||||
|
border-left: 2px solid #ccc;
|
||||||
|
padding-left: 8px;
|
||||||
|
}
|
||||||
|
input{
|
||||||
|
margin: 5px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="settings">
|
||||||
|
<label>
|
||||||
|
Max height
|
||||||
|
<input id="max-height" type="number" min="1" max="5000" step="1" value="2000">
|
||||||
|
px
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
Spacing
|
||||||
|
<input id="spacing" type="number" min="0" max="100" step="1" value="0">
|
||||||
|
px
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<input id="vertical" type="checkbox" checked>
|
||||||
|
Vertical
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div id="hint">Drag and drop your images here...</div>
|
||||||
|
<canvas id="canvas"></canvas>
|
||||||
|
<script>
|
||||||
|
var canvas = document.getElementById("canvas")
|
||||||
|
var ctx = canvas.getContext("2d")
|
||||||
|
var allFiles
|
||||||
|
var maxHeightElement = document.getElementById("max-height")
|
||||||
|
var spacingElement = document.getElementById("spacing")
|
||||||
|
var maxHeight = parseInt(maxHeightElement.value)
|
||||||
|
var spacing = parseInt(spacingElement.value)
|
||||||
|
var vectical = true
|
||||||
|
|
||||||
|
document.addEventListener("dragover", event => {
|
||||||
|
event.preventDefault()
|
||||||
|
event.dataTransfer.dropEffect = "copy"
|
||||||
|
document.body.style.backgroundColor = "#ccc"
|
||||||
|
})
|
||||||
|
document.addEventListener("dragleave", () => {
|
||||||
|
document.body.style.backgroundColor = "#fff"
|
||||||
|
})
|
||||||
|
document.addEventListener("drop", event => {
|
||||||
|
document.getElementById("hint").style.display = "none"
|
||||||
|
document.body.style.backgroundColor = "#fff"
|
||||||
|
event.preventDefault()
|
||||||
|
allFiles = []
|
||||||
|
var promises = []
|
||||||
|
for(let file of event.dataTransfer.files){
|
||||||
|
promises.push(readFile(file))
|
||||||
|
}
|
||||||
|
Promise.all(promises).then(drawCanvas)
|
||||||
|
})
|
||||||
|
maxHeightElement.addEventListener("change", event => {
|
||||||
|
var value = parseInt(event.currentTarget.value)
|
||||||
|
if(value >= 1 && value <= 5000){
|
||||||
|
maxHeight = value
|
||||||
|
if(allFiles && allFiles.length){
|
||||||
|
drawCanvas()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
spacingElement.addEventListener("change", event => {
|
||||||
|
var value = parseInt(event.currentTarget.value)
|
||||||
|
if(value >= 0 && value <= 100){
|
||||||
|
spacing = value
|
||||||
|
if(allFiles && allFiles.length){
|
||||||
|
drawCanvas()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
document.getElementById("vertical").addEventListener("change", event => {
|
||||||
|
vertical = event.currentTarget.checked
|
||||||
|
if(allFiles && allFiles.length){
|
||||||
|
drawCanvas()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
function readFile(file){
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
var reader = new FileReader()
|
||||||
|
reader.addEventListener("load", () => {
|
||||||
|
if(reader.result){
|
||||||
|
var img = document.createElement("img")
|
||||||
|
img.addEventListener("load", () => {
|
||||||
|
var noExt = file.name.slice(0, file.name.lastIndexOf("."))
|
||||||
|
if(parseInt(noExt) == noExt){
|
||||||
|
var name = parseInt(noExt)
|
||||||
|
}else{
|
||||||
|
var name = noExt
|
||||||
|
}
|
||||||
|
allFiles.push({
|
||||||
|
name: name,
|
||||||
|
img: img
|
||||||
|
})
|
||||||
|
resolve()
|
||||||
|
})
|
||||||
|
img.addEventListener("error", resolve)
|
||||||
|
img.addEventListener("abort", resolve)
|
||||||
|
img.src = reader.result
|
||||||
|
}else{
|
||||||
|
resolve()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
reader.addEventListener("error", resolve)
|
||||||
|
reader.addEventListener("abort", resolve)
|
||||||
|
reader.readAsDataURL(file)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function drawCanvas(){
|
||||||
|
var x = 0
|
||||||
|
var y = 0
|
||||||
|
var biggestWidth = 0
|
||||||
|
var canvasWidth = 0
|
||||||
|
var canvasHeight = 0
|
||||||
|
allFiles.sort((a, b) => a.name > b.name ? 1 : -1)
|
||||||
|
for(var i in allFiles){
|
||||||
|
var file = allFiles[i]
|
||||||
|
if(vertical){
|
||||||
|
if(y + file.img.height > maxHeight + spacing){
|
||||||
|
y = 0
|
||||||
|
x += biggestWidth
|
||||||
|
biggestWidth = 0
|
||||||
|
}
|
||||||
|
file.x = x + (x === 0 ? 0 : spacing)
|
||||||
|
file.y = y + (y === 0 ? 0 : spacing)
|
||||||
|
y += file.img.height + (y === 0 ? 0 : spacing)
|
||||||
|
if(file.img.width > biggestWidth){
|
||||||
|
biggestWidth = file.img.width
|
||||||
|
}
|
||||||
|
if(y > canvasHeight){
|
||||||
|
canvasHeight = y
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
if(x + file.img.width > maxHeight + spacing){
|
||||||
|
x = 0
|
||||||
|
y += biggestWidth
|
||||||
|
biggestWidth = 0
|
||||||
|
}
|
||||||
|
file.x = x + (x === 0 ? 0 : spacing)
|
||||||
|
file.y = y + (y === 0 ? 0 : spacing)
|
||||||
|
x += file.img.width + (x === 0 ? 0 : spacing)
|
||||||
|
if(file.img.height > biggestWidth){
|
||||||
|
biggestWidth = file.img.height
|
||||||
|
}
|
||||||
|
if(x > canvasWidth){
|
||||||
|
canvasWidth = x
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(vertical){
|
||||||
|
canvasWidth = x + biggestWidth
|
||||||
|
}else{
|
||||||
|
canvasHeight = y + biggestWidth
|
||||||
|
}
|
||||||
|
canvas.width = canvasWidth
|
||||||
|
canvas.height = canvasHeight
|
||||||
|
for(var i in allFiles){
|
||||||
|
var file = allFiles[i]
|
||||||
|
ctx.drawImage(file.img, file.x, file.y, file.img.width, file.img.height)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
86
tools/set_previews.py
Normal file
86
tools/set_previews.py
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
from __future__ import division
|
||||||
|
import os
|
||||||
|
import sqlite3
|
||||||
|
import re
|
||||||
|
DATABASE = 'taiko.db'
|
||||||
|
|
||||||
|
conn = sqlite3.connect(DATABASE)
|
||||||
|
curs = conn.cursor()
|
||||||
|
|
||||||
|
def parse_osu(osu):
|
||||||
|
osu_lines = open(osu, 'r').read().replace('\x00', '').split('\n')
|
||||||
|
sections = {}
|
||||||
|
current_section = (None, [])
|
||||||
|
|
||||||
|
for line in osu_lines:
|
||||||
|
line = line.strip()
|
||||||
|
secm = re.match('^\[(\w+)\]$', line)
|
||||||
|
if secm:
|
||||||
|
if current_section:
|
||||||
|
sections[current_section[0]] = current_section[1]
|
||||||
|
current_section = (secm.group(1), [])
|
||||||
|
else:
|
||||||
|
if current_section:
|
||||||
|
current_section[1].append(line)
|
||||||
|
else:
|
||||||
|
current_section = ('Default', [line])
|
||||||
|
|
||||||
|
if current_section:
|
||||||
|
sections[current_section[0]] = current_section[1]
|
||||||
|
|
||||||
|
return sections
|
||||||
|
|
||||||
|
|
||||||
|
def get_osu_key(osu, section, key, default=None):
|
||||||
|
sec = osu[section]
|
||||||
|
for line in sec:
|
||||||
|
ok = line.split(':', 1)[0].strip()
|
||||||
|
ov = line.split(':', 1)[1].strip()
|
||||||
|
|
||||||
|
if ok.lower() == key.lower():
|
||||||
|
return ov
|
||||||
|
|
||||||
|
return default
|
||||||
|
|
||||||
|
|
||||||
|
def get_preview(song_id, song_type):
|
||||||
|
preview = 0
|
||||||
|
|
||||||
|
if song_type == "tja":
|
||||||
|
if os.path.isfile('public/songs/%s/main.tja' % song_id):
|
||||||
|
preview = get_tja_preview('public/songs/%s/main.tja' % song_id)
|
||||||
|
else:
|
||||||
|
osus = [osu for osu in os.listdir('public/songs/%s' % song_id) if osu in ['easy.osu', 'normal.osu', 'hard.osu', 'oni.osu']]
|
||||||
|
if osus:
|
||||||
|
osud = parse_osu('public/songs/%s/%s' % (song_id, osus[0]))
|
||||||
|
preview = int(get_osu_key(osud, 'General', 'PreviewTime', 0))
|
||||||
|
|
||||||
|
return preview
|
||||||
|
|
||||||
|
|
||||||
|
def get_tja_preview(tja):
|
||||||
|
tja_lines = open(tja, 'r').read().replace('\x00', '').split('\n')
|
||||||
|
|
||||||
|
for line in tja_lines:
|
||||||
|
line = line.strip()
|
||||||
|
if ':' in line:
|
||||||
|
name, value = line.split(':', 1)
|
||||||
|
if name.lower() == 'demostart':
|
||||||
|
value = value.strip()
|
||||||
|
try:
|
||||||
|
value = float(value)
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
return int(value * 1000)
|
||||||
|
elif line.lower() == '#start':
|
||||||
|
break
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
songs = curs.execute('select id, type from songs').fetchall()
|
||||||
|
for song in songs:
|
||||||
|
preview = get_preview(song[0], song[1]) / 1000
|
||||||
|
curs.execute('update songs set preview = ? where id = ?', (preview, song[0]))
|
||||||
|
conn.commit()
|
49
tools/taikodb_hash.py
Normal file
49
tools/taikodb_hash.py
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import hashlib
|
||||||
|
import base64
|
||||||
|
import sqlite3
|
||||||
|
|
||||||
|
def md5(md5hash, filename):
|
||||||
|
with open(filename, "rb") as file:
|
||||||
|
for chunk in iter(lambda: file.read(64 * 1024), b""):
|
||||||
|
md5hash.update(chunk)
|
||||||
|
|
||||||
|
def get_hashes(root):
|
||||||
|
hashes = {}
|
||||||
|
diffs = ["easy", "normal", "hard", "oni", "ura"]
|
||||||
|
dirs = os.listdir(root)
|
||||||
|
for dir in dirs:
|
||||||
|
dir_path = os.path.join(root, dir)
|
||||||
|
if dir.isdigit() and os.path.isdir(dir_path):
|
||||||
|
files = os.listdir(dir_path)
|
||||||
|
md5hash = hashlib.md5()
|
||||||
|
if "main.tja" in files:
|
||||||
|
md5(md5hash, os.path.join(dir_path, "main.tja"))
|
||||||
|
else:
|
||||||
|
for diff in diffs:
|
||||||
|
if diff + ".osu" in files:
|
||||||
|
md5(md5hash, os.path.join(dir_path, diff + ".osu"))
|
||||||
|
hashes[dir] = base64.b64encode(md5hash.digest())[:-2]
|
||||||
|
return hashes
|
||||||
|
|
||||||
|
def write_db(database, songs):
|
||||||
|
db = sqlite3.connect(database)
|
||||||
|
hashes = get_hashes(songs)
|
||||||
|
added = 0
|
||||||
|
for id in hashes:
|
||||||
|
added += 1
|
||||||
|
cur = db.cursor()
|
||||||
|
cur.execute("update songs set hash = ? where id = ?", (hashes[id].decode(), int(id)))
|
||||||
|
cur.close()
|
||||||
|
db.commit()
|
||||||
|
db.close()
|
||||||
|
if added:
|
||||||
|
print("{0} hashes have been added to the database.".format(added))
|
||||||
|
else:
|
||||||
|
print("Error: No songs were found in the given directory.")
|
||||||
|
|
||||||
|
if len(sys.argv) >= 3:
|
||||||
|
write_db(sys.argv[1], sys.argv[2])
|
||||||
|
else:
|
||||||
|
print("Usage: taikodb_hash.py ../taiko.db ../public/songs")
|
Loading…
Reference in New Issue
Block a user