Skip to content

Commit

Permalink
Youtube loader tries to get thumbnail in different resolutions
Browse files Browse the repository at this point in the history
  • Loading branch information
usercode committed Jul 26, 2024
1 parent df32982 commit d87f1e7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
3 changes: 0 additions & 3 deletions src/ImageWizard.Core/Loaders/Http/HttpLoaderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ public HttpLoaderBase(
/// <summary>
/// GetAsync
/// </summary>
/// <param name="source"></param>
/// <param name="existingCachedData"></param>
/// <returns></returns>
public override async Task<LoaderResult> GetAsync(string source, ICachedData? existingCachedData)
{
Uri? url = await CreateRequestUrl(source);
Expand Down
24 changes: 23 additions & 1 deletion src/ImageWizard.Core/Loaders/Youtube/YoutubeLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,28 @@ public YouTubeLoader(

protected override Task<Uri?> CreateRequestUrl(string source)
{
return Task.FromResult<Uri?>(new Uri($"https://i.ytimg.com/vi/{source}/maxresdefault.jpg"));
return Task.FromResult<Uri?>(new Uri(source));
}

public override async Task<LoaderResult> GetAsync(string source, ICachedData? existingCachedData)
{
string[] quality = [
"maxresdefault.jpg", //1920 x 1080
"hq720.jpg", //1280 x 720
"sddefault.jpg", //640 x 480
"hqdefault.jpg", //480 x 360
];

for (int i = 0; i < quality.Length; i++)
{
LoaderResult result = await base.GetAsync($"https://i.ytimg.com/vi/{source}/{quality[i]}", existingCachedData);

if (result.State == LoaderResultState.Success)
{
return result;
}
}

return LoaderResult.NotFound();
}
}

0 comments on commit d87f1e7

Please sign in to comment.