@@ -149,41 +149,28 @@ def _download(self, songs, template=None):
149
149
for song in songs :
150
150
song_id = song ['id' ]
151
151
152
- try :
153
- title = song .get ('title' , "<empty>" )
154
- artist = song .get ('artist' , "<empty>" )
155
- album = song .get ('album' , "<empty>" )
152
+ title = song .get ('title' , "<empty>" )
153
+ artist = song .get ('artist' , "<empty>" )
154
+ album = song .get ('album' , "<empty>" )
156
155
157
- logger .debug (
158
- "Downloading {title} -- {artist} -- {album} ({song_id})" .format (
159
- title = title , artist = artist , album = album , song_id = song_id
160
- )
156
+ logger .debug (
157
+ "Downloading {title} -- {artist} -- {album} ({song_id})" .format (
158
+ title = title , artist = artist , album = album , song_id = song_id
161
159
)
160
+ )
162
161
163
- suggested_filename , audio = self .api .download_song (song_id )
162
+ try :
163
+ _ , audio = self .api .download_song (song_id )
164
164
except CallFailure as e :
165
165
result = ({}, {song_id : e })
166
166
else :
167
167
with tempfile .NamedTemporaryFile (suffix = '.mp3' , delete = False ) as temp :
168
168
temp .write (audio )
169
169
170
170
metadata = mutagen .File (temp .name , easy = True )
171
+ filepath = template_to_filepath (template , metadata ) + '.mp3'
171
172
172
- if template != os .getcwd ():
173
- suggested_filename = suggested_filename .replace ('.mp3' , '' )
174
- t = template .replace ("%suggested%" , suggested_filename )
175
- filepath = template_to_filepath (t , metadata ) + '.mp3'
176
-
177
- dirname , basename = os .path .split (filepath )
178
-
179
- if basename == '.mp3' :
180
- filepath = os .path .join (dirname , suggested_filename )
181
- else :
182
- filepath = suggested_filename
183
-
184
- dirname = os .path .dirname (filepath )
185
-
186
- if dirname :
173
+ if os .path .dirname (filepath ):
187
174
try :
188
175
os .makedirs (dirname )
189
176
except OSError :
0 commit comments