import logging import uuid from pathlib import Path class UltraStarSongFile: def __init__(self): # Baisc Information self.path = "" self.title = "" self.artist = "" # TXT Metadata self.creator = "" self.version = "" self.encoding = "" # Detailed Song Information self.edition = "" self.genre = "" self.language = "" self.album = "" self.year = "" # Files used by Song self.cover = "" self.mp3 = "" self.background = "" self.video = "" # Technical Information about Song self.bpm = "" self.length = "" self.end = "" self.gap = "" self.videogap = "" self.previewstart = "" # Misc Shit self.resolution = "" self.id = "" # Other self.start = "" self.notesgap = "" self.relative = "" self.medleystartbeat = "" self.medleyendbeat = "" self.calcmedley = "" self.p1 = "" self.p2 = "" # Database Information self.songid = "" self.artistid = "" self.albumid = "" # Custom Tags self.duet = False self.custom_tags = [] # Songdata self.songdata = [] # list of lines with songdata def __eq__(self, other): if isinstance(other, self.__class__): if self.songid == "" or other.songid == "": return (self.title == other.title) and ( self.artist == other.artist) and (self.duet == other.duet) else: return self.songid == other.songid def set_attributes(self, parsed_data: dict) -> None: """ Setzt die attribute der Klasse Args: parsed_data: dict mit den geparseden tags und einem key "songdata" der eine liste, mit den Text/Tonhöhe Zeilen enthält """ k: str v: str for k, v in parsed_data.items(): if hasattr(self, k.lower()): setattr(self, k.lower(), v) else: self.custom_tags.append({k, v}) logging.debug("got custom tag: %s", k) if self.songid == "": self.songid = str(uuid.uuid4()) def dumps(self) -> str: out: str = "" out += f"#TITLE:{self.title}\n" out += f"#ARTIST:{self.artist}\n" out += f"#MP3:{self.mp3}\n" out += f"#BPM:{self.bpm}\n" out += f"#GAP:{self.gap}\n" if self.creator: out += f"#CREATOR:{self.creator}\n" if self.version: out += f"#VERSION:{self.version}\n" if self.encoding: out += f"#ENCODING:{self.encoding}\n" if self.edition: out += f"#EDITION:{self.edition}\n" if self.genre: out += f"#GENRE:{self.genre}\n" if self.language: out += f"#LANGUAGE:{self.language}\n" if self.album: out += f"#ALBUM:{self.album}\n" if self.year: out += f"#YEAR:{self.year}\n" if self.cover: out += f"#COVER:{self.cover}\n" if self.background: out += f"#BACKGROUND:{self.background}\n" if self.video: out += f"#VIDEO:{self.video}\n" if self.length: out += f"#LENGTH:{self.length}\n" if self.end: out += f"#END:{self.end}\n" if self.videogap: out += f"#VIDEOGAP:{self.videogap}\n" if self.previewstart: out += f"#PREVIEWSTART:{self.previewstart}\n" if self.resolution: out += f"#RESOLUTION:{self.resolution}\n" if self.id: out += f"#ID:{self.id}\n" if self.start: out += f"#START:{self.start}\n" if self.notesgap: out += f"#NOTESGAP:{self.notesgap}" if self.relative: out += f"#RELATIVE:{self.relative}\n" if self.medleystartbeat: out += f"#MEDLEYSTARTBEAT:{self.medleystartbeat}\n" if self.medleyendbeat: out += f"#MEDLEYENDBEAT:{self.medleyendbeat}\n" if self.calcmedley: out += f"#CALCMEDLEY:{self.calcmedley}\n" if self.p1: out += f"#P1:{self.p1}\n" if self.p2: out += f"#P2:{self.p2}\n" if self.songid: out += f"#SONGID:{self.songid}\n" if self.artistid: out += f"#ARTISTID:{self.artistid}\n" if self.albumid: out += f"#ALBUMID:{self.albumid}\n" if self.duet: out += f"#DUET:{self.duet}\n" out += "".join(self.songdata) return out def dump(self, file: Path): with open(file, "w", newline="\r\n") as f: f.write(self.dumps())