本文整理匯總了Python中quodlibet.formats.MusicFile類的典型用法代碼示例。如果您正苦於以下問題:Python MusicFile類的具體用法?Python MusicFile怎麽用?Python MusicFile使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了MusicFile類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: TOperonImageClear
class TOperonImageClear(TOperonBase):
# <image-file> <file> [<files>]
def setUp(self):
super(TOperonImageClear, self).setUp()
self.fcover = get_temp_copy(get_data_path('test-2.wma'))
self.cover = MusicFile(self.fcover)
def tearDown(self):
os.unlink(self.fcover)
super(TOperonImageClear, self).tearDown()
def test_misc(self):
self.check_true(["image-clear", "-h"], True, False)
self.check_true(["image-clear", self.fcover], False, False)
self.check_false(["image-clear"], False, True)
def test_not_supported(self):
path = get_data_path('test.mid')
out, err = self.check_false(["image-clear", path], False, True)
self.assertTrue("supported" in err)
def test_clear(self):
images = self.cover.get_images()
self.assertEqual(len(images), 1)
self.check_true(["image-clear", self.fcover], False, False)
self.cover.reload()
images = self.cover.get_images()
self.assertEqual(len(images), 0)
示例2: TOperonImageSet
class TOperonImageSet(TOperonBase):
# <image-file> <file> [<files>]
def setUp(self):
super(TOperonImageSet, self).setUp()
from gi.repository import GdkPixbuf
h, self.filename = mkstemp(".png")
os.close(h)
wide = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB, True, 8, 150, 10)
wide.savev(self.filename, "png", [], [])
self.fcover = get_temp_copy(get_data_path('test-2.wma'))
self.cover = MusicFile(self.fcover)
self.fcover2 = get_temp_copy(get_data_path('test-2.wma'))
self.cover2 = MusicFile(self.fcover2)
def tearDown(self):
os.unlink(self.fcover)
os.unlink(self.filename)
super(TOperonImageSet, self).tearDown()
def test_misc(self):
self.check_true(["image-set", "-h"], True, False)
self.check_false(["image-set", self.fcover], False, True)
self.check_false(["image-set"], False, True)
self.check_false(["image-set", self.filename], False, True)
def test_not_supported(self):
path = get_data_path('test.mid')
out, err = self.check_false(
["image-set", self.filename, path], False, True)
self.assertTrue("supported" in err)
def test_set(self):
self.check_true(["image-set", self.filename, self.fcover],
False, False)
self.check_true(["-v", "image-set", self.filename, self.fcover],
False, True)
self.cover.reload()
images = self.cover.get_images()
self.assertEqual(len(images), 1)
with open(self.filename, "rb") as h:
self.assertEqual(h.read(), images[0].read())
def test_set_two(self):
self.check_true(
["image-set", self.filename, self.fcover, self.fcover2],
False, False)
with open(self.filename, "rb") as h:
image_data = h.read()
for audio in [self.cover, self.cover2]:
audio.reload()
image = audio.get_images()[0]
self.assertEqual(image.read(), image_data)
示例3: TOperonImageClear
class TOperonImageClear(TOperonBase):
# <image-file> <file> [<files>]
def setUp(self):
super(TOperonImageClear, self).setUp()
fd, self.fcover = mkstemp(".wma")
os.close(fd)
shutil.copy(os.path.join(DATA_DIR, 'test-2.wma'), self.fcover)
self.cover = MusicFile(self.fcover)
def tearDown(self):
os.unlink(self.fcover)
super(TOperonImageClear, self).tearDown()
def test_misc(self):
self.check_true(["image-clear", "-h"], True, False)
self.check_true(["image-clear", self.fcover], False, False)
self.check_false(["image-clear"], False, True)
def test_not_supported(self):
path = os.path.join(DATA_DIR, 'test.mid')
out, err = self.check_false(["image-clear", path], False, True)
self.assertTrue("supported" in err)
def test_clear(self):
images = self.cover.get_images()
self.assertEqual(len(images), 1)
self.check_true(["image-clear", self.fcover], False, False)
self.cover.reload()
images = self.cover.get_images()
self.assertEqual(len(images), 0)
示例4: TOperonImageExtract
class TOperonImageExtract(TOperonBase):
# [--dry-run] [--primary] [-d <destination>] <file> [<files>]
def setUp(self):
super(TOperonImageExtract, self).setUp()
h, self.fcover = mkstemp(".wma")
os.close(h)
shutil.copy(os.path.join(DATA_DIR, 'test-2.wma'), self.fcover)
self.cover = MusicFile(self.fcover)
def tearDown(self):
os.unlink(self.fcover)
super(TOperonImageExtract, self).tearDown()
def test_misc(self):
self.check_true(["image-extract", "-h"], True, False)
self.check_true(["image-extract", self.f], False, False)
self.check_true(["image-extract", self.f, self.f2], False, False)
self.check_false(["image-extract"], False, True)
def test_extract_all(self):
target_dir = os.path.dirname(self.fcover)
self.check_true(["image-extract", "-d", target_dir, self.fcover],
False, False)
self.assertEqual(len(self.cover.get_images()), 1)
image = self.cover.get_primary_image()
name = os.path.splitext(os.path.basename(self.fcover))[0]
expected = "%s-00.%s" % (name, image.extensions[0])
expected_path = os.path.join(target_dir, expected)
self.assertTrue(os.path.exists(expected_path))
with open(expected_path, "rb") as h:
self.assertEqual(h.read(), image.file.read())
def test_extract_primary(self):
target_dir = os.path.dirname(self.fcover)
self.check_true(
["image-extract", "-d", target_dir, "--primary", self.fcover],
False, False)
self.assertEqual(len(self.cover.get_images()), 1)
image = self.cover.get_primary_image()
name = os.path.splitext(os.path.basename(self.fcover))[0]
expected = "%s.%s" % (name, image.extensions[0])
expected_path = os.path.join(target_dir, expected)
self.assertTrue(os.path.exists(expected_path))
with open(expected_path, "rb") as h:
self.assertEqual(h.read(), image.file.read())
示例5: TAudioFileAllBase
class TAudioFileAllBase(object):
FILE = None
def setUp(self):
fd, filename = mkstemp(os.path.splitext(self.FILE)[-1])
os.close(fd)
shutil.copy(self.FILE, filename)
self.song = MusicFile(filename)
self.filename = filename
def tearDown(self):
try:
os.remove(self.filename)
except OSError:
pass
def test_clear_images_noent(self):
os.remove(self.filename)
self.assertRaises(AudioFileError, self.song.clear_images)
def test_set_image_noent(self):
os.remove(self.filename)
image = EmbeddedImage(None, "image/png")
self.assertRaises(AudioFileError, self.song.set_image, image)
def test_get_primary_image_noent(self):
os.remove(self.filename)
self.assertTrue(self.song.get_primary_image() is None)
def test_get_images_noent(self):
os.remove(self.filename)
self.assertEqual(self.song.get_images(), [])
def test_write_noent(self):
os.remove(self.filename)
try:
self.song.write()
except AudioFileError:
pass
def test_load_noent(self):
os.remove(self.filename)
self.assertRaises(AudioFileError, type(self.song), self.filename)
@classmethod
def create_tests(cls):
for i, file_ in enumerate(FILES):
new_type = type(cls.__name__ + str(i),
(cls, TestCase), {"FILE": file_})
assert new_type.__name__ not in globals()
globals()[new_type.__name__] = new_type
示例6: setUp
def setUp(self):
super(TOperonImageExtract, self).setUp()
h, self.fcover = mkstemp(".wma")
os.close(h)
shutil.copy(os.path.join(DATA_DIR, 'test-2.wma'), self.fcover)
self.cover = MusicFile(self.fcover)
示例7: TOperonImageSet
class TOperonImageSet(TOperonBase):
# <image-file> <file> [<files>]
def setUp(self):
super(TOperonImageSet, self).setUp()
from gi.repository import GdkPixbuf
h, self.filename = mkstemp(".png")
os.close(h)
wide = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB, True, 8, 150, 10)
wide.savev(self.filename, "png", [], [])
h, self.fcover = mkstemp(".wma")
os.close(h)
shutil.copy(os.path.join(DATA_DIR, 'test-2.wma'), self.fcover)
self.cover = MusicFile(self.fcover)
def tearDown(self):
os.unlink(self.fcover)
os.unlink(self.filename)
super(TOperonImageSet, self).tearDown()
def test_misc(self):
self.check_true(["image-set", "-h"], True, False)
self.check_false(["image-set", self.fcover], False, True)
self.check_false(["image-set"], False, True)
self.check_false(["image-set", self.filename], False, True)
def test_not_supported(self):
path = os.path.join(DATA_DIR, 'test.mid')
out, err = self.check_false(
["image-set", self.filename, path], False, True)
self.assertTrue("supported" in err)
def test_set(self):
self.check_true(["image-set", self.filename, self.fcover],
False, False)
self.check_true(["-v", "image-set", self.filename, self.fcover],
False, True)
self.cover.reload()
images = self.cover.get_images()
self.assertEqual(len(images), 1)
with open(self.filename, "rb") as h:
self.assertEqual(h.read(), images[0].file.read())
示例8: __init__
def __init__(self, track, pltag=None):
if isinstance(track, str):
self.track = MusicFile(track)
elif isinstance(track, quodlibet.formats._audio.AudioFile):
self.track = track
else:
raise TypeError("track must be either a quodlibet audiofile or a path to a music file.")
self.pltag = pltag or 'playlist'
示例9: setUp
def setUp(self):
super(TOperonImageSet, self).setUp()
from gi.repository import GdkPixbuf
h, self.filename = mkstemp(".png")
os.close(h)
wide = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB, True, 8, 150, 10)
wide.savev(self.filename, "png", [], [])
self.fcover = get_temp_copy(get_data_path('test-2.wma'))
self.cover = MusicFile(self.fcover)
self.fcover2 = get_temp_copy(get_data_path('test-2.wma'))
self.cover2 = MusicFile(self.fcover2)
示例10: PLTrack
class PLTrack(object):
'''Extends MusicFile with convenience methods for accessing playlists.'''
def __init__(self, track, pltag=None):
if isinstance(track, str):
self.track = MusicFile(track)
elif isinstance(track, quodlibet.formats._audio.AudioFile):
self.track = track
else:
raise TypeError("track must be either a quodlibet audiofile or a path to a music file.")
self.pltag = pltag or 'playlist'
def get_playlists(self):
"""Get the set of playlists of which this track is a member."""
playlists = self.track.get(self.pltag)
if playlists:
return tuple(playlists.split("\n"))
else:
return tuple()
示例11: test_reload
def test_reload(self):
audio = MusicFile(get_data_path('silence-44-s.mp3'))
audio["title"] = u"foo"
audio.reload()
self.assertNotEqual(audio.get("title"), u"foo")
示例12: setUp
def setUp(self):
super(TOperonImageClear, self).setUp()
self.fcover = get_temp_copy(os.path.join(DATA_DIR, 'test-2.wma'))
self.cover = MusicFile(self.fcover)
示例13: test_reload_fail
def test_reload_fail(self):
audio = MusicFile(os.path.join(DATA_DIR, 'silence-44-s.mp3'))
audio["title"] = u"foo"
audio.sanitize(fsnative(u"/dev/null"))
self.assertRaises(AudioFileError, audio.reload)
self.assertEqual(audio["title"], u"foo")
示例14: test_reload
def test_reload(self):
audio = MusicFile(os.path.join(DATA_DIR, 'silence-44-s.mp3'))
audio["title"] = u"foo"
audio.reload()
self.assertNotEqual(audio.get("title"), u"foo")
示例15: setUp
def setUp(self):
self.filename = get_temp_copy(self.FILE)
self.song = MusicFile(self.filename)