Skip to content
This repository was archived by the owner on Oct 20, 2018. It is now read-only.

Commit 0fff90b

Browse files
committed
Update for utility function changes
1 parent 7d34e66 commit 0fff90b

File tree

1 file changed

+11
-24
lines changed

1 file changed

+11
-24
lines changed

gmusicapi_wrapper/musicmanager.py

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -149,41 +149,28 @@ def _download(self, songs, template=None):
149149
for song in songs:
150150
song_id = song['id']
151151

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>")
156155

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
161159
)
160+
)
162161

163-
suggested_filename, audio = self.api.download_song(song_id)
162+
try:
163+
_, audio = self.api.download_song(song_id)
164164
except CallFailure as e:
165165
result = ({}, {song_id: e})
166166
else:
167167
with tempfile.NamedTemporaryFile(suffix='.mp3', delete=False) as temp:
168168
temp.write(audio)
169169

170170
metadata = mutagen.File(temp.name, easy=True)
171+
filepath = template_to_filepath(template, metadata) + '.mp3'
171172

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):
187174
try:
188175
os.makedirs(dirname)
189176
except OSError:

0 commit comments

Comments
 (0)