def parse_id666(data): #http://snesmusic.org/files/spc_file_format.txt tags = {} tags["title"] = data[:32] tags["album"] = data[32:64] tags["dumper"] = data[64:80] tags["comments"] = data[80:112] # Artist differs based on binary or text mode, which is implicit. # Instead of detecting "perfectly", we'll just detect enough for # the "artist" field. This fails for artist names that begin with # numbers or symbols less than ascii value A. if getbyte(data, 130) < b'A': try: tags["~#length"] = int(data[123:126].strip(b"\x00")) except ValueError: pass tags["artist"] = data[131:163] else: tags["artist"] = data[130:162] for k in listkeys(tags): if k[:2] == "~#": continue tags[k] = tags[k].replace(b"\x00", b"").decode("ascii", "ignore") if not tags[k]: del tags[k] return tags
def __init__(self, filename): with translate_errors(): with open(filename, "rb") as h: head = h.read(46) if len(head) != 46 or head[:27] != b"SNES-SPC700 Sound File Data": raise IOError("Not a valid SNES-SPC700 file") if getbyte(head, 35) == b"\x1a": data = h.read(210) if len(data) == 210: self.update(parse_id666(data)) self.setdefault("title", fsdecode(os.path.basename(filename)[:-4])) self.sanitize(filename)
def __init__(self, filename): with translate_errors(): with open(filename, "rb") as h: head = h.read(46) if len(head) != 46 or \ head[:27] != b'SNES-SPC700 Sound File Data': raise IOError("Not a valid SNES-SPC700 file") if getbyte(head, 35) == b'\x1a': data = h.read(210) if len(data) == 210: self.update(parse_id666(data)) self.setdefault("title", fsdecode(os.path.basename(filename)[:-4])) self.sanitize(filename)