2014-10-31 9 views
0

내 스크립트는 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() 

답변

1

는 말한다 :이 모듈은 초기 개발 단계에 아직도있다

하는 것으로. 많은 기능이 지원되지 않습니다 ...

나중에 앨범 아트 및 여러 값 태그 처리와 관련된 제한 사항을 설명하므로 하나의 앨범 앨범 태그에 여러 가지 문제가 있다는 것은 놀랄만한 것은 아닙니다. 체재. 이 버전은 0.0.5입니다.

자세한 설명을 원하시면 the source 번을 읽어 보거나 작성자에게 문의하십시오. (아마도 filing a bug에 의해 가능할 것입니다.) 그러나 나는 유일한 해결책이 "스스로 고칠 것"이거나 "다른 누군가가 그것을 충분히 수행 할 때까지 기다리는 것"이라고 내기를 기꺼이합니다.

+0

아, 감사합니다. 아마도 스크립트에서 MP3 처리를위한 정규 Mutagen을 사용하고 그 작동 여부를 확인하게 될 것입니다. –

+0

@ JohnBroderick : 그런데 MusicBrainz Picard와 Quod Libet에 포함 된 Mutagen 랩퍼를보고 싶을 수도 있습니다. – abarnert