本文整理汇总了Python中mutagen.oggvorbis.OggVorbis.save方法的典型用法代码示例。如果您正苦于以下问题:Python OggVorbis.save方法的具体用法?Python OggVorbis.save怎么用?Python OggVorbis.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mutagen.oggvorbis.OggVorbis
的用法示例。
在下文中一共展示了OggVorbis.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_start
# 需要导入模块: from mutagen.oggvorbis import OggVorbis [as 别名]
# 或者: from mutagen.oggvorbis.OggVorbis import save [as 别名]
def set_start(filename, start_time):
"""
Writes the start of the song section to file
"""
song_meta = OggVorbis(filename)
song_meta[Settings.song_start_tag] = start_time
song_meta.save()
示例2: _EasyPythonMutagenOggVorbis
# 需要导入模块: from mutagen.oggvorbis import OggVorbis [as 别名]
# 或者: from mutagen.oggvorbis.OggVorbis import save [as 别名]
class _EasyPythonMutagenOggVorbis(object):
'''An interface like EasyId3, but for OggVorbis files.'''
def __init__(self, filename):
from mutagen.oggvorbis import OggVorbis
self.obj = OggVorbis(filename)
self.map = {
'album': 'album',
'comment': 'comment',
'artist': 'artist',
'title': 'title',
'albumartist': 'albumartist',
'tracknumber': 'tracknumber',
'discnumber': 'discnumber',
'composer': 'composer',
'genre': 'genre',
'description': 'description',
'website': 'www'}
def __getitem__(self, key):
return self.obj[self.map[key]]
def __setitem__(self, key, val):
self.obj[self.map[key]] = val
def __contains__(self, key):
return key in self.map and self.map[key] in self.obj
def save(self):
self.obj.save()
示例3: rm_ogg_cover
# 需要导入模块: from mutagen.oggvorbis import OggVorbis [as 别名]
# 或者: from mutagen.oggvorbis.OggVorbis import save [as 别名]
def rm_ogg_cover(self, episode):
filename = episode.local_filename(create=False)
if filename is None:
return
basename, extension = os.path.splitext(filename)
if episode.file_type() != 'audio':
return
if extension.lower() != '.ogg':
return
try:
ogg = OggVorbis(filename)
found = False
for key in ogg.keys():
if key.startswith('cover'):
found = True
ogg.pop(key)
if found:
logger.info('Removed cover art from OGG file: %s', filename)
ogg.save()
except Exception, e:
logger.warn('Failed to remove OGG cover: %s', e, exc_info=True)
示例4: download_and_fix_ogg
# 需要导入模块: from mutagen.oggvorbis import OggVorbis [as 别名]
# 或者: from mutagen.oggvorbis.OggVorbis import save [as 别名]
def download_and_fix_ogg(ogg, audio_metadata, cover_art_file):
global DRY_RUN
if DRY_RUN:
print "This is a dry run. So pretending to download the ogg..."
return "/tmp/ogg"
print "Now downloading the ogg in order to set the metadata in it..."
if not LIVE and len(sys.argv) >= 6 and os.path.exists(sys.argv[5]):
ogg_local_fn = sys.argv[5]
print "(using presupplied file %s)" % ogg_local_fn
else:
f, metadata = client.get_file_and_metadata(ogg)
ogg_local_fn = fetch_file(f, metadata)
print "Successfully downloaded (to %s): now editing metadata..." % ogg_local_fn
audio = OggVorbis(ogg_local_fn)
for k in audio_metadata.keys():
audio[k] = audio_metadata[k]
# add cover art
im=Image.open(cover_art_file)
w,h=im.size
p=Picture()
imdata=open(cover_art_file,'rb').read()
p.data=imdata
p.type=3
p.desc=''
p.mime='image/jpeg';
p.width=w; p.height=h
p.depth=24
dt=p.write();
enc=base64.b64encode(dt).decode('ascii');
audio['metadata_block_picture']=[enc];
audio.save()
print "Successfully updated metadata."
return ogg_local_fn
示例5: on_episode_downloaded
# 需要导入模块: from mutagen.oggvorbis import OggVorbis [as 别名]
# 或者: from mutagen.oggvorbis.OggVorbis import save [as 别名]
def on_episode_downloaded(self, episode):
log(u'on_episode_downloaded(%s/%s)' % (episode.channel.title, episode.title))
filename = episode.local_filename(create=False, check_only=True)
if filename is None:
return
basename, extension = os.path.splitext(filename)
if episode.file_type() == 'audio' and extension.lower() == '.ogg':
log(u'trying to remove cover from %s' % filename)
found = False
try:
ogg = OggVorbis(filename)
for key in ogg.keys():
if key.startswith('cover'):
found = True
ogg[key]=''
if found:
log(u'removed cover from the ogg file successfully')
ogg.save()
else:
log(u'there was no cover to remove in the ogg file')
except:
None
示例6: add_tag
# 需要导入模块: from mutagen.oggvorbis import OggVorbis [as 别名]
# 或者: from mutagen.oggvorbis.OggVorbis import save [as 别名]
def add_tag(f, tag, value):
if f.endswith('ogg'):
audio = OggVorbis(f)
elif f.endswith('flac'):
audio = FLAC(f)
audio[tag] = value
# audio.pprint()
audio.save()
示例7: ogg_tag
# 需要导入模块: from mutagen.oggvorbis import OggVorbis [as 别名]
# 或者: from mutagen.oggvorbis.OggVorbis import save [as 别名]
def ogg_tag(config):
print("Tagging " + config.ogg_file)
audio = OggVorbis(config.ogg_file)
# Add the tags.
for k in config.tags.keys():
audio[k] = config.tags[k]
audio.save()
示例8: remove_all
# 需要导入模块: from mutagen.oggvorbis import OggVorbis [as 别名]
# 或者: from mutagen.oggvorbis.OggVorbis import save [as 别名]
def remove_all(self):
if self.backup is True:
shutil.copy2(self.filename, self.output)
self.filename = self.output
mfile = OggVorbis(self.filename)
mfile.delete()
mfile.save()
示例9: Vorbis
# 需要导入模块: from mutagen.oggvorbis import OggVorbis [as 别名]
# 或者: from mutagen.oggvorbis.OggVorbis import save [as 别名]
class Vorbis(object):
tags = ['title', 'artist', 'album', 'genre', 'tracknumber']
def __init__(self, filename):
self._comment = OggVorbis(filename)
def write_random_tag(self, data):
tag = random.choice(Vorbis.tags)
self._comment[tag] = data
self._comment.save()
示例10: convert
# 需要导入模块: from mutagen.oggvorbis import OggVorbis [as 别名]
# 或者: from mutagen.oggvorbis.OggVorbis import save [as 别名]
def convert(self):
''' Convert wav -> ogg.'''
if self.songwav == self.song:
success = True
dec = None
else:
success, dec = self.decode()
if not success:
warn('Decoding of "%s" failed.' % self.song)
return
if dec and self.decoder == 'mpg123':
import mutagen
try:
info("additional option:" )
opts=['-R', str(mutagen.File(self.song).info.sample_rate)]
info(str(opts))
except:
opts=[]
else:
opts=[]
if dec:
enc = Popen(['oggenc', '-Q', '-o', self.songogg, '-q', str(self.conf.quality).replace('.', ','), '-'] + opts, stdin=dec.stdout)
enc.communicate()
dec.wait()
if dec.returncode < 0:
warn('Decoding of "%s" failed.' % self.song)
return False
elif enc.returncode < 0:
warn('Encoding of "%s" failed.' % self.song)
return False
else:
enc = call(['oggenc', '-o', self.songogg, '-q', str(self.conf.quality).replace('.', ','), self.songwav])
if enc != 0:
warn('Encoding of "%s" failed.' % self.songwav)
return False
elif not self.conf.preserve_wav and self.song != self.songwav:
os.remove(self.songwav)
if self.tags != {}:
try:
# Add tags to the ogg file
from mutagen.oggvorbis import OggVorbis
myogg = OggVorbis(self.songogg)
myogg.update(self.tags)
myogg.save()
except:
warn('Could not save the tags')
import traceback
traceback.print_exc()
return False
elif self.songwav != self.song or 'cd-' in self.decoder:
warn('No tags found...')
if self.conf.delete_input:
os.remove(self.song)
return True
示例11: ogg_write_tags
# 需要导入模块: from mutagen.oggvorbis import OggVorbis [as 别名]
# 或者: from mutagen.oggvorbis.OggVorbis import save [as 别名]
def ogg_write_tags(self, path, tag_type, input_string):
try:
ogg_audio = OggVorbis(path) #Reading tags
except:
print ("No Ogg tag found or %r is not a valid OGG file") \
% (path.encode(sys.stdout.encoding or "utf-8", "replace"), )
return
ogg_audio[tag_type] = input_string
ogg_audio.save()
示例12: setValue
# 需要导入模块: from mutagen.oggvorbis import OggVorbis [as 别名]
# 或者: from mutagen.oggvorbis.OggVorbis import save [as 别名]
def setValue(path, tag, value):
format = os.path.splitext(path)[1]
if(format == ".mp3"):
audio = EasyID3(path)
elif(format == ".ogg"):
audio = OggVorbis(path)
audio[tag] = value
audio.save()
示例13: test_save_split_setup_packet
# 需要导入模块: from mutagen.oggvorbis import OggVorbis [as 别名]
# 或者: from mutagen.oggvorbis.OggVorbis import save [as 别名]
def test_save_split_setup_packet(self):
fn = os.path.join(DATA_DIR, "multipage-setup.ogg")
shutil.copy(fn, self.filename)
audio = OggVorbis(self.filename)
tags = audio.tags
self.failUnless(tags)
audio.save()
self.audio = OggVorbis(self.filename)
self.failUnlessEqual(self.audio.tags, tags)
示例14: saveLabel
# 需要导入模块: from mutagen.oggvorbis import OggVorbis [as 别名]
# 或者: from mutagen.oggvorbis.OggVorbis import save [as 别名]
def saveLabel(self, file, label):
'''read file and save label tag'''
af = OggVorbis(file)
logger.info( "Tags BEFORE labelizer: " + str(af) )
af['label'] = label
af.save()
logger.info( "Tags AFTER labelizer: " + str(af) )
示例15: write_tags_to_ogg
# 需要导入模块: from mutagen.oggvorbis import OggVorbis [as 别名]
# 或者: from mutagen.oggvorbis.OggVorbis import save [as 别名]
def write_tags_to_ogg(path, tags):
audio = OggVorbis(path)
for dest, source in [['TITLE', 'TIT2'], ['ARTIST', 'TPE1'],
['ALBUM', 'TALB'], ['DATE', 'TDRC'],
['COPYRIGHT', 'TCOP'], ['LICENSE', 'WXXX:']]:
audio[dest] = tags[source]
audio['coverartmime'] = 'image/jpeg'
audio['coverartdescription'] = 'Radiotux_ID3Tag.jpg'
audio['coverart'] = get_ogg_coverart()
audio.save()