本文整理汇总了Python中mutagen.flac.FLAC.delete方法的典型用法代码示例。如果您正苦于以下问题:Python FLAC.delete方法的具体用法?Python FLAC.delete怎么用?Python FLAC.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mutagen.flac.FLAC
的用法示例。
在下文中一共展示了FLAC.delete方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _tag_flac
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import delete [as 别名]
def _tag_flac(self, trackno):
""" Calls the mutagen library to perform metadata changes for FLAC files """
logging.debug("Tagging '%s'" % os.path.join(self.dest_dir_name,
self.file_tag_map[trackno][1]))
audio = FLAC(os.path.join(self.dest_dir_name,
self.file_tag_map[trackno][1]))
try:
encoding = audio["ENCODING"]
except:
encoding = ""
audio.delete()
# add FLAC tag data
audio["TITLE"] = self.tracks[trackno][1]
audio["ARTIST"] = self.tracks[trackno][0]
audio["ALBUM"] = self.title
audio["COMPOSER"] = self.artist
audio["ORGANIZATION"] = self.label
audio["CATALOGNUM"] = self.catno
audio["GENRE"] = self.genre
audio["YEAR"] = self.year
audio["TRACKNUMBER"] = str(trackno)
audio["TRACKTOTAL"] = str(len(self.tracks))
audio["DESCRIPTION"] = '::> Don\'t believe the hype! <::'
if(len(encoding) != 0):
audio["ENCODING"] = encoding
audio.pprint()
try:
audio.save()
except:
logging.error("Unable to tag '%s'" % self.file_tag_map[trackno][1])
raise DiscogsTaggerError, "Unable to write tag '%s'" % \
self.file_tag_map[trackno][1]
示例2: test_delete_multiple
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import delete [as 别名]
def test_delete_multiple(self):
# on delete we delete both
f = FLAC(self.filename)
f.delete()
assert len(f.tags) == 0
f = FLAC(self.filename)
assert f.tags is None
示例3: test_delete_multiple_fail
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import delete [as 别名]
def test_delete_multiple_fail(self):
f = FLAC(self.filename)
with pytest.raises(MutagenError):
f.delete(os.devnull)
f.save()
# if delete failed we shouldn't see a difference
f = FLAC(self.filename)
assert f.metadata_blocks[2] is f.tags
assert f.metadata_blocks[3].code == f.tags.code
示例4: remove_all
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import delete [as 别名]
def remove_all(self):
'''
Remove the "metadata" block from the file
'''
if self.backup is True:
shutil.copy2(self.filename, self.output)
self.filename = self.output
mfile = FLAC(self.filename)
mfile.delete()
mfile.clear_pictures()
mfile.save()
示例5: reset_flac_tags
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import delete [as 别名]
def reset_flac_tags(full_path):
f = FLAC(full_path)
t = f.tags
# we need to save the 'vendor' string because calling mutagen's delete() removes it too
for block in list(f.metadata_blocks):
if isinstance(block, VCFLACDict):
vendor = block.vendor
f.clear_pictures()
f.delete()
for item in 'artist', 'album', 'tracknumber', 'tracktotal', 'title', 'date':
if item in t:
f[item] = t[item]
for block in list(f.metadata_blocks):
if isinstance(block, VCFLACDict):
block.vendor = vendor
f.save(deleteid3=True)
示例6: TFLAC
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import delete [as 别名]
class TFLAC(TestCase):
SAMPLE = os.path.join("tests", "data", "silence-44-s.flac")
NEW = SAMPLE + ".new"
def setUp(self):
shutil.copy(self.SAMPLE, self.NEW)
self.failUnlessEqual(open(self.SAMPLE).read(), open(self.NEW).read())
self.flac = FLAC(self.NEW)
def test_delete(self):
self.failUnless(self.flac.tags)
self.flac.delete()
self.failIf(self.flac.tags)
flac = FLAC(self.NEW)
self.failIf(flac.tags)
def test_module_delete(self):
delete(self.NEW)
flac = FLAC(self.NEW)
self.failIf(flac.tags)
def test_info(self):
self.failUnlessAlmostEqual(FLAC(self.NEW).info.length, 3.7, 1)
def test_keys(self):
self.failUnlessEqual(self.flac.keys(), self.flac.tags.keys())
def test_values(self):
self.failUnlessEqual(self.flac.values(), self.flac.tags.values())
def test_items(self):
self.failUnlessEqual(self.flac.items(), self.flac.tags.items())
def test_vc(self):
self.failUnlessEqual(self.flac['title'][0], 'Silence')
def test_write_nochange(self):
f = FLAC(self.NEW)
f.save()
self.failUnlessEqual(open(self.SAMPLE).read(), open(self.NEW).read())
def test_write_changetitle(self):
f = FLAC(self.NEW)
f["title"] = "A New Title"
f.save()
f = FLAC(self.NEW)
self.failUnlessEqual(f["title"][0], "A New Title")
def test_write_changetitle_unicode_value(self):
f = FLAC(self.NEW)
f["title"] = u"A Unicode Title \u2022"
f.save()
f = FLAC(self.NEW)
self.failUnlessEqual(f["title"][0], u"A Unicode Title \u2022")
def test_write_changetitle_unicode_key(self):
f = FLAC(self.NEW)
f[u"title"] = "A New Title"
f.save()
f = FLAC(self.NEW)
self.failUnlessEqual(f[u"title"][0], "A New Title")
def test_write_changetitle_unicode_key_and_value(self):
f = FLAC(self.NEW)
f[u"title"] = u"A Unicode Title \u2022"
f.save()
f = FLAC(self.NEW)
self.failUnlessEqual(f[u"title"][0], u"A Unicode Title \u2022")
def test_force_grow(self):
f = FLAC(self.NEW)
f["faketag"] = ["a" * 1000] * 1000
f.save()
f = FLAC(self.NEW)
self.failUnlessEqual(f["faketag"], ["a" * 1000] * 1000)
def test_force_shrink(self):
self.test_force_grow()
f = FLAC(self.NEW)
f["faketag"] = "foo"
f.save()
f = FLAC(self.NEW)
self.failUnlessEqual(f["faketag"], ["foo"])
def test_add_vc(self):
f = FLAC(os.path.join("tests", "data", "no-tags.flac"))
self.failIf(f.tags)
f.add_tags()
self.failUnless(f.tags == [])
self.failUnlessRaises(ValueError, f.add_tags)
def test_add_vc_implicit(self):
f = FLAC(os.path.join("tests", "data", "no-tags.flac"))
self.failIf(f.tags)
f["foo"] = "bar"
self.failUnless(f.tags == [("foo", "bar")])
self.failUnlessRaises(ValueError, f.add_tags)
def test_ooming_vc_header(self):
# issue 112: Malformed FLAC Vorbis header causes out of memory error
# http://code.google.com/p/mutagen/issues/detail?id=112
#.........这里部分代码省略.........
示例7: TFLAC
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import delete [as 别名]
class TFLAC(TestCase):
SAMPLE = os.path.join(DATA_DIR, "silence-44-s.flac")
def setUp(self):
self.NEW = get_temp_copy(self.SAMPLE)
self.flac = FLAC(self.NEW)
def tearDown(self):
os.unlink(self.NEW)
def test_zero_samples(self):
# write back zero sample count and load again
self.flac.info.total_samples = 0
self.flac.save()
new = FLAC(self.flac.filename)
assert new.info.total_samples == 0
assert new.info.bitrate == 0
assert new.info.length == 0.0
def test_bitrate(self):
assert self.flac.info.bitrate == 101430
old_file_size = os.path.getsize(self.flac.filename)
self.flac.save(padding=lambda x: 9999)
new_flac = FLAC(self.flac.filename)
assert os.path.getsize(new_flac.filename) > old_file_size
assert new_flac.info.bitrate == 101430
def test_padding(self):
for pad in [0, 42, 2**24 - 1, 2 ** 24]:
self.flac.save(padding=lambda x: pad)
new = FLAC(self.flac.filename)
expected = min(2**24 - 1, pad)
self.assertEqual(new.metadata_blocks[-1].length, expected)
def test_save_multiple_padding(self):
# we don't touch existing padding blocks on save, but will
# replace them in the file with one at the end
def num_padding(f):
blocks = f.metadata_blocks
return len([b for b in blocks if isinstance(b, Padding)])
num_blocks = num_padding(self.flac)
self.assertEqual(num_blocks, 1)
block = Padding()
block.length = 42
self.flac.metadata_blocks.append(block)
block = Padding()
block.length = 24
self.flac.metadata_blocks.append(block)
self.flac.save()
self.assertEqual(num_padding(self.flac), num_blocks + 2)
new = FLAC(self.flac.filename)
self.assertEqual(num_padding(new), 1)
self.assertTrue(isinstance(new.metadata_blocks[-1], Padding))
def test_increase_size_new_padding(self):
self.assertEqual(self.flac.metadata_blocks[-1].length, 3060)
value = u"foo" * 100
self.flac[u"foo"] = [value]
self.flac.save()
new = FLAC(self.NEW)
self.assertEqual(new.metadata_blocks[-1].length, 2752)
self.assertEqual(new[u"foo"], [value])
def test_delete(self):
self.failUnless(self.flac.tags)
self.flac.delete()
self.assertTrue(self.flac.tags is not None)
self.assertFalse(self.flac.tags)
flac = FLAC(self.NEW)
self.assertTrue(flac.tags is None)
def test_delete_change_reload(self):
self.flac.delete()
self.flac.tags["FOO"] = ["BAR"]
self.flac.save()
assert FLAC(self.flac.filename)["FOO"] == ["BAR"]
# same with delete failing due to IO etc.
with pytest.raises(MutagenError):
self.flac.delete(os.devnull)
self.flac.tags["FOO"] = ["QUUX"]
self.flac.save()
assert FLAC(self.flac.filename)["FOO"] == ["QUUX"]
def test_module_delete(self):
delete(self.NEW)
flac = FLAC(self.NEW)
self.failIf(flac.tags)
def test_info(self):
self.failUnlessAlmostEqual(FLAC(self.NEW).info.length, 3.7, 1)
def test_keys(self):
self.failUnlessEqual(
list(self.flac.keys()), list(self.flac.tags.keys()))
def test_values(self):
#.........这里部分代码省略.........
示例8: TRCK
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import delete [as 别名]
mp3['TRCK'] = TRCK(encoding=3, text=t['track_num'])
mp3['TIT2'] = TIT2(encoding=3, text=t['track_title'])
mp3.save()
elif t['track_format'] == 'ogg':
ogg = OggVorbis(t['track_fname'])
ogg.delete()
ogg['artist'] = t['track_artist']
ogg['album'] = t['album']
ogg['date'] = t['date']
ogg['year'] = t['year']
ogg['tracknumber'] = t['track_num']
ogg['title'] = t['track_title']
ogg.save()
elif t['track_format'] == 'flac':
flac = FLAC(t['track_fname'])
flac.delete()
flac['artist'] = t['track_artist']
flac['album'] = t['album']
flac['date'] = t['date']
flac['year'] = t['year']
flac['tracknumber'] = t['track_num']
flac['title'] = t['track_title']
flac.save()
# change back to original working directory
os.chdir(ori_cwd)
示例9: ID3
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import delete [as 别名]
if ft == u'mp3':
# remove tags in audio files
try:
audio = ID3(f)
audio.delete()
except mutagen.id3.ID3NoHeaderError:
pass
elif ft == u'flac':
audio = FLAC(f)
# remember the encoding settings before deleting all tags:
try:
encoding = audio["ENCODING"]
except:
encoding = ""
audio.delete()
if ft == u'mp3':
# add new ID3 tags
try:
id3 = mutagen.id3.ID3(f)
except mutagen.id3.ID3NoHeaderError:
id3 = mutagen.id3.ID3()
if ft == u'mp3':
# adding new id3 frames
id3.add(TIT2(encoding=3, text=disc.track_list[c].title))
id3.add(TPE1(encoding=3, text=disc.track_list[c].artist))
id3.add(TALB(encoding=3, text=disc.title))
id3.add(TCOM(encoding=3, text=disc.artist))
id3.add(TPUB(encoding=3, text=disc.label))
id3.add(TDRC(encoding=3, text=disc.year))