내 스크립트는 FLAC 파일에서 이미지를 추출하는 데 문제가 없지만 MP3 파일이 주어지면 나머지 이미지가 아닌 첫 번째 이미지 만 가져옵니다.Mutagen (Mutagenwrapper) : MP3 파일에서 여러 이미지 추출
상황은 나는 시도했다 :
- 트랙 [ '사진']의 전체 배열에서 APEv2
- 인쇄에 ID3v2.4
- 변환 ID3v2.3에 ID3v2.3 변환.
스크립트는 두 개의 명령 줄 인수를 사용합니다. 첫 번째는 이미지가 기록 될 하위 디렉토리 인 마운트 이름입니다. 두 번째 파일의 경로입니다.
예 : 파이썬 extract_art.py "고전", "hello.mp3"the documentation으로
# -*- coding: UTF-8 -*-
# This script gets called from metadata.liq
# Run this script using Python 2
import sys
import random
import os
import codecs
from mutagenwrapper import read_tags
# Name of the stream (Exaples: anything-goes, anime)
mount_name = sys.argv[1]
# Name of the file to be opened
filename = sys.argv[2]
# Points to the path where images will be written to
full_path = "/mnt/album_art/" + mount_name + "/"
track = read_tags(filename)
try:
# Check if there is album art
album_art = track['pictures'][0]
except:
# If album art cannot be read, return a null string to flag deletion on album art that pervious song wrote.
album_art = ""
if album_art == "":
try:
# If no album art was found, attempt to delete album art that may have been previously written by another song
os.remove(full_path + 'albumart.jpg')
print("Deleted album art")
except:
# If there is no album art to delete
print("No album art to delete")
else:
#If album art was found in the current track, write the new album art and create the proper paths if necessary
if not os.path.exists(os.path.dirname(full_path)):
os.makedirs(os.path.dirname(full_path))
with open(full_path + 'albumart.jpg', 'wb') as f:
f.write(album_art)
print("Wrote new album art")
f.close()
# Same as writing album art, except with background image
background_image = ""
try:
background_image = track['pictures'][1]
except:
if background_image == "":
background_image = album_art
print("No background image found, using album art as background iamge.")
else:
background_image = ""
if background_image == "":
try:
os.remove(full_path + 'backgroundimage.jpg')
print("Deleted background image")
except:
print("No background image to delete")
else:
if not os.path.exists(os.path.dirname(full_path)):
os.makedirs(os.path.dirname(full_path))
with open(full_path + 'backgroundimage.jpg', 'wb') as f:
f.write(background_image)
print("Wrote new background image")
f.close()
아, 감사합니다. 아마도 스크립트에서 MP3 처리를위한 정규 Mutagen을 사용하고 그 작동 여부를 확인하게 될 것입니다. –
@ JohnBroderick : 그런데 MusicBrainz Picard와 Quod Libet에 포함 된 Mutagen 랩퍼를보고 싶을 수도 있습니다. – abarnert