forked from hkc/cc-stuff
Try to get title from file metadata
This commit is contained in:
parent
5fc6b26428
commit
5b261e82c2
|
@ -24,6 +24,7 @@ local function bytes2time(b)
|
||||||
return string.format("%dm, %ds", math.floor(s / 60), s % 60)
|
return string.format("%dm, %ds", math.floor(s / 60), s % 60)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
term.clear()
|
||||||
local screen_w, screen_h = term.getSize()
|
local screen_w, screen_h = term.getSize()
|
||||||
|
|
||||||
parallel.waitForAll(
|
parallel.waitForAll(
|
||||||
|
@ -56,6 +57,7 @@ function()
|
||||||
drive.play()
|
drive.play()
|
||||||
end
|
end
|
||||||
elseif ev == "term_resize" then
|
elseif ev == "term_resize" then
|
||||||
|
term.clear()
|
||||||
screen_w, screen_h = term.getSize()
|
screen_w, screen_h = term.getSize()
|
||||||
elseif ev == "tape_present" then
|
elseif ev == "tape_present" then
|
||||||
table_of_contents = {}
|
table_of_contents = {}
|
||||||
|
|
|
@ -7,9 +7,11 @@ from sys import argv
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from os.path import splitext
|
from os.path import splitext
|
||||||
from math import ceil
|
from math import ceil
|
||||||
|
from re import search
|
||||||
|
|
||||||
DFPWM_ENCODER_EXECUTABLE = "aucmp"
|
DFPWM_ENCODER_EXECUTABLE = "aucmp"
|
||||||
FFMPEG_EXECUTABLE = "ffmpeg"
|
FFMPEG_EXECUTABLE = "ffmpeg"
|
||||||
|
FFPROBE_EXECUTABLE = "ffprobe"
|
||||||
|
|
||||||
DFPWM_SAMPLE_RATE = 6000
|
DFPWM_SAMPLE_RATE = 6000
|
||||||
|
|
||||||
|
@ -22,6 +24,7 @@ with TemporaryDirectory(prefix="tapedrive") as tmpdir_str:
|
||||||
tmpdir = Path(tmpdir_str)
|
tmpdir = Path(tmpdir_str)
|
||||||
|
|
||||||
filelist: list[Path] = []
|
filelist: list[Path] = []
|
||||||
|
titles: list[bytes] = []
|
||||||
for i, name in enumerate(input_folder.rglob("*.mp3")):
|
for i, name in enumerate(input_folder.rglob("*.mp3")):
|
||||||
if i >= 48:
|
if i >= 48:
|
||||||
print(f"more than 48 tracks, skipping {name}")
|
print(f"more than 48 tracks, skipping {name}")
|
||||||
|
@ -29,16 +32,20 @@ with TemporaryDirectory(prefix="tapedrive") as tmpdir_str:
|
||||||
encoded_file = tmpdir / (splitext(name.name)[0] + ".dfpwm")
|
encoded_file = tmpdir / (splitext(name.name)[0] + ".dfpwm")
|
||||||
filelist.append(encoded_file)
|
filelist.append(encoded_file)
|
||||||
with encoded_file.open("wb") as fout:
|
with encoded_file.open("wb") as fout:
|
||||||
|
with Popen([ FFPROBE_EXECUTABLE, name ], stderr=PIPE) as ffprobe:
|
||||||
|
metadata: str = ffprobe.stderr.read().decode() # type: ignore
|
||||||
|
if (match := search(r"title\s+: (.*)", metadata)):
|
||||||
|
titles.append(match.groups()[0].encode("ascii", errors="ignore"))
|
||||||
|
else:
|
||||||
|
titles.append(splitext(name.name)[0].encode("ascii", errors="ignore"))
|
||||||
with Popen([ DFPWM_ENCODER_EXECUTABLE ], stdout=fout, stdin=PIPE) as dfpwm:
|
with Popen([ DFPWM_ENCODER_EXECUTABLE ], stdout=fout, stdin=PIPE) as dfpwm:
|
||||||
with Popen([ FFMPEG_EXECUTABLE, "-i", name, "-f", "s8", "-ac", "1",
|
with Popen([ FFMPEG_EXECUTABLE, "-i", name, "-f", "s8", "-ac", "1",
|
||||||
"-ar", "48k", "-" ], stdout=dfpwm.stdin) as ffmpeg:
|
"-ar", "48k", "-" ], stdout=dfpwm.stdin) as ffmpeg:
|
||||||
ffmpeg.wait()
|
ffmpeg.wait()
|
||||||
|
|
||||||
offset: int = 6000
|
offset: int = 6000
|
||||||
titles: list[bytes] = []
|
|
||||||
positions: list[tuple[int, int]] = []
|
positions: list[tuple[int, int]] = []
|
||||||
for file in filelist:
|
for file in filelist:
|
||||||
titles.append(file.name.removesuffix(".dfpwm").encode("ascii", errors="replace"))
|
|
||||||
size = ceil(file.stat().st_size / DFPWM_SAMPLE_RATE) * DFPWM_SAMPLE_RATE
|
size = ceil(file.stat().st_size / DFPWM_SAMPLE_RATE) * DFPWM_SAMPLE_RATE
|
||||||
positions.append((offset, size))
|
positions.append((offset, size))
|
||||||
offset += size
|
offset += size
|
||||||
|
@ -50,7 +57,7 @@ with TemporaryDirectory(prefix="tapedrive") as tmpdir_str:
|
||||||
name = (titles[i] if i < len(titles) else b"")[:117]
|
name = (titles[i] if i < len(titles) else b"")[:117]
|
||||||
pos = positions[i] if i < len(titles) else (0, 0)
|
pos = positions[i] if i < len(titles) else (0, 0)
|
||||||
if i < len(titles):
|
if i < len(titles):
|
||||||
print(f"{i:2d} {pos[0]} + {pos[1]}")
|
print(f"{i:2d} {pos[0]} + {pos[1]} {name}")
|
||||||
written_bytes += fout.write(pos[0].to_bytes(4, "big"))
|
written_bytes += fout.write(pos[0].to_bytes(4, "big"))
|
||||||
written_bytes += fout.write(pos[1].to_bytes(4, "big"))
|
written_bytes += fout.write(pos[1].to_bytes(4, "big"))
|
||||||
written_bytes += fout.write(name)
|
written_bytes += fout.write(name)
|
||||||
|
|
Loading…
Reference in New Issue