当前位置: 首页>>代码示例>>Python>>正文


Python FLAC.add_tags方法代码示例

本文整理汇总了Python中mutagen.flac.FLAC.add_tags方法的典型用法代码示例。如果您正苦于以下问题:Python FLAC.add_tags方法的具体用法?Python FLAC.add_tags怎么用?Python FLAC.add_tags使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mutagen.flac.FLAC的用法示例。


在下文中一共展示了FLAC.add_tags方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: export_digital

# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import add_tags [as 别名]
def export_digital(item):
    """ Export and/or split digital files for an item (parallelized) """
    logging.warning('{0} -> {1}'.format(item.name, DIGITAL_FOLDER))
    if 'std' in item.option:        
        if JUST_ADD_TAGS:
            if item.digital_ext == 'mp3':
                mutagen_audio = EasyID3(item.digital_file_path)    
            elif item.digital_ext == 'flac':
                mutagen_audio = FLAC(item.digital_file_path)
            else:
                raise Exception('Format {0} not recognized for item {1}.'.format(item.digital_ext, item.name))
            mutagen_audio['title'] = item.album
            mutagen_audio['artist'] = item.artist
            mutagen_audio['albumartist'] = item.artist
            mutagen_audio['album'] = item.album
            mutagen_audio.save()
        else:
            # Export audio file
            digital_file = AudioSegment.from_wav(item.path)
            digital_file.export(out_f=item.digital_file_path, format=item.digital_ext, bitrate='192k', tags={
                'title':(item.album or item.artist), 'artist':item.artist, 'albumartist':item.artist, 'album':(item.album or item.artist)})
        # Add cover art
        if item.thumb and (item.digital_ext == 'mp3'):
            mutagen_audio = MP3(item.digital_file_path, ID3=ID3)
            try:
                # Add ID3 tag if it doesn't exist
                mutagen_audio.add_tags()
            except error:
                pass
            mutagen_audio.tags.add(
                APIC(
                    encoding=3, # 3 is for utf-8
                    mime='image/jpeg', # image/jpeg or image/png
                    type=3, # 3 is for the cover image
                    desc=u'Cover',
                    data=open(item.thumb_path, 'rb').read()
                )
            )            
            mutagen_audio.save()
        elif item.thumb and (item.digital_ext == 'flac'):
            mutagen_audio = File(item.digital_file_path)
            flac_image = Picture()
            flac_image.type = 3
            mime = 'image/jpeg'
            flac_image.desc = 'Cover'
            with open(item.thumb_path, 'rb') as f:
                flac_image.data = f.read()
            mutagen_audio.add_picture(flac_image)
            mutagen_audio.save()
        else:
            logging.warning('No cover found for item {0}'.format(item.name))
        if JUST_ADD_TAGS:
            os.rename(item.digital_file_path, item.digital_rename_path)
        if DROPBOX_COPY:
            # Copy finished digital file to Dropbox order folder
            shutil.copy2(item.digital_file_path, item.dropbox_order_folder)
    # Deluxe / 45
    else:        
        split.split_item(item, DIGITAL_FOLDER, DROPBOX_COPY)
开发者ID:broxeph,项目名称:ameryn,代码行数:61,代码来源:print-labels-5+-+tweaks.py

示例2: test_add_vc

# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import add_tags [as 别名]
 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)
开发者ID:andrewboie,项目名称:discogstool,代码行数:8,代码来源:test_flac.py

示例3: export_digital

# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import add_tags [as 别名]
def export_digital(item):
    """ Export and/or split digital files for an item (parallelized) """
    logging.info('{0} -> {1}'.format(item.name, digital_folder))
    if 'std' in item.option:        
        if just_add_tags:
            if item.digital_ext == 'mp3':
                mutagen_audio = ID3(item.digital_file_path)
                mutagen_audio.add(TIT2(encoding=3, text=item.album))
                mutagen_audio.add(TOA(encoding=3, text=item.artist))
                mutagen_audio.add(TP1(encoding=3, text=item.artist))
                mutagen_audio.add(TP2(encoding=3, text=item.artist))
                mutagen_audio.add(TP4(encoding=3, text=item.artist))
                mutagen_audio.add(TAL(encoding=3, text=item.album))
                mutagen_audio.save(v2_version=3)
            elif item.digital_ext == 'flac':
                mutagen_audio = FLAC(item.digital_file_path)
                mutagen_audio['title'] = item.album
                mutagen_audio['artist'] = item.artist
                mutagen_audio['albumartist'] = item.artist
                mutagen_audio['album'] = item.album
                mutagen_audio.save()
            else:
                raise Exception('Format {0} not recognized for item {1} tags.'.format(item.digital_ext, item.name))
        else:
            # Export audio file
            digital_file = AudioSegment.from_wav(item.path)
            digital_file.export(out_f=item.digital_file_path, format=item.digital_ext, bitrate=item.bitrate, tags={
                'title':(item.album or item.artist), 'artist':item.artist, 'albumartist':item.artist, 'album':(item.album or item.artist)},
                id3v2_version='3')
        # Add cover art
        if item.thumb and (item.digital_ext == 'mp3'):
            mutagen_audio = MP3(item.digital_file_path, ID3=ID3)
            try:
                # Add ID3 tag if it doesn't exist
                mutagen_audio.add_tags()
            except error:
                pass
            mutagen_audio.tags.add(
                APIC(
                    encoding=3, # 3 is for utf-8
                    mime='image/jpeg', # image/jpeg or image/png
                    type=3, # 3 is for the cover image
                    desc=u'Cover',
                    data=open(item.thumb_path, 'rb').read()
                )
            )            
            mutagen_audio.save(v2_version=3)
        elif item.thumb and (item.digital_ext == 'flac'):
            mutagen_audio = File(item.digital_file_path)
            flac_image = Picture()
            flac_image.type = 3
            mime = 'image/jpeg'
            flac_image.desc = 'Cover'
            with open(item.thumb_path, 'rb') as f:
                flac_image.data = f.read()
            mutagen_audio.add_picture(flac_image)
            mutagen_audio.save()
        elif item.image:
            logging.warning('No cover found for item {0}'.format(item.name))
        if just_add_tags:
            os.rename(item.digital_file_path, item.digital_rename_path)
    # Deluxe / 45
    else:        
        split.split_item(item, digital_folder, dropbox_move)
开发者ID:broxeph,项目名称:ameryn,代码行数:66,代码来源:print_labels.py

示例4: tagFile

# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import add_tags [as 别名]
	def tagFile(self,filename,metadata,art_url):
		image = None
		if art_url is not None:
			self.getFile('artwork.jpg',art_url,True)
			try:
				with open('artwork.jpg','rb') as file:
					image = file.read()
			except:
				pass
		if(filename.endswith('.mp3')):
			audio = MP3(filename,ID3=ID3)
			try:
				audio.add_tags()
			except:
				pass 
			audio.tags.add(
				APIC(
					encoding=3,
					mime='image/jpeg',
					type=3,
					desc=u'Cover',
					data=image
					)
				)
			audio.tags["TIT2"] = TIT2(encoding=3, text=metadata['title'])
			audio.tags["TPE1"] = TPE1(encoding=3, text=metadata['artist'])
			audio.tags["TDRC"] = TDRC(encoding=3, text=unicode(metadata['year']))
			audio.tags["TCON"] = TCON(encoding=3, text=metadata['genre'])
			audio.save()
		elif(filename.endswith('.flac')):
			audio = FLAC(filename)
			try:
				audio.add_tags()
			except:
				pass
			audio.tags['title'] = metadata['title']
			audio.tags['artist'] = metadata['artist']
			audio.tags['year'] = metadata['year']
			audio.tags['genre'] = metadata['genre']
			audio.tags.add(
				APIC(
					encoding=3,
					mime='image/jpeg',
					type=3,
					desc=u'Cover',
					data=image
					)
				)
			audio.save()
		elif(filename.endswith('.m4a')):
			audio = MP4(filename)
			try:
				audio.add_tags()
			except:
				pass
			covr = []
			covr.append(MP4Cover(image, MP4Cover.FORMAT_JPEG))
			audio.tags['covr'] = covr
			audio.tags['title'] = metadata['title']
			audio.tags['artist'] = metadata['artist']
			#audio.tags['year'] = metadata['year']
			audio.tags['genre'] = metadata['genre']
			audio.save()
		if os.path.isfile('artwork.jpg'):	
			os.remove('artwork.jpg')
开发者ID:jzbl,项目名称:soundcloud-dl,代码行数:67,代码来源:downloader.py

示例5: _load

# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import add_tags [as 别名]
 def _load(filename):
     audio = FLAC(filename)
     if audio.tags is None:
         audio.add_tags()
     return audio
开发者ID:Iconoclasteinc,项目名称:tgit,代码行数:7,代码来源:flac_file.py

示例6: export_digital

# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import add_tags [as 别名]
def export_digital(item):
    """ Export and/or split digital files for an item (parallelized) """
    logging.info('{0} -> {1}'.format(item.name, digital_folder))
    if 'std' in item.option:        
        if just_add_tags:
            if item.digital_ext == 'mp3':
                mutagen_audio = EasyID3(item.digital_file_path)    
            elif item.digital_ext == 'flac':
                mutagen_audio = FLAC(item.digital_file_path)
            else:
                raise Exception('Format {0} not recognized for item {1}.'.format(item.digital_ext, item.name))
            mutagen_audio['title'] = item.album
            mutagen_audio['artist'] = item.artist
            mutagen_audio['albumartist'] = item.artist
            mutagen_audio['album'] = item.album
            mutagen_audio.save()
        else:
            # Export audio file
            digital_file = AudioSegment.from_wav(item.path)
            digital_file.export(out_f=item.digital_file_path, format=item.digital_ext, bitrate=item.bitrate, tags={
                'title':(item.album or item.artist), 'artist':item.artist, 'albumartist':item.artist, 'album':(item.album or item.artist)})
        # Add cover art
        if item.thumb and (item.digital_ext == 'mp3'):
            mutagen_audio = MP3(item.digital_file_path, ID3=ID3)
            try:
                # Add ID3 tag if it doesn't exist
                mutagen_audio.add_tags()
            except error:
                pass
            mutagen_audio.tags.add(
                APIC(
                    encoding=3, # 3 is for utf-8
                    mime='image/jpeg', # image/jpeg or image/png
                    type=3, # 3 is for the cover image
                    desc=u'Cover',
                    data=open(item.thumb_path, 'rb').read()
                )
            )            
            mutagen_audio.save()
        elif item.thumb and (item.digital_ext == 'flac'):
            mutagen_audio = File(item.digital_file_path)
            flac_image = Picture()
            flac_image.type = 3
            mime = 'image/jpeg'
            flac_image.desc = 'Cover'
            with open(item.thumb_path, 'rb') as f:
                flac_image.data = f.read()
            mutagen_audio.add_picture(flac_image)
            mutagen_audio.save()
        else:
            logging.warning('No cover found for item {0}'.format(item.name))
        if just_add_tags:
            os.rename(item.digital_file_path, item.digital_rename_path)
    # Deluxe / 45
    else:        
        split.split_item(item, digital_folder, dropbox_move, item.bitrate)
    # Move original wave to mp3 folder, so we don't see it in the to-burn list
    if not 'cd' in item.format:
        shutil.move(item.path, os.path.join(digital_folder, item.filename))
        try:
            shutil.move(os.path.splitext(item.path)[0] + '.pkf', os.path.join(digital_folder, os.path.splitext(item.filename)[0] + '.pkf'))
        except IOError:
            pass
开发者ID:broxeph,项目名称:ameryn,代码行数:65,代码来源:print-labels-12+-+configparser+input.py


注:本文中的mutagen.flac.FLAC.add_tags方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。