Files
thomasasfk_drs2dd/util.py
T
544146 48f93de564 Clean up code a little
- Move duck blocks down, they were too high
- Change timing on jump notes, 1/8th to allow user to jump over
- Change timing on duck blocks, 1/16h to allow user to duck under on beat
- Move jump note blocks down into the ground, so they're easy to jump over
- Shorten song duration by 10 seconds, so you don't wait at the end for 10 seconds
- Add more metadata to the files
2023-09-19 21:32:01 +01:00

60 lines
1.8 KiB
Python

from __future__ import annotations
import contextlib
import os
import subprocess
from datetime import datetime
def get_ogg_and_duration(folder_path) -> tuple[str, str] | tuple[None, None]:
ogg_files = [f for f in os.listdir(folder_path) if f.endswith('.ogg')]
matching_files = [f for f in ogg_files if f.endswith('clip1.ogg')]
if matching_files:
ogg_file = os.path.join(folder_path, matching_files[0])
with contextlib.suppress(subprocess.CalledProcessError):
ffprobe_cmd = [
'ffprobe',
'-i', ogg_file,
'-show_entries', 'format=duration',
'-v', 'error',
'-of', 'default=noprint_wrappers=1:nokey=1',
]
duration_str = subprocess.check_output(
ffprobe_cmd, text=True,
).strip()
return ogg_file, duration_str
return None, None
def get_song_cover_path(folder_path) -> str | None:
cover_files = [
f for f in os.listdir(folder_path) if f.startswith('jk_') and f.endswith('_b.png')
]
if not cover_files:
return None
return os.path.join(folder_path, cover_files[0])
def create_valid_filename(input_string: str):
valid_chars = f'-_() {os.sep}{os.sep}'
sanitized_string = ''.join(
c for c in input_string if c.isalnum() or c in valid_chars
).rstrip()
max_filename_length = 255
return sanitized_string[:max_filename_length]
def datetime_to_ticks(dt):
epoch = datetime(1, 1, 1)
dt_delta = dt - epoch
# total_seconds() returns seconds, but we need 100-nanosecond intervals
ticks = dt_delta.total_seconds() * 10 ** 7
return int(ticks)
def yyyymmdd_to_ticks(date_str: str):
dt = datetime.strptime(date_str, '%Y%m%d')
return datetime_to_ticks(dt)