Skip to content

Commit d87f1e7

Browse files
committed
Youtube loader tries to get thumbnail in different resolutions
1 parent df32982 commit d87f1e7

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/ImageWizard.Core/Loaders/Http/HttpLoaderBase.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ public HttpLoaderBase(
5050
/// <summary>
5151
/// GetAsync
5252
/// </summary>
53-
/// <param name="source"></param>
54-
/// <param name="existingCachedData"></param>
55-
/// <returns></returns>
5653
public override async Task<LoaderResult> GetAsync(string source, ICachedData? existingCachedData)
5754
{
5855
Uri? url = await CreateRequestUrl(source);

src/ImageWizard.Core/Loaders/Youtube/YoutubeLoader.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,28 @@ public YouTubeLoader(
2323

2424
protected override Task<Uri?> CreateRequestUrl(string source)
2525
{
26-
return Task.FromResult<Uri?>(new Uri($"https://i.ytimg.com/vi/{source}/maxresdefault.jpg"));
26+
return Task.FromResult<Uri?>(new Uri(source));
27+
}
28+
29+
public override async Task<LoaderResult> GetAsync(string source, ICachedData? existingCachedData)
30+
{
31+
string[] quality = [
32+
"maxresdefault.jpg", //1920 x 1080
33+
"hq720.jpg", //1280 x 720
34+
"sddefault.jpg", //640 x 480
35+
"hqdefault.jpg", //480 x 360
36+
];
37+
38+
for (int i = 0; i < quality.Length; i++)
39+
{
40+
LoaderResult result = await base.GetAsync($"https://i.ytimg.com/vi/{source}/{quality[i]}", existingCachedData);
41+
42+
if (result.State == LoaderResultState.Success)
43+
{
44+
return result;
45+
}
46+
}
47+
48+
return LoaderResult.NotFound();
2749
}
2850
}

0 commit comments

Comments
 (0)