fix(1): Add error handling and retry after 2 minutes for each video

This commit is contained in:
Josh Creek
2021-09-18 10:15:32 +01:00
parent f908f08010
commit 0f0fc854fc
+29 -5
View File
@@ -39,12 +39,36 @@ namespace YouTubeChannelDownloader
foreach (YouTubeVideo video in newVideos) foreach (YouTubeVideo video in newVideos)
{ {
Console.WriteLine($"Starting {channel.Title} - {video.PlaylistVideo.Title}"); Console.WriteLine($"Starting {channel.Title} - {video.PlaylistVideo.Title}");
string pathString = await DownloadVideoAsync(video, channel.Title); try
await RecordSuccessfulVideoDownload(video, channel.Title); {
string pathString = await DownloadVideoAsync(video, channel.Title);
await RecordSuccessfulVideoDownload(video, channel.Title);
// TODO? - set this up with a discard to run in a separate thread so more downloads can happen, need to be careful of error handling and logging // TODO? - set this up with a discard to run in a separate thread so more downloads can happen, need to be careful of error handling and logging
TransferFileToNasShare(pathString); TransferFileToNasShare(pathString);
DeleteLocalFile(pathString); DeleteLocalFile(pathString);
}
catch (Exception ex)
{
// Wait a few minutes then try again
int minutesToWait = 2;
await Task.Delay(minutesToWait * 60 * 1000);
try
{
string pathString = await DownloadVideoAsync(video, channel.Title);
await RecordSuccessfulVideoDownload(video, channel.Title);
// TODO? - set this up with a discard to run in a separate thread so more downloads can happen, need to be careful of error handling and logging
TransferFileToNasShare(pathString);
DeleteLocalFile(pathString);
}
catch (Exception ex2)
{
// Give up on this video, and log the error
Console.WriteLine($"Unable to process video after retrying due to error: {ex2.Message}");
}
}
} }
} }