2016-11-09 26 views
0

私は、サーバーから音楽ファイルをダウンロードし、URLからアルバム画像を追加するpythonスクリプトを作成しています。これは、eyeD3 pythonライブラリを使用しています。以下。eyeD3を使用してURLからアルバムアートを埋め込む

import eyed3 

mySong = eyed3.load('C:\Users\PC\Music\Test.mp3') 
mySong.tag.album_artist = u'Artist-Name' 
mySong.tag.images.remove(u'') 
mySong.tag.images.set(3, 'None', 'https://upload.wikimedia.org/wikipedia/en/6/60/Recovery_Album_Cover.jpg') 
mySong.tag.save() 

Iは、このコマンドの異なるバージョンを試してみました、それはエラーを返していないが、上記コードは「とValueErrorを示すエラーメッセージがないか、返しのような画像を埋め込むないか:NOの場合、画像データimg_urlはNoneはいけません"

誰かが私の他の代替手段がフォルダ内のURLストアから直接画像をダウンロードしてそこから埋め込み、明らかに私の他の解決策が改善される前にeyeD3のこの部分で成功しました。

答えて

0

あなたは使用をURLからの画像の画像データを取得し、eyed3

import urllib2 
response = urllib2.urlopen(your image url) 
imagedata=response.read() 

import eyed3 
file = eyed3.load("song.mp3") 
file.tag.images.set(3, imagedata , "image/jpeg" ,u"Discription") 
file.tag.save() 
0

でそれを使用するurllib2のに使用できる

mySong.tag.images.set(type_=3, img_data=None, mime_type=None, description=u"you can put a description here", img_url=u"https://upload.wikimedia.org/wikipedia/en/6/60/Recovery_Album_Cover.jpg") 

説明:

mySong.tag.images.setset関数を呼び出していますクラスImagesAccessorsrc/eyed3/id3/tag.pyで定義されています。

署名は以下の通りである:

def set(self, type_, img_data, mime_type, description=u"", img_url=None): 
    """Add an image of ``type_`` (a type constant from ImageFrame). 
    The ``img_data`` is either bytes or ``None``. In the latter case 
    ``img_url`` MUST be the URL to the image. In this case ``mime_type`` 
    is ignored and "-->" is used to signal this as a link and not data 
    (per the ID3 spec).""" 
関連する問題