Skip to content

Commit

Permalink
Added indication of progress
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurenceRawlings committed Feb 2, 2021
1 parent 90a51e2 commit 8386ade
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions savify/savify.py
Expand Up @@ -60,6 +60,8 @@ def __init__(self, api_credentials=None, quality=Quality.BEST, download_format=F
self.ydl_options = ydl_options
self.skip_cover_art = skip_cover_art
self.ffmpeg_location = ffmpeg_location
self.queue_size = 0
self.completed = 0

if api_credentials is None:
if not (check_env()):
Expand Down Expand Up @@ -110,6 +112,7 @@ def _parse_query(self, query, query_type=Type.TRACK, artist_albums: bool = False
def download(self, query, query_type=Type.TRACK, create_m3u=False, artist_albums: bool = False) -> None:
try:
queue = self._parse_query(query, query_type=query_type, artist_albums=artist_albums)
self.queue_size += len(queue)
except requests.exceptions.ConnectionError or URLError:
raise InternetConnectionError

Expand Down Expand Up @@ -159,6 +162,8 @@ def download(self, query, query_type=Type.TRACK, create_m3u=False, artist_albums
f'\n\tReason:\t{failed_job["error"]}\n'

self.logger.info(message)
self.queue_size -= len(queue)
self.completed -= len(queue)

def _download(self, track: Track) -> dict:
extractor = 'ytsearch'
Expand All @@ -185,6 +190,7 @@ def _download(self, track: Track) -> dict:
if check_file(output):
self.logger.info(f'{str(track)} -> is already downloaded. Skipping...')
status['returncode'] = 0
self.completed += 1
return status

create_dir(output.parent)
Expand Down Expand Up @@ -244,6 +250,7 @@ def _download(self, track: Track) -> dict:
status['returncode'] = 1
status['error'] = "Failed to download song."
self.logger.error(ex.message)
self.completed += 1
return status

from shutil import move, Error as ShutilError
Expand All @@ -255,10 +262,12 @@ def _download(self, track: Track) -> dict:
status['returncode'] = 1
status['error'] = 'Filesystem error.'
self.logger.error('Failed to move temp file!')
self.completed += 1
return status

status['returncode'] = 0
self.logger.info(f'Downloaded -> {str(track)}')
self.completed += 1
self.logger.info(f'Downloaded {self.completed} / {self.queue_size} -> {str(track)}')
return status

attempt = 0
Expand Down Expand Up @@ -300,6 +309,7 @@ def _download(self, track: Track) -> dict:
status['returncode'] = 1
status['error'] = 'Filesystem error.'
self.logger.error('Failed to move temp file!')
self.completed += 1
return status

status['returncode'] = 0
Expand All @@ -308,5 +318,6 @@ def _download(self, track: Track) -> dict:
remove(output_temp)
except OSError:
pass
self.logger.info(f'Downloaded -> {str(track)}')
self.completed += 1
self.logger.info(f'Downloaded {self.completed} / {self.queue_size} -> {str(track)}')
return status

0 comments on commit 8386ade

Please sign in to comment.