Created
May 12, 2014 06:16
-
-
Save shonenada/86d7e1dd0b915de8763b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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