29 lines
679 B
Python
29 lines
679 B
Python
# Bryan Schumaker (5 / 21 / 2011)
|
|
|
|
import tagpy
|
|
import datetime
|
|
|
|
FileRef = tagpy.FileRef
|
|
timedelta = datetime.timedelta
|
|
|
|
class Track:
|
|
def __init__(self, filepath):
|
|
ref = FileRef(filepath)
|
|
tags = ref.tag()
|
|
audio = ref.audioProperties()
|
|
|
|
self.artist = tags.artist or u"Unknown Artist"
|
|
self.album = tags.album or u"Unknown Album"
|
|
self.title = tags.title or u"Unknown Title"
|
|
self.track = tags.track
|
|
self.genre = tags.genre
|
|
self.year = tags.year
|
|
self.seconds = audio.length
|
|
self.filepath = filepath
|
|
|
|
lenstr = "%s" % timedelta(seconds=self.seconds)
|
|
if lenstr[:2] == "0:":
|
|
self.lenstr = lenstr[2:]
|
|
else:
|
|
self.lenstr = lenstr
|