add "format" field to MediaFile for getting the file type

This allows using $format in your path format string, which is nice.
This commit is contained in:
Adrian Sampson 2010-07-21 23:01:32 -07:00
parent 1bb17de8b0
commit 2eb10e391a
5 changed files with 27 additions and 0 deletions

View file

@ -60,6 +60,7 @@ ITEM_FIELDS = [
('length', 'real', False, True),
('bitrate', 'int', False, True),
('format', 'text', False, True),
]
ITEM_KEYS_WRITABLE = [f[0] for f in ITEM_FIELDS if f[3] and f[2]]
ITEM_KEYS_META = [f[0] for f in ITEM_FIELDS if f[3]]

View file

@ -50,6 +50,18 @@ class FileTypeError(UnreadableFileError):
pass
# Constants.
# Human-readable type names.
TYPES = {
'mp3': 'MP3',
'mp4': 'AAC',
'ogg': 'OGG',
'flac': 'FLAC',
'ape': 'APE',
}
# Flags for encoding field behavior.
class Enumeration(object):
@ -660,3 +672,6 @@ class MediaFile(object):
else:
return self.mgfile.info.bitrate
@property
def format(self):
return TYPES[self.type]

Binary file not shown.

View file

@ -46,6 +46,7 @@ def item(): return beets.library.Item({
'path': 'somepath',
'length': 60.0,
'bitrate': 128000,
'format': 'FLAC',
'mb_trackid': 'someID-1',
'mb_albumid': 'someID-2',
'mb_artistid': 'someID-3',
@ -247,6 +248,11 @@ class DestinationTest(unittest.TestCase):
def test_sanitize_replaces_colon_with_dash(self):
p = beets.library._sanitize_path(u':', 'Darwin')
self.assertEqual(p, u'-')
def test_path_with_format(self):
self.lib.path_format = '$artist/$album ($format)'
p = self.lib.destination(self.i)
self.assert_('(FLAC)' in p)
class MigrationTest(unittest.TestCase):
"""Tests the ability to change the database schema between

View file

@ -207,26 +207,31 @@ read_only_correct_dicts = {
'full.mp3': {
'length': 1.0,
'bitrate': 80000,
'format': 'MP3',
},
'full.flac': {
'length': 1.0,
'bitrate': 705600,
'format': 'FLAC',
},
'full.m4a': {
'length': 1.0,
'bitrate': 64000,
'format': 'AAC',
},
'full.ogg': {
'length': 1.0,
'bitrate': 48000,
'format': 'OGG',
},
'full.ape': {
'length': 1.0,
'bitrate': 705600,
'format': 'APE',
},
}