Skip to content

Commit

Permalink
Allow thumbnail loading to fail without stopping video sync
Browse files Browse the repository at this point in the history
  • Loading branch information
Foxocube committed Jan 6, 2025
1 parent ba7077d commit f73e5ed
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
2 changes: 2 additions & 0 deletions MediaFeeder/MediaFeeder/Data/Enums/Provider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ public enum Provider
YouTube = 1,
Sonarr = 3,
RSS = 4,

// Twitch
}
24 changes: 16 additions & 8 deletions MediaFeeder/MediaFeeder/Providers/Youtube/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,30 @@ internal async Task<string> LoadResourceThumbnail(string itemId, string type, Th

internal async Task<string> LoadUrlThumbnail(string itemId, string type, string url, ILogger logger, CancellationToken cancellationToken)
{
var httpClient = httpClientFactory.CreateClient("retry");
try
{
var httpClient = httpClientFactory.CreateClient("retry");

var request = await httpClient.GetAsync(url, cancellationToken);
request.EnsureSuccessStatusCode();
var request = await httpClient.GetAsync(url, cancellationToken);
request.EnsureSuccessStatusCode();

var ext = new FileExtensionContentTypeProvider().Mappings
.FirstOrDefault(g => g.Value == request.Content.Headers.ContentType?.MediaType)
.Key ?? ".png";
var fileName = $"{itemId}{ext}";

var path = configuration.GetValue<string>("MediaRoot");
path = Path.Join(path, "thumbnails", type, fileName);
var path = configuration.GetValue<string>("MediaRoot");
path = Path.Join(path, "thumbnails", type, fileName);

await using var file = File.OpenWrite(path);
await request.Content.CopyToAsync(file, cancellationToken);
await using var file = File.OpenWrite(path);
await request.Content.CopyToAsync(file, cancellationToken);

return path;
return path;
}
catch (Exception e)
{
logger.LogError(e, "Error while downloading channel thumbnail");
return "";
}
}
}

0 comments on commit f73e5ed

Please sign in to comment.