parent
a7d1313183
commit
572ab4f84f
37
mode/mp3.py
37
mode/mp3.py
|
@ -12,11 +12,29 @@ try:
|
|||
except ImportError:
|
||||
has_eyed3 = False
|
||||
|
||||
def _size_info(i):
|
||||
if i >= 1024 ** 2:
|
||||
return '%.2f MB' % (i * 1.0 / 1024 ** 2)
|
||||
elif i >= 1024:
|
||||
return '%.2f KB' % (i * 1.0 / 1024)
|
||||
else:
|
||||
return '%d B' % i
|
||||
|
||||
def _time_info(i):
|
||||
if i >= 60 ** 2:
|
||||
(j, k) = (i // 60 ** 2, i % 60 ** 2)
|
||||
return '%d:%02d:%02d secs' % (j, k // 60, k % 60)
|
||||
elif i >= 60:
|
||||
return '%d:%02d secs' % (i // 60, i % 60)
|
||||
else:
|
||||
return '%d secs' % i
|
||||
|
||||
def _str_info(s):
|
||||
if s:
|
||||
return str(s)
|
||||
else:
|
||||
return ''
|
||||
|
||||
def _num_pair_info(t):
|
||||
if t[0] and t[1]:
|
||||
return '%s/%s' % t
|
||||
|
@ -26,14 +44,15 @@ def _num_pair_info(t):
|
|||
return '/%s' % t[1]
|
||||
else:
|
||||
return ''
|
||||
|
||||
class Mp3Buffer(Buffer):
|
||||
btype = 'mp3'
|
||||
def __init__(self, path):
|
||||
Buffer.__init__(self)
|
||||
self.path = os.path.realpath(path)
|
||||
self.base = os.path.basename(self.path)
|
||||
self.tag = eyeD3.Tag()
|
||||
self.tag.link(self.path)
|
||||
self.af = eyeD3.tag.Mp3AudioFile(self.path)
|
||||
self.tag = self.af.getTag()
|
||||
def changed(self): return False
|
||||
def readonly(self): return True
|
||||
def path_exists(self): raise Exception
|
||||
|
@ -41,15 +60,16 @@ class Mp3Buffer(Buffer):
|
|||
def save(self, force=False): raise Exception, "can't save an mbox"
|
||||
def save_as(self, path): raise Exception, "can't save an mbox"
|
||||
def name(self): return 'mp3:%s' % (self.base)
|
||||
def open(self):
|
||||
self.lines = self._get_lines()
|
||||
def reload(self):
|
||||
lines = self._get_lines()
|
||||
self.set_lines(lines, force=True)
|
||||
def open(self): self.lines = self._get_lines()
|
||||
def reload(self): self.set_lines(self._get_lines(), force=True)
|
||||
def _get_lines(self):
|
||||
lines = [
|
||||
'# INFO',
|
||||
'Size: 666KB',
|
||||
'Filename: ' + os.path.basename(self.af.fileName),
|
||||
'Filesize: ' + _size_info(self.af.fileSize),
|
||||
'Playtime: ' + _time_info(self.af.getPlayTime()),
|
||||
'Bitrate: ' + _str_info(self.af.getBitRate()),
|
||||
'Samplerate: ' + _str_info(self.af.getSampleFreq()) + ' kHz',
|
||||
'# ID3',
|
||||
'Artist: ' + _str_info(self.tag.getArtist()),
|
||||
'Album: ' + _str_info(self.tag.getAlbum()),
|
||||
|
@ -63,7 +83,6 @@ class Mp3Buffer(Buffer):
|
|||
'TrackNum: ' + _num_pair_info(self.tag.getTrackNum()),
|
||||
#'Version: ' + _str_info(self.tag.getVersion()),
|
||||
'Year: ' + _str_info(self.tag.getYear()),
|
||||
'',
|
||||
]
|
||||
return lines
|
||||
|
||||
|
|
Loading…
Reference in New Issue