Exemplo n.º 1
0
        public async Task <bool> Download(Comic comic, bool verbose = false)
        {
            if (verbose)
            {
                Write("Downloading at: ");
                WriteSuccess(comic.LocalFileName !);
                Write("Source: ");
                WriteWarning(comic.ImageLink !);
                WriteLine();
            }

            if (FileHelper.Exists(comic.LocalFileName !))
            {
                if (verbose)
                {
                    WriteInfo($"File {comic.LocalFileName} already exists. Skipping download...");
                }
                return(true);
            }

            try
            {
                var response = await _client.GetAsync(comic.ImageLink);

                if (response is null)
                {
                    throw new Exception("HTTP GET request failed.");
                }
                await FileHelper.SaveFile(comic.LocalFileName !, response);
            }
            catch (Exception e)
            {
                WriteError($"Error downloading {comic.ImageLink}. Skipping...\n{e.Message}\n");
                return(false);
            }
            return(true);
        }