Skip to content

Instantly share code, notes, and snippets.

@shonenada
Created May 12, 2014 06:16
Show Gist options
  • Save shonenada/86d7e1dd0b915de8763b to your computer and use it in GitHub Desktop.
Save shonenada/86d7e1dd0b915de8763b to your computer and use it in GitHub Desktop.
class Music(object):
metadata_info = (
('title', 3, 33),
('artist', 33, 63),
('album', 63, 93),
('year', 93, 97),
('comment', 97, 126),
)
def __init__(self, filepath):
self.filepath = filepath
self.meta = {}
def parse(self):
try:
with open(self.filepath, 'rb') as msfile:
msfile.seek(-128, 2)
metadata = msfile.read(128)
print metadata
if metadata[:3] == 'TAG':
for tag, start, end in self.metadata_info:
self.meta[tag] = self._parse_string(metadata[start : end])
self.meta['genre'] = ord(metadata[127 : 128])
except IOError:
return False
def _parse_string(self, data):
return data.replace('\00', '').strip()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment