1010import os
1111import sys
1212import base64
13+ import urllib
14+
1315
1416
1517def set_metadata_tags (args , audio_file , idx , track , ripper ):
@@ -69,7 +71,19 @@ def set_metadata_tags(args, audio_file, idx, track, ripper):
6971 genres_ascii = [to_ascii (genre ) for genre in genres ]
7072
7173 # cover art image
72- image = track .album .cover ()
74+ def get_cover_image (image_link ):
75+ image_link = 'http://open.spotify.com%s' % (
76+ image_link [len ('spotify' ):].replace (':' , '/' ))
77+ cover_file = urllib .urlretrieve (image_link )[0 ]
78+
79+ with open (cover_file , "rb" ) as f :
80+ if f .mode == "rb" :
81+ return f .read ()
82+ else :
83+ return None
84+
85+ image_link = str (track .album .cover (2 ).link )
86+ image = get_cover_image (image_link )
7387
7488 def tag_to_ascii (_str , _str_ascii ):
7589 return _str if args .ascii_path_only else _str_ascii
@@ -82,13 +96,13 @@ def idx_of_total_str(_idx, _total):
8296
8397 def save_cover_image (embed_image_func ):
8498 if image is not None :
85- image . load ()
99+
86100 def write_image (file_name ):
87101 cover_path = os .path .dirname (audio_file )
88102 cover_file = os .path .join (cover_path , file_name )
89103 if not path_exists (cover_file ):
90104 with open (cover_file , "wb" ) as f :
91- f .write (image . data )
105+ f .write (image )
92106
93107 if args .cover_file is not None :
94108 write_image (args .cover_file [0 ])
@@ -109,7 +123,7 @@ def embed_image():
109123 mime = 'image/jpeg' ,
110124 type = 3 ,
111125 desc = 'Front Cover' ,
112- data = image . data
126+ data = image
113127 )
114128 )
115129
@@ -168,7 +182,7 @@ def embed_image():
168182 mime = 'image/jpeg' ,
169183 type = 3 ,
170184 desc = 'Front Cover' ,
171- data = image . data
185+ data = image
172186 )
173187 )
174188
@@ -224,7 +238,7 @@ def embed_image():
224238 pic .type = 3
225239 pic .mime = "image/jpeg"
226240 pic .desc = "Front Cover"
227- pic .data = image . data
241+ pic .data = image
228242 if args .output_type == "flac" :
229243 audio .add_picture (pic )
230244 else :
@@ -262,7 +276,7 @@ def set_mp4_tags(audio):
262276 audio .add_tags ()
263277
264278 def embed_image ():
265- audio .tags ["covr" ] = mp4 .MP4Cover (image . data )
279+ audio .tags ["covr" ] = mp4 .MP4Cover (image )
266280
267281 save_cover_image (embed_image )
268282
@@ -289,7 +303,7 @@ def set_m4a_tags(audio):
289303 audio .add_tags ()
290304
291305 def embed_image ():
292- audio .tags [str ("covr" )] = m4a .M4ACover (image . data )
306+ audio .tags [str ("covr" )] = m4a .M4ACover (image )
293307
294308 save_cover_image (embed_image )
295309
0 commit comments