Compare commits

...

2 commits

Author SHA1 Message Date
Ash Garcia
275f27155d anonymize bpms 2024-09-22 21:51:10 -07:00
Ash Garcia
33376ab44b script to aggregate dimocracy aliases from my hard drive 2024-09-22 21:51:02 -07:00
2 changed files with 58 additions and 0 deletions

View file

@ -0,0 +1,41 @@
from glob import iglob
import simfile
from simfile.dir import SimfilePack
from simfile.sm import SMChart, SMSimfile
from simfile.ssc import SSCChart
pack_pattern = R"D:\SM\Disabled Songs\dimocracy 202*"
def main():
for pack_dir in iglob(pack_pattern):
print(f"========== {pack_dir} ==========")
for sim, path in simfile.openpack(pack_dir=pack_dir, strict=False):
if len(sim.charts) == 0:
print(f"WARNING: {path} has no charts")
continue
matches = list(
filter(
lambda ch: ch.difficulty == "Challenge"
and ch.stepstype == "dance-single",
sim.charts,
)
)
if len(matches) > 0:
chart = matches[0]
else:
chart = sim.charts[0]
if isinstance(chart, SMChart):
print(chart.description)
else:
nonnull_fields = set(
filter(None, [chart.credit, chart.description, chart.chartname])
)
print(" OR ".join(nonnull_fields))
if __name__ == "__main__":
main()

View file

@ -3,6 +3,7 @@ import csv
import _csv
from dataclasses import dataclass
from datetime import datetime
from decimal import Decimal
import enum
import os
from random import Random
@ -22,6 +23,7 @@ import simfile
from simfile.dir import SimfilePack, SimfileDirectory
from simfile.sm import SMChart, SMSimfile
from simfile.ssc import SSCChart, SSCSimfile
from simfile.timing import BeatValues, BeatValue
from simfile.types import Simfile
@ -456,6 +458,17 @@ def maybe_anonymize_entries(
os.remove(absolute_path)
print(f"Deleted {os.path.relpath(absolute_path, temp_fs.root_path)}")
def anonymize_bpms(bpm_str: str | None) -> str:
bpm_values = BeatValues.from_str(bpm_str)
bpm_values.append(
BeatValue(
beat=bpm_values[-1].beat + 10000,
value=bpm_values[-1].value + Decimal("0.001"),
)
)
print(f"Anonymized BPMs from {repr(bpm_str)} to {repr(str(bpm_values))}")
return str(bpm_values)
for row in csv_contents:
if row[KnownColumns.IgnoreFile]:
continue
@ -484,6 +497,7 @@ def maybe_anonymize_entries(
sm.cdtitle = ""
sm.genre = ""
sm.music = f"{canonical_filename}.ogg"
sm.bpms = anonymize_bpms(sm.bpms)
for _chart in sm.charts:
sm_chart: SMChart = _chart # typing workaround
sm_chart.description = row[KnownColumns.GeneratedAlias]
@ -505,12 +519,15 @@ def maybe_anonymize_entries(
ssc.cdimage = ""
ssc.discimage = ""
ssc.labels = ""
ssc.bpms = anonymize_bpms(ssc.bpms)
for _chart in ssc.charts:
ssc_chart: SSCChart = _chart # typing workaround
ssc_chart.description = ""
ssc_chart.chartname = ""
ssc_chart.chartstyle = ""
ssc_chart.credit = row[KnownColumns.GeneratedAlias]
if ssc_chart.bpms:
ssc_chart.bpms = anonymize_bpms(ssc_chart.bpms)
maybe_rename_file(simfile_dir.ssc_path, f"{canonical_filename}.ssc")
print(
f"Scrubbed {os.path.relpath(absolute_simfile_dir_path, temp_fs.root_path)}/{canonical_filename}.ssc"