2016-11-09 11 views
0

나는 서버에서 음악 파일을 다운로드하고 URL에서 앨범 이미지를 추가하는 python 스크립트를 작업하고 있습니다.이 경우 eyeD3 파이썬 라이브러리를 사용하고 있습니다. 원래 코드 이하.URL에서 앨범 아트를 포함하는 데 eyeD3 사용

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() 

나는이 명령의 다른 버전을 시도하고 그 중 하나가 오류를 반환하지만 위의 코드가하는 나에 ValueError가 "라는 오류 메시지가 반환로 이미지를 포함하지 않습니다 img_url은 아무도 없을해서는 안된다을 할 때 어떤 이미지 자료 없음 ".

다른 대안이 폴더의 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)."""