本文整理汇总了Python中mutagen.File方法的典型用法代码示例。如果您正苦于以下问题:Python mutagen.File方法的具体用法?Python mutagen.File怎么用?Python mutagen.File使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mutagen
的用法示例。
在下文中一共展示了mutagen.File方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import mutagen [as 别名]
# 或者: from mutagen import File [as 别名]
def main(argv):
from mutagen import File
parser = OptionParser()
parser.add_option("--no-flac", help="Compatibility; does nothing.")
parser.add_option("--no-mp3", help="Compatibility; does nothing.")
parser.add_option("--no-apev2", help="Compatibility; does nothing.")
(options, args) = parser.parse_args(argv[1:])
if not args:
raise SystemExit(parser.print_help() or 1)
for filename in args:
print_(u"--", filename)
try:
print_(u"-", File(filename).pprint())
except AttributeError:
print_(u"- Unknown file type")
except Exception as err:
print_(text_type(err))
print_(u"")
示例2: is_partial
# 需要导入模块: import mutagen [as 别名]
# 或者: from mutagen import File [as 别名]
def is_partial(audio_file, track):
args = get_args()
if (args.partial_check == "none"):
return False
def audio_file_duration(audio_file):
if (path_exists(audio_file)):
_file = mutagen.File(audio_file)
if _file is not None and _file.info is not None:
return _file.info.length
return None
audio_file_dur = audio_file_duration(audio_file)
# for 'weak', give a ~1.5 second wiggle-room
if (args.partial_check == "strict"):
return (audio_file_dur is None or
track.duration > (audio_file_dur * 1000))
else:
return (audio_file_dur is not None and
(track.duration - 1500) > (audio_file_dur * 1000))
# borrowed from eyeD3
示例3: embed_album_art
# 需要导入模块: import mutagen [as 别名]
# 或者: from mutagen import File [as 别名]
def embed_album_art(cover_filepath, audio_filepaths):
""" Embed album art into audio files. """
with open(cover_filepath, "rb") as f:
cover_data = f.read()
for filepath in audio_filepaths:
mf = mutagen.File(filepath)
if (isinstance(mf.tags, mutagen._vorbis.VComment) or
isinstance(mf, mutagen.ogg.OggFileType)):
picture = mutagen.flac.Picture()
picture.data = cover_data
picture.type = mutagen.id3.PictureType.COVER_FRONT
picture.mime = "image/jpeg"
encoded_data = base64.b64encode(picture.write())
mf["metadata_block_picture"] = encoded_data.decode("ascii")
elif (isinstance(mf.tags, mutagen.id3.ID3) or
isinstance(mf, mutagen.id3.ID3FileType)):
mf.tags.add(mutagen.id3.APIC(mime="image/jpeg",
type=mutagen.id3.PictureType.COVER_FRONT,
data=cover_data))
elif (isinstance(mf.tags, mutagen.mp4.MP4Tags) or
isinstance(mf, mutagen.mp4.MP4)):
mf["covr"] = [mutagen.mp4.MP4Cover(cover_data,
imageformat=mutagen.mp4.AtomDataType.JPEG)]
mf.save()
示例4: removeAllTagsFromPath
# 需要导入模块: import mutagen [as 别名]
# 或者: from mutagen import File [as 别名]
def removeAllTagsFromPath(path):
# subprocess.check_output(['id3v2', '--delete-all', path])
mutagenFile = mutagen.File(path)
print(type(mutagenFile), path)
if isinstance(mutagenFile, mutagen.flac.FLAC):
mutagenFile.clear_pictures()
mutagenFile.delete(path)
# mutagenFile.save(path, deleteid3=True, padding=lambda x: 0)
return
elif isinstance(mutagenFile, mutagen.id3.ID3FileType):
mutagenFile.delete(path)
return
elif isinstance(mutagenFile, mutagen.apev2.APEv2File):
mutagenFile.delete(path)
return
mutagenFile.delete(path)
示例5: removeAllTags
# 需要导入模块: import mutagen [as 别名]
# 或者: from mutagen import File [as 别名]
def removeAllTags(filelike, recurse=True):
try:
filelike.seek(0)
id3 = mutagen.id3.ID3(filelike)
except mutagen.id3._util.ID3NoHeaderError:
pass
else:
filelike.seek(0)
id3.delete(filelike)
filelike.seek(0)
mutagenFile = mutagen.File(filelike)
# print(type(mutagenFile), filelike.name)
if isinstance(mutagenFile, mutagen.flac.FLAC) and mutagenFile.pictures:
mutagenFile.clear_pictures()
filelike.seek(0)
mutagenFile.save(filelike, padding=lambda x: 0)
filelike.seek(0)
if mutagenFile:
mutagenFile.delete(filelike)
示例6: getCoverImage
# 需要导入模块: import mutagen [as 别名]
# 或者: from mutagen import File [as 别名]
def getCoverImage(self):
path = self.path()
directory = os.path.dirname(path)
for cover in ['cover.jpg', 'cover.png']:
coverfilename = os.path.join(directory, cover)
if os.path.exists(coverfilename):
return coverfilename
try:
metadata = self.metadata
except AttributeError:
try:
metadata = mutagen.File(path)
except mutagen.mp3.HeaderNotFoundError as e:
print("Error reading %s:" % path, e)
return None
try:
image = extractFrontCover(metadata)
except OSError:
print('Error extracting image from %s' % path)
return None
return image
示例7: fixMtime
# 需要导入模块: import mutagen [as 别名]
# 或者: from mutagen import File [as 别名]
def fixMtime(self):
collection = getMusic()
count = 0
for song in collection:
if not song.mtime():
try:
mtime = os.path.getmtime(song.path())
except os.FileNotFoundError:
print('File %s not found: removing from db' % song.path())
MusicDatabase.removeSong(song)
continue
if not config['immutableDatabase']:
c = MusicDatabase.getCursor()
sql = text('UPDATE songs set mtime = :mtime '
'WHERE id = :id')
c.execute(sql.bindparams(mtime=mtime, id=song.id))
count += 1
if count % 10:
MusicDatabase.commit()
print('Fixed %s' % song.path())
else:
print('%s already fixed' % song.path())
MusicDatabase.commit()
示例8: add_metadata
# 需要导入模块: import mutagen [as 别名]
# 或者: from mutagen import File [as 别名]
def add_metadata(self, file, sound):
# "sound" requires a "freesound_client.get_sound" object
# http://wiki.hydrogenaud.io/index.php?title=APE_key
try:
# Write it
audio = FLAC(file)
audio["title"] = sound.name
audio["Artist"] = sound.username
audio["Comment"] = sound.description
audio["Publisher"] = "freesound.org"
audio["File"] = sound.url
# Save it
audio.pprint()
audio.save()
# Read it
file_info = mutagen.File(file)
log.debug("Result metadata update:")
log.debug(file_info)
return file_info
except Exception as e:
log.debug(e)
return False
示例9: get_audio_length
# 需要导入模块: import mutagen [as 别名]
# 或者: from mutagen import File [as 别名]
def get_audio_length(path):
try:
audio = MutagenFile(path, FORMATS)
if audio is not None:
return int(audio.info.length) * 1000
return 0
except:
return 0
示例10: get_audio_length
# 需要导入模块: import mutagen [as 别名]
# 或者: from mutagen import File [as 别名]
def get_audio_length(path):
try:
audio = MutagenFile(path, FORMATS)
if audio is not None:
return int(audio.info.length) * 1000
return 0
except:
return 0
示例11: test_add_album_art
# 需要导入模块: import mutagen [as 别名]
# 或者: from mutagen import File [as 别名]
def test_add_album_art():
musictools.add_album_art(location, albumart)
tags = File(location)
assert 'APIC:Cover' in tags.keys() != None
示例12: _add_audio_length_on_file
# 需要导入模块: import mutagen [as 别名]
# 或者: from mutagen import File [as 别名]
def _add_audio_length_on_file(audio_file, text, _length):
file = mutagen.File(audio_file)
try:
length = file.info.length
except AttributeError:
# In case the type was not recognized by mutagen
logging.warning("Audio file incorrect : %s", audio_file)
length = 0
return [audio_file, text, length]
示例13: initialize
# 需要导入模块: import mutagen [as 别名]
# 或者: from mutagen import File [as 别名]
def initialize(file):
audio = mutagen.File(file)
if (isinstance(audio, MP4)):
return mp4Editor(file)
if (isinstance(audio, MP3)):
return mp3Editor(file)
示例14: get_filelist
# 需要导入模块: import mutagen [as 别名]
# 或者: from mutagen import File [as 别名]
def get_filelist(self, src_dir):
res = {}
for f in sorted(os.listdir(src_dir)):
fpath = join(src_dir, f)
fname = f[:-4]
fext = f[-4:].lower()
if isfile(fpath) and fext in ('.wav', '.mp3', '.ogg'):
if fname in res:
if fext=='.wav':
res[fname]['ext'] = fext
elif fext=='.ogg' and res[fname]['ext']!='.wav':
res[fname]['ext'] = fext
else:
res[fname] = {
'fpath': fpath,
'ext': fext
}
for fname in res:
try:
res[fname]['length'] = mutagen.File(res[fname]['fpath']).info.length
except Exception as e:
res[fname]['length'] = 0
logging.warning(e)
return res
示例15: checkSongsExistenceInPath
# 需要导入模块: import mutagen [as 别名]
# 或者: from mutagen import File [as 别名]
def checkSongsExistenceInPath(self, song, callback=None):
if not os.path.exists(song.path()):
if os.path.lexists(song.path()):
print('Broken symlink at %s' % song.path())
else:
print('File not found: %s' % song.path())
if callback:
callback(song)