本文整理汇总了Python中mutagen.flac.FLAC.update方法的典型用法代码示例。如果您正苦于以下问题:Python FLAC.update方法的具体用法?Python FLAC.update怎么用?Python FLAC.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mutagen.flac.FLAC
的用法示例。
在下文中一共展示了FLAC.update方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_two_invalid
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import update [as 别名]
def test_two_invalid(tmpdir):
"""Test when two FLAC files have invalid tags."""
flac_dir = tmpdir.mkdir('flac')
flac_files = []
# One.
flac = flac_dir.join('Artist2 - 202 - Album - 01 - Title.flac').ensure(file=True)
with open(os.path.join(os.path.dirname(__file__), '1khz_sine.flac'), 'rb') as f:
flac.write(f.read(), 'wb')
tags = FLAC(str(flac.realpath()))
tags.update(dict(artist='Artist2', date='2012', album='Album', tracknumber='01', title='Title'))
tags.save()
flac_files.append(str(flac.realpath()))
# Two.
flac = flac_dir.join('Artist - 2014 - Album - 01 - Title.flac').ensure(file=True)
with open(os.path.join(os.path.dirname(__file__), '1khz_sine.flac'), 'rb') as f:
flac.write(f.read(), 'wb')
tags = FLAC(str(flac.realpath()))
tags.update(dict(artist='Artist2', date='2014', album='Album', tracknumber='01', title='Title'))
tags.save()
flac_files.append(str(flac.realpath()))
# Test.
a_messages = find_inconsistent_tags(flac_files, True, True)
e_messages = {
flac_files[0]: ["Filename date not four digits."],
flac_files[1]: ["Artist mismatch: Artist != Artist2"],
}
assert e_messages == a_messages
示例2: test_one_valid_two_invalid
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import update [as 别名]
def test_one_valid_two_invalid(tmpdir):
"""Test when one FLAC file is fully valid and another one isn't."""
flac_dir = tmpdir.mkdir('flac')
flac_files = []
# Valid.
flac = flac_dir.join('Artist2 - 2012 - Album - 01 - Title.flac').ensure(file=True)
with open(os.path.join(os.path.dirname(__file__), '1khz_sine.flac'), 'rb') as f:
flac.write(f.read(), 'wb')
tags = FLAC(str(flac.realpath()))
tags.update(dict(artist='Artist2', date='2012', album='Album', tracknumber='01', title='Title'))
tags.save()
flac_files.append(str(flac.realpath()))
# Invalid.
flac = flac_dir.join('Artist - 2014 - Album - 01 - Title.flac').ensure(file=True)
with open(os.path.join(os.path.dirname(__file__), '1khz_sine.flac'), 'rb') as f:
flac.write(f.read(), 'wb')
tags = FLAC(str(flac.realpath()))
tags.update(dict(artist='Artist2', date='2014', album='Album', tracknumber='01', title='Title'))
tags.save()
flac_files.append(str(flac.realpath()))
# Test.
a_messages = find_inconsistent_tags(flac_files, True, True)
e_messages = {flac_files[1]: [
"Artist mismatch: Artist != Artist2",
]}
assert e_messages == a_messages
示例3: test_write_tags
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import update [as 别名]
def test_write_tags(tmpdir):
"""Test writing tags from a FLAC to mp3 file."""
# Prepare.
flac = tmpdir.mkdir('flac').join('song.flac').ensure(file=True)
mp3 = tmpdir.mkdir('mp3').join('song.mp3').ensure(file=True)
with open(os.path.join(os.path.dirname(__file__), '1khz_sine.flac'), 'rb') as f:
flac.write(f.read(), 'wb')
with open(os.path.join(os.path.dirname(__file__), '1khz_sine.mp3'), 'rb') as f:
mp3.write(f.read(), 'wb')
flac, mp3 = str(flac.realpath()), str(mp3.realpath())
tags = FLAC(flac)
tags.update(dict(artist='Artist2', date='2012', album='Album', tracknumber='01', title='Title', unsyncedlyrics='L'))
image = Picture()
image.type, image.mime = 3, 'image/jpeg'
with open(os.path.join(os.path.dirname(__file__), '1_album_art.jpg'), 'rb') as f:
image.data = f.read()
tags.add_picture(image)
tags.save()
# Test.
ConvertFiles.write_tags(flac, mp3)
# Check.
id3 = ID3(mp3)
assert 'Artist2' == id3['TPE1']
assert '2012' == id3['TDRC']
assert 'Album' == id3['TALB']
assert '01' == id3['TRCK']
assert 'Title' == id3['TIT2']
assert 'L' == id3["USLT:Lyrics:'eng'"].text
with open(os.path.join(os.path.dirname(__file__), '1_album_art.jpg'), 'rb') as f:
assert f.read() == id3['APIC:'].data
assert ({}, [], [], []) == find_files(str(tmpdir.join('flac')), str(tmpdir.join('mp3')))
示例4: test_basic_numeric_tags_ignore_lyrics_art
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import update [as 别名]
def test_basic_numeric_tags_ignore_lyrics_art(tmpdir):
"""Test when everything but lyrics/art are valid, while ignoring lyrics/art."""
flac_dir = tmpdir.mkdir('flac')
flac = flac_dir.join('Artist2 - 2012 - Album - 01 - Title.flac').ensure(file=True)
with open(os.path.join(os.path.dirname(__file__), '1khz_sine.flac'), 'rb') as f:
flac.write(f.read(), 'wb')
tags = FLAC(str(flac.realpath()))
tags.update(dict(artist='Artist2', date='2012', album='Album', tracknumber='01', title='Title'))
tags.save()
a_messages = find_inconsistent_tags([str(flac.realpath())], True, True)
assert {} == a_messages
示例5: standardize
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import update [as 别名]
def standardize(self):
"""
"""
# 1. Is the album already standardized?
scanner = scan.Scanner()
if scanner.scan_album(self.abs_album_dir):
print 'Valid Album Detected'
return
# 2. Categories all files within the album subdir
self.find_files()
if not self.cue_file:
sys.stderr.write('Cue file not found\n')
return
# 3. Parse the cue file so we have enough info
cue = CueParser().parse(self.cue_file)
# 4. Do we have all split tracks present?
track_count = len(self.track_files)
if track_count != len(cue):
sys.stderr.write('Wrong number of tracks: {0}\n'.format(track_count))
return
# 5. Fix track metadata and rename them
# TODO: Deal with multi-CD releases (but this also on top-level)
track_data = dict([(v, getattr(cue,k)) for k,v in const.CUE_TO_TRACK.items()])
track_data['tracktotal'] = '{0:0>2}'.format(len(cue))
for i, track in enumerate(cue):
track_number = '{0:0>2}'.format(i+1)
track_data['tracknumber'] = track_number
track_data['title'] = track['TITLE']
track_file = self.track_files[i]
audio = FLAC(track_file)
audio.clear()
audio.update(track_data)
audio.save()
# Build proper track name
track_name = const.TRACK_FMT.format(track_number,
self.sanitize_title(track_data['title']),
)
os.rename(track_file, os.path.join(self.abs_album_dir, track_name))
# 6. Clean up other files
map(os.remove, self.rm_files+[self.cue_file])
map(shutil.rmtree, self.subdirs)
# 7. Rename album folder if necessary
album_parent = os.path.dirname(self.abs_album_dir)
abs_album_dir = os.path.join(os.path.dirname(self.abs_album_dir),
const.ALBUM_FMT.format(cue.REM_DATE,
self.sanitize_title(cue.TITLE)))
if self.abs_album_dir != abs_album_dir:
os.rename(self.abs_album_dir, abs_album_dir)
示例6: test_single_digit
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import update [as 别名]
def test_single_digit(tmpdir):
"""Test for single digit track numbers (should be 2) and dates (should be 4)."""
flac_dir = tmpdir.mkdir('flac')
flac = flac_dir.join('Artist2 - 1 - Album - 1 - Title.flac').ensure(file=True)
with open(os.path.join(os.path.dirname(__file__), '1khz_sine.flac'), 'rb') as f:
flac.write(f.read(), 'wb')
tags = FLAC(str(flac.realpath()))
tags.update(dict(artist='Artist2', date='1', album='Album', tracknumber='1', title='Title'))
tags.save()
a_messages = find_inconsistent_tags([str(flac.realpath())], True, True)
e_messages = {str(flac.realpath()): [
"Filename date not four digits.",
"Filename track number not two digits."
]}
assert e_messages == a_messages
示例7: test_file_name_alpha_instead_of_numeric
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import update [as 别名]
def test_file_name_alpha_instead_of_numeric(tmpdir):
"""Test when track number and date file names aren't integers."""
flac_dir = tmpdir.mkdir('flac')
flac = flac_dir.join('Artist2 - 2012 - Album - 0.1 - Title.flac').ensure(file=True)
with open(os.path.join(os.path.dirname(__file__), '1khz_sine.flac'), 'rb') as f:
flac.write(f.read(), 'wb')
tags = FLAC(str(flac.realpath()))
tags.update(dict(artist='Artist2', date='2012', album='Album', tracknumber='01 ', title='Title'))
tags.save()
a_messages = find_inconsistent_tags([str(flac.realpath())], True, True)
e_messages = {str(flac.realpath()): [
"Filename date not a number.",
"Filename track number not a number."
]}
assert e_messages == a_messages
示例8: test_art_lyrics
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import update [as 别名]
def test_art_lyrics(tmpdir):
"""Test when everything is valid."""
flac_dir = tmpdir.mkdir('flac')
flac = flac_dir.join('Artist2 - 2012 - Album - 01 - Title.flac').ensure(file=True)
with open(os.path.join(os.path.dirname(__file__), '1khz_sine.flac'), 'rb') as f:
flac.write(f.read(), 'wb')
tags = FLAC(str(flac.realpath()))
tags.update(dict(artist='Artist2', date='2012', album='Album', tracknumber='01', title='Title', unsyncedlyrics='L'))
image = Picture()
image.type, image.mime = 3, 'image/jpeg'
with open(os.path.join(os.path.dirname(__file__), '1_album_art.jpg'), 'rb') as f:
image.data = f.read()
tags.add_picture(image)
tags.save()
a_messages = find_inconsistent_tags([str(flac.realpath())], False, False)
assert {} == a_messages
示例9: test_basic_tags
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import update [as 别名]
def test_basic_tags(tmpdir):
"""Test when artist, album, title are the only valid tags."""
flac_dir = tmpdir.mkdir('flac')
flac = flac_dir.join('Artist2 - 2012 - Album - 01 - Title.flac').ensure(file=True)
with open(os.path.join(os.path.dirname(__file__), '1khz_sine.flac'), 'rb') as f:
flac.write(f.read(), 'wb')
tags = FLAC(str(flac.realpath()))
tags.update(dict(artist='Artist2', album='Album', title='Title'))
tags.save()
a_messages = find_inconsistent_tags([str(flac.realpath())])
e_messages = {str(flac.realpath()): [
"Date mismatch: 2012 != ",
"Track number mismatch: 01 != ",
"No album art.",
"No lyrics."
]}
assert e_messages == a_messages
示例10: test_skip_conversion
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import update [as 别名]
def test_skip_conversion(tmpdir):
flac_dir = tmpdir.mkdir('flac')
mp3_dir = tmpdir.mkdir('mp3')
flac = flac_dir.join('Artist - 2001 - Album - 01 - Title.flac').ensure(file=True)
with open(os.path.join(os.path.dirname(__file__), '1khz_sine.flac'), 'rb') as f:
flac.write(f.read(), 'wb')
tags = FLAC(str(flac))
tags.update(dict(artist='Artist', date='2001', album='Album', tracknumber='01', title='Title'))
tags.save()
song = Song(str(flac), str(flac_dir), str(mp3_dir))
song.get_metadata()
OPTIONS['--ignore-lyrics'] = True
OPTIONS['--ignore-art'] = True
assert song.metadata_ok
assert not song.skip_conversion
mp3 = mp3_dir.join('Artist - 2001 - Album - 01 - Title.mp3').ensure(file=True)
with open(os.path.join(os.path.dirname(__file__), '1khz_sine.mp3'), 'rb') as f:
mp3.write(f.read(), 'wb')
id3 = ID3(str(mp3))
id3.delete()
id3.add(COMM(encoding=3, lang='eng', desc='', text=(' ' * PAD_COMMENT)))
id3.save(v1=2)
comment = json.dumps(dict(
flac_mtime=int(flac.mtime()), flac_size=int(flac.size()), mp3_mtime=int(mp3.mtime()), mp3_size=int(mp3.size())
))
id3.add(COMM(encoding=3, lang='eng', desc='', text=comment)) # Now put in real data.
id3.save(v1=2)
song = Song(str(flac), str(flac_dir), str(mp3_dir))
song.get_metadata()
assert song.metadata_ok
assert song.skip_conversion
示例11: test_get_metadata
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import update [as 别名]
def test_get_metadata(tmpdir):
flac_dir = tmpdir.mkdir('flac')
mp3_dir = '/tmp/mp3_dir'
flac = flac_dir.join('Artist - 2001 - Album (Disc 1) - 01 - Title.flac').ensure(file=True)
with open(os.path.join(os.path.dirname(__file__), '1khz_sine.flac'), 'rb') as f:
flac.write(f.read(), 'wb')
tags = FLAC(str(flac))
tags.update(dict(artist='Artist', date='2001', album='Album', discnumber='1', tracknumber='01', title='Title',
unsyncedlyrics='L'))
image = Picture()
image.type, image.mime = 3, 'image/jpeg'
with open(os.path.join(os.path.dirname(__file__), '1_album_art.jpg'), 'rb') as f:
image.data = f.read()
tags.add_picture(image)
tags.save()
song = Song(str(flac), str(flac_dir), mp3_dir)
song.get_metadata()
assert dict() == OPTIONS
assert ['Artist', '2001', 'Album'] == [song.flac_artist, song.flac_date, song.flac_album]
assert ['01', 'Title'] == [song.flac_track, song.flac_title]
assert [True, True] == [song.flac_has_lyrics, song.flac_has_picture]
assert song.metadata_ok