Skip to content
Snippets Groups Projects
Verified Commit d9468ff0 authored by Eliot Berriot's avatar Eliot Berriot
Browse files

Support for ignoring errors when downloading tracks

parent a8976e5f
No related branches found
No related tags found
No related merge requests found
......@@ -643,6 +643,8 @@ def flatten(d, parent_key="", sep="_"):
@click.option("--format", "-f")
@click.option("-d", "--directory", type=click.Path(exists=True))
@click.option("-o", "--overwrite", is_flag=True, default=False)
@click.option("-s", "--skip-existing", is_flag=True, default=False)
@click.option("-i", "--ignore-errors", multiple=True, type=int)
@click.option(
"-t",
"--template",
......@@ -651,7 +653,7 @@ def flatten(d, parent_key="", sep="_"):
)
@click.pass_context
@async_command
async def track_download(ctx, id, format, directory, template, overwrite):
async def track_download(ctx, id, format, directory, template, overwrite, ignore_errors, skip_existing):
async with ctx.obj["remote"]:
progressbar = tqdm.tqdm(id, unit="Files")
for i in progressbar:
......@@ -661,7 +663,14 @@ async def track_download(ctx, id, format, directory, template, overwrite):
logs.logger.info("Downloading from {}".format(download_url))
response = await ctx.obj["remote"].request("get", download_url, timeout=0)
try:
response.raise_for_status()
except aiohttp.ClientResponseError as e:
if response.status in ignore_errors:
logs.logger.warning("Remote answered with {} for url {}, skipping".format(response.status, download_url))
continue
else:
raise click.ClickException("Remote answered with {} for url {}, exiting".format(response.status, download_url))
filename_params = flatten(track_data)
filename_params["album"] = filename_params['album_title']
filename_params["artist"] = filename_params['artist_name']
......@@ -680,7 +689,11 @@ async def track_download(ctx, id, format, directory, template, overwrite):
final_directory = os.path.dirname(full_path)
pathlib.Path(final_directory).mkdir(parents=True, exist_ok=True)
logs.logger.info("Downloading to {}".format(full_path))
if not overwrite and os.path.exists(full_path):
existing = os.path.exists(full_path)
if skip_existing and existing:
logs.logger.info("'{}' already exists on disk, skipping download".format(full_path))
continue
elif not overwrite and existing:
raise click.ClickException(
"'{}' already exists on disk. Relaunch this command with --overwrite if you want to replace it".format(
full_path
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment