0

私のスクリプトでは、FLAC ファイルから画像を抽出するのに問題はありませんが、MP3 ファイルを指定すると、最初の画像のみが取得され、残りは取得されません。

私が試したこと:

  • ID3v2.3 から ID3v2.4 への変換
  • ID3v2.3 から APEv2 への変換
  • track['pictures'] の完全な配列を出力します。0 の範囲を超えません。

このスクリプトは、2 つのコマンド ライン引数を取ります。1 つ目は、イメージが書き込まれるサブディレクトリであるマウント名です。2 番目は、ファイルへのパスです。

例: python extract_art.py "クラシック" "hello.mp3"

# -*- 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()
4

1 に答える 1

1

ドキュメントが言うように:

このモジュールはまだ開発の初期段階にあることに注意してください。多くの機能がサポートされていません…</p>

後で、(とりわけ) アルバム アートと多値タグの処理に関する制限について説明するので、1 つの形式で複数のアルバム アート タグを使用すると問題が発生することはそれほど驚くべきことではありません。これはバージョン 0.0.5 のみです…</p>

より深い説明が必要な場合は、おそらくソースを掘り下げるか、著者に尋ねる必要があります。(おそらくバグを報告することによって。)しかし、唯一の解決策は「自分で修正する」か、「他の誰かがそれを実装するのに十分気になるまで待つ」ことであると確信しています。

于 2014-10-31T20:48:54.810 に答える