本文整理汇总了Python中mutagen.File.add_tags方法的典型用法代码示例。如果您正苦于以下问题:Python File.add_tags方法的具体用法?Python File.add_tags怎么用?Python File.add_tags使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mutagen.File
的用法示例。
在下文中一共展示了File.add_tags方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: write_basic_tags
# 需要导入模块: from mutagen import File [as 别名]
# 或者: from mutagen.File import add_tags [as 别名]
def write_basic_tags(self, modify_tags, set_artist_to_album, set_version):
audio = File(self.filename, easy=True)
if audio.tags is None:
audio.add_tags()
if modify_tags:
if self.album is not None:
audio.tags['album'] = self.album
if self.title is not None:
audio.tags['title'] = self.title
if self.genre is not None:
audio.tags['genre'] = self.genre
if self.pubDate is not None:
audio.tags['date'] = self.pubDate
if set_artist_to_album:
audio.tags['artist'] = self.album
if type(audio) is EasyMP3:
audio.save(v2_version=set_version)
else:
# Not actually audio
audio.save()
示例2: write_info2file
# 需要导入模块: from mutagen import File [as 别名]
# 或者: from mutagen.File import add_tags [as 别名]
def write_info2file(self, info):
# open file with mutagen
audio = File(info['filename'], easy=True)
if audio is None:
return
# write title+album information into audio files
if audio.tags is None:
audio.add_tags()
# write album+title
if info['album'] is not None:
audio.tags['album'] = info['album']
if info['title'] is not None:
audio.tags['title'] = info['title']
# write genre tag
if self.container.config.genre_tag is not None:
audio.tags['genre'] = self.container.config.genre_tag
else:
audio.tags['genre'] = ''
# write pubDate
if info['pubDate'] is not None:
audio.tags['date'] = info['pubDate']
audio.save()
示例3: postProcessSong
# 需要导入模块: from mutagen import File [as 别名]
# 或者: from mutagen.File import add_tags [as 别名]
def postProcessSong(self, song):
if self.shouldGenerateTags:
try:
name = self.getSongPath(song)
localList = song.name.split("- ") #The song should be split as "artist - title". If not, it won't be recognized
artist = localList[0] if len(localList) > 1 else self.defaultArtist #The artist is usually first if its there. Otherwise no artist
if self.allSongsDefaultArtist: artist = self.defaultArtist
title = localList[1] if len(localList) > 1 else localList[0] #If there is no artist, the whole name is the title
artist = artist.lstrip().rstrip()
title = title.lstrip().rstrip()
#Appreciate this. It took upwards of 5 hours to get the damn software to do this.
try:
songID = EasyID3(name)
except ID3NoHeaderError:
songID = MutagenFile(name, easy = True)
songID.add_tags()
songID['artist'] = artist
songID['title'] = title
songID.save()
songID = ID3(name, v2_version=3) #EasyID3 doesn't support saving as 2.3 to get Windows to recognize it
songID.update_to_v23()
songID.save(v2_version=3)
except FileNotFoundError:
debug("File not found for: ", name)
示例4: ensure_id3_tag_present
# 需要导入模块: from mutagen import File [as 别名]
# 或者: from mutagen.File import add_tags [as 别名]
def ensure_id3_tag_present(filepath):
try:
meta = EasyID3(filepath)
except ID3NoHeaderError:
meta = File(filepath, easy=True)
meta.add_tags()
meta.save()
示例5: set_track_metadata
# 需要导入模块: from mutagen import File [as 别名]
# 或者: from mutagen.File import add_tags [as 别名]
def set_track_metadata(self, track = None, filename = None, url = None):
"""Find and set all metadata for a track"""
if url == None or track == None:
return None
if filename == None:
filename = get_track_filename(url)
# id3 is only for mp3
if not filename.endswith(".mp3"):
if filename.endswith(".wav"):
filename = self.convert_wav_to_mp3(filename)
else:
return None
# Set title
try:
meta = ID3(filename)
except ID3NoHeaderError:
try:
meta = File(filename, easy=True)
meta.add_tags()
meta.save()
meta = ID3(filename)
except:
return
except IOError:
return
try:
meta.add(TIT2(encoding=3, text=track.title))
meta.add(TCON(encoding=3, text=track.genre))
meta.add(TCOM(encoding=3, text=track.user["username"]))
meta.save()
artwork_filename = wget.download(track.artwork_url)
audio = MP3(filename, ID3=ID3)
# add ID3 tag if it doesn't exist
try:
audio.add_tags()
except error:
pass
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(artwork_filename).read()
)
)
audio.save()
except:
return
示例6: update_id3_tags
# 需要导入模块: from mutagen import File [as 别名]
# 或者: from mutagen.File import add_tags [as 别名]
def update_id3_tags(self):
"""
Update ID3 tags of downloaded song
"""
# Must init ID3 tags for appropriate header settings
audio = File(self.tags._title+'.mp3', easy=True)
audio.add_tags()
# Save new tags
audio['title'] = self.tags._title
audio['artist'] = self.tags._artist
audio['album'] = self.tags._album
audio.save(self.tags._title+'.mp3')
示例7: on_episode_downloaded
# 需要导入模块: from mutagen import File [as 别名]
# 或者: from mutagen.File import add_tags [as 别名]
def on_episode_downloaded(self, episode):
# exit if mutagen is not installed
if not mutagen_installed:
return
# read filename (incl. file path) from gPodder database
filename = episode.local_filename(create=False, check_only=True)
if filename is None:
return
# open file with mutagen
audio = File(filename, easy=True)
if audio is None:
return
# read title+album from gPodder database
album = episode.channel.title
title = episode.title
if (strip_album_from_title and title and album and title.startswith(album)):
title = title[len(album):].lstrip()
# convert pubDate to string
try:
pubDate = datetime.datetime.fromtimestamp(episode.pubDate).strftime('%Y-%m-%d %H:%M')
except:
pubDate = None
# write title+album information into audio files
if audio.tags is None:
audio.add_tags()
# write album+title
if album is not None:
audio.tags['album'] = album
if title is not None:
audio.tags['title'] = title
# write genre tag
if genre_tag is not None:
audio.tags['genre'] = genre_tag
else:
audio.tags['genre'] = ''
# write pubDate
if pubDate is not None:
audio.tags['date'] = pubDate
audio.save()
log(u'tagging.on_episode_downloaded(%s/%s)' % (episode.channel.title, episode.title))
示例8: download
# 需要导入模块: from mutagen import File [as 别名]
# 或者: from mutagen.File import add_tags [as 别名]
def download(self, path: str, web_driver: WebDriver = None, service_url: str = '',
lyrics='', website='', comment=''):
file_path = super().download(path)
try:
meta = id3.ID3(file_path)
except id3.ID3NoHeaderError:
meta = File(file_path)
meta.add_tags()
if web_driver:
lyrics = self.load_lyrics(web_driver)
meta['TPE1'] = id3._frames.TPE1(text=[self.artist])
meta['TIT2'] = id3._frames.TIT2(text=[self.title])
meta['USLT'] = id3._frames.USLT(text=lyrics)
meta['WORS'] = id3._frames.WORS(text=[website])
meta['COMM'] = id3._frames.COMM(text=[comment])
meta.save()
return file_path
示例9: write_basic_tags
# 需要导入模块: from mutagen import File [as 别名]
# 或者: from mutagen.File import add_tags [as 别名]
def write_basic_tags(self):
audio = File(self.filename, easy=True)
if audio.tags is None:
audio.add_tags()
if self.album is not None:
audio.tags['album'] = self.album
if self.title is not None:
audio.tags['title'] = self.title
if self.genre is not None:
audio.tags['genre'] = self.genre
if self.pubDate is not None:
audio.tags['date'] = self.pubDate
audio.save()
示例10: write_basic_tags
# 需要导入模块: from mutagen import File [as 别名]
# 或者: from mutagen.File import add_tags [as 别名]
def write_basic_tags(self):
audio = File(self.filename, easy=True)
if audio.tags is None:
audio.add_tags()
if self.album is not None:
audio.tags['album'] = self.album
if self.title is not None:
audio.tags['title'] = self.title
if self.genre is not None:
audio.tags['genre'] = self.genre
if self.pubDate is not None:
audio.tags['date'] = self.pubDate
if self.container.config.set_artist_to_album:
audio.tags['artist'] = self.album
audio.save()
示例11: main
# 需要导入模块: from mutagen import File [as 别名]
# 或者: from mutagen.File import add_tags [as 别名]
def main():
parser = argparse.ArgumentParser('Change or manipulate the ID3 tags of the audio files')
parser.add_argument('--artist','-a', default='', help='set the artist name')
parser.add_argument('--album','-A', default='', help='set the album name')
parser.add_argument('--title','-t', default='', help='set the title name')
parser.add_argument('--wors','-r', default='', help='set the internet radio url')
parser.add_argument('--year','-Y', default='', help='set the release year')
parser.add_argument('--cover','-c', default='', help='set the cover image')
parser.add_argument('--format', '-f', default='', help='''return the ID3 information as a formatted string;
the format string should containing one or more of the following specifiers:
, {artist}
, {title}
, {album}
, {year}
, {kbps}
, {wors}
, {len} (the length of the audio file, in seconds)
, {path} (the absolute path of the file)''')
parser.add_argument('--separator','-s', default='\n', help='define the separator used to append at the end of the output for each file (excluding the last file)')
parser.add_argument('--escape','-e', default='', help='define the characters that should be escaped in all the outputed fields')
parser.add_argument('audiofile', nargs='+', help='an audio file containing the ID3 tags')
args = parser.parse_args()
# input section
to_artist = unicode(args.artist.decode('utf-8'))
to_album = unicode(args.album.decode('utf-8'))
to_title = unicode(args.title.decode('utf-8'))
to_wors = unicode(args.wors.decode('utf-8'))
to_year = unicode(args.year.decode('utf-8'))
to_cover = unicode(args.cover.decode('utf-8'))
if to_cover != '':
cover_ext = os.path.splitext(to_cover)[1]
#print("Cover path is "+to_cover)
import mimetypes
mimetypes.init()
to_cover_mime = mimetypes.types_map[cover_ext]
#print("Mime type is "+to_cover_mime)
# output section
outputs = []
formatstr = unicode(args.format)
escapepat = ""
delimiter = ''
for c in unicode(args.escape):
esc = ''
if c in r'()[]\^$.|?*+{}':
esc = '\\'
escapepat = escapepat + delimiter + esc + c
delimiter = '|'
to_escape = False
if escapepat != '':
to_escape = True
escapepat = '(%s)' % escapepat
separator = unicode(args.separator)
def getinfo(file):
try:
return (file.info.bitrate / 1000, int(round(file.info.length)))
except:
return (0,0)
for f in args.audiofile:
path = unicode(os.path.realpath(f.decode('utf-8')))
artist = title = album = year = wors = ""
file = File(f)
kbps, len = getinfo(file)
try:
if (type(file) == MP3):
# add ID3 tag if it doesn't exist
try:
file.add_tags()
except:
pass
# should we set the tag in anyway?
if to_artist != '':
file.tags['TPE1'] = TPE1(encoding=3, text=to_artist)
if to_album != '':
file.tags['TALB'] = TALB(encoding=3, text=to_album)
if to_title != '':
file.tags['TIT2'] = TIT2(encoding=3, text=to_title)
if to_wors != '':
file.tags['WORS'] = WORS(url=to_wors)
if to_year != '':
file.tags['TDRL'] = TDRL(encoding=3, text=to_year)
if to_cover != '':
#print('The image data is '+open(to_cover).read())
file.tags['APIC:'] = APIC(
encoding=3,
mime=to_cover_mime,
type=3,
data=open(to_cover).read()
)
file.save()
# process mp3 specific tag information
artist = file.tags['TPE1'].text[0] if 'TPE1' in file.tags else ''
album = file.tags['TALB'].text[0] if 'TALB' in file.tags else ''
title = file.tags['TIT2'].text[0] if 'TIT2' in file.tags else ''
wors = file.tags['WORS'].url if 'WORS' in file.tags else ''
#.........这里部分代码省略.........