import fileinfo import types #from fileinfo import MP3FileInfo mp3file = fileinfo.MP3FileInfo() #print mp3file #print MP3FileInfo.__setitem__("name", "/Music/1. B.o.B - Dont Let Me Fall.mp3") #print type(fileinfo.MP3FileInfo) #print fileinfo.MP3FileInfo.tagDataMap m = fileinfo.MP3FileInfo() #print m.tagDataMap f = open("/home/grenouille/Music/1. B.o.B - Dont Let Me Fall.mp3", "rb") print f.name print f #print f.tell() f.seek(-128, 2) #print f.tell() tagData = f.read(128) #print tagData #print f.tell() print f.closed f.close() print f #print f.closed
{'name':'/music/_singles/kairo.mp3', 'genre':31} >>> f["genre"] = 32 #or this one >>> f {'name':'/music/_singles/kairo.mp3', 'genre':32} #6. Overriding __setitem__ in MP3FileInfo: def __setitem__(self, key, item): if key == "name" and item: self.__parse(item) #we do extra parsing of the item when key=name FileInfo.__setitem__(self, key, item) #we must call the ancestor method #6.2. Example 5.15. Setting an MP3FileInfo's name >>> import fileinfo >>> mp3file = fileinfo.MP3FileInfo() #an MP3Fileinfo instance >>> mp3file["name"] = "/music/_singles/kairo.mp3" #here we're using the setitem defined above >>> mp3file {'album': 'Rave Mix', 'artist': '***DJ MARY-JANE***', 'genre': 31, 'title': 'KAIRO****THE BEST GOA', 'name': '/music/_singles/kairo.mp3', 'year': '2000', 'comment': 'http://mp3.com/DJMARYJANE'}#the extra processing happened #7. Introducing Class Attributes: class MP3FileInfo(FileInfo): "store ID3v1.0 MP3 tags" tagDataMap = { "title" : ( 3, 33, stripnulls), '''class attribute''' "artist" : ( 33, 63, stripnulls), "album" : ( 63, 93, stripnulls), "year" : ( 93, 97, stripnulls),
#! /usr/bin/python import sys sys.path.append('../../') import fileinfo print fileinfo.MP3FileInfo print fileinfo.MP3FileInfo.tagDataMap m = fileinfo.MP3FileInfo() print m.tagDataMap
#!/usr/bin/python import os import sys import fileinfo f = fileinfo.FileInfo("C:\Users\Public\Music\Sample Music\Sleep\ Away.mp3") #print f #print f.__getitem__("name") f.__setitem__("Genre",31) #print f mp3File = fileinfo.MP3FileInfo() #print mp3File mp3File["name"] = "C:\Users\Public\Music\Sample Music\Sleep\ Away.mp3" #print mp3File.tagDataMap #modifying class attribute class counter: count = 0 def __init__(self): self.__class__.count +=1 a = counter() b = counter() #print b.count #print counter.count