parent
be93716993
commit
fa6d1d8b74
|
@ -735,40 +735,57 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
|
||||||
trackAlreadyDownloaded = os.path.isfile(writepath)
|
trackAlreadyDownloaded = os.path.isfile(writepath)
|
||||||
if not trackAlreadyDownloaded or settings['overwriteFile'] == 'y':
|
if not trackAlreadyDownloaded or settings['overwriteFile'] == 'y':
|
||||||
logger.info(f"[{track['mainArtist']['name']} - {track['title']}] Downloading the track")
|
logger.info(f"[{track['mainArtist']['name']} - {track['title']}] Downloading the track")
|
||||||
try:
|
def downloadMusic(dz, track, trackAPI, queueItem, interface, writepath, result, settings):
|
||||||
with open(writepath, 'wb') as stream:
|
try:
|
||||||
stream_track(dz, track, stream, trackAPI, queueItem, interface)
|
with open(writepath, 'wb') as stream:
|
||||||
chmod(writepath, 0o770)
|
stream_track(dz, track, stream, trackAPI, queueItem, interface)
|
||||||
except downloadCancelled:
|
chmod(writepath, 0o770)
|
||||||
remove(writepath)
|
except downloadCancelled:
|
||||||
result['cancel'] = True
|
remove(writepath)
|
||||||
return result
|
result['cancel'] = True
|
||||||
except HTTPError:
|
return 1
|
||||||
remove(writepath)
|
except HTTPError:
|
||||||
if track['fallbackId'] != 0:
|
remove(writepath)
|
||||||
logger.warn(f"[{track['mainArtist']['name']} - {track['title']}] Track not available, using fallback id")
|
if track['fallbackId'] != 0:
|
||||||
trackNew = dz.get_track_gw(track['fallbackId'])
|
logger.warn(f"[{track['mainArtist']['name']} - {track['title']}] Track not available, using fallback id")
|
||||||
if not 'MD5_ORIGIN' in trackNew:
|
trackNew = dz.get_track_gw(track['fallbackId'])
|
||||||
trackNew['MD5_ORIGIN'] = dz.get_track_md5(trackNew['SNG_ID'])
|
|
||||||
track = parseEssentialTrackData(track, trackNew)
|
|
||||||
return downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=track, interface=interface)
|
|
||||||
elif not 'searched' in track and settings['fallbackSearch']:
|
|
||||||
logger.warn(f"[{track['mainArtist']['name']} - {track['title']}] Track not available, searching for alternative")
|
|
||||||
searchedId = dz.get_track_from_metadata(track['mainArtist']['name'], track['title'],
|
|
||||||
track['album']['title'])
|
|
||||||
if searchedId != 0:
|
|
||||||
trackNew = dz.get_track_gw(searchedId)
|
|
||||||
if not 'MD5_ORIGIN' in trackNew:
|
if not 'MD5_ORIGIN' in trackNew:
|
||||||
trackNew['MD5_ORIGIN'] = dz.get_track_md5(trackNew['SNG_ID'])
|
trackNew['MD5_ORIGIN'] = dz.get_track_md5(trackNew['SNG_ID'])
|
||||||
track = parseEssentialTrackData(track, trackNew)
|
track = parseEssentialTrackData(track, trackNew)
|
||||||
track['searched'] = True
|
return 2
|
||||||
return downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=track,
|
elif not 'searched' in track and settings['fallbackSearch']:
|
||||||
interface=interface)
|
logger.warn(f"[{track['mainArtist']['name']} - {track['title']}] Track not available, searching for alternative")
|
||||||
|
searchedId = dz.get_track_from_metadata(track['mainArtist']['name'], track['title'],
|
||||||
|
track['album']['title'])
|
||||||
|
if searchedId != 0:
|
||||||
|
trackNew = dz.get_track_gw(searchedId)
|
||||||
|
if not 'MD5_ORIGIN' in trackNew:
|
||||||
|
trackNew['MD5_ORIGIN'] = dz.get_track_md5(trackNew['SNG_ID'])
|
||||||
|
track = parseEssentialTrackData(track, trackNew)
|
||||||
|
track['searched'] = True
|
||||||
|
return 2
|
||||||
|
else:
|
||||||
|
logger.error(f"[{track['mainArtist']['name']} - {track['title']}] Track not available on deezer's servers and no alternative found!")
|
||||||
|
trackCompletePercentage(trackAPI, queueItem, interface)
|
||||||
|
result['error'] = {
|
||||||
|
'message': "Track not available on deezer's servers and no alternative found!",
|
||||||
|
'data': {
|
||||||
|
'id': track['id'],
|
||||||
|
'title': track['title'],
|
||||||
|
'artist': track['mainArtist']['name']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
queueItem['failed'] += 1
|
||||||
|
queueItem['errors'].append(result['error'])
|
||||||
|
if interface:
|
||||||
|
interface.send("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': result['error']['data'],
|
||||||
|
'error': "Track not available on deezer's servers and no alternative found!"})
|
||||||
|
return 1
|
||||||
else:
|
else:
|
||||||
logger.error(f"[{track['mainArtist']['name']} - {track['title']}] Track not available on deezer's servers and no alternative found!")
|
logger.error(f"[{track['mainArtist']['name']} - {track['title']}] Track not available on deezer's servers!")
|
||||||
trackCompletePercentage(trackAPI, queueItem, interface)
|
trackCompletePercentage(trackAPI, queueItem, interface)
|
||||||
result['error'] = {
|
result['error'] = {
|
||||||
'message': "Track not available on deezer's servers and no alternative found!",
|
'message': "Track not available on deezer's servers!",
|
||||||
'data': {
|
'data': {
|
||||||
'id': track['id'],
|
'id': track['id'],
|
||||||
'title': track['title'],
|
'title': track['title'],
|
||||||
|
@ -779,25 +796,18 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
|
||||||
queueItem['errors'].append(result['error'])
|
queueItem['errors'].append(result['error'])
|
||||||
if interface:
|
if interface:
|
||||||
interface.send("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': result['error']['data'],
|
interface.send("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': result['error']['data'],
|
||||||
'error': "Track not available on deezer's servers and no alternative found!"})
|
'error': "Track not available on deezer's servers!"})
|
||||||
return result
|
return 1
|
||||||
else:
|
except:
|
||||||
logger.error(f"[{track['mainArtist']['name']} - {track['title']}] Track not available on deezer's servers!")
|
logger.warn(f"[{track['mainArtist']['name']} - {track['title']}] Error while downloading the track, trying again in 5s...")
|
||||||
trackCompletePercentage(trackAPI, queueItem, interface)
|
sleep(5)
|
||||||
result['error'] = {
|
return downloadMusic(dz, track, trackAPI, queueItem, interface, writepath, result, settings)
|
||||||
'message': "Track not available on deezer's servers!",
|
return 0
|
||||||
'data': {
|
outcome = downloadMusic(dz, track, trackAPI, queueItem, interface, writepath, result, settings)
|
||||||
'id': track['id'],
|
if outcome == 1:
|
||||||
'title': track['title'],
|
return result
|
||||||
'artist': track['mainArtist']['name']
|
elif outcome == 2:
|
||||||
}
|
return downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=track, interface=interface)
|
||||||
}
|
|
||||||
queueItem['failed'] += 1
|
|
||||||
queueItem['errors'].append(result['error'])
|
|
||||||
if interface:
|
|
||||||
interface.send("updateQueue", {'uuid': queueItem['uuid'], 'failed': True, 'data': result['error']['data'],
|
|
||||||
'error': "Track not available on deezer's servers!"})
|
|
||||||
return result
|
|
||||||
else:
|
else:
|
||||||
logger.info(f"[{track['mainArtist']['name']} - {track['title']}] Skipping track as it's already downloaded")
|
logger.info(f"[{track['mainArtist']['name']} - {track['title']}] Skipping track as it's already downloaded")
|
||||||
trackCompletePercentage(trackAPI, queueItem, interface)
|
trackCompletePercentage(trackAPI, queueItem, interface)
|
||||||
|
|
Loading…
Reference in New Issue