mirror of
https://github.com/yattee/yattee.git
synced 2024-12-14 22:30:32 +05:30
Improve Invidious thumbnails URL handling
This commit is contained in:
parent
722c879211
commit
0a797db129
@ -410,11 +410,12 @@ final class InvidiousAPI: Service, ObservableObject, VideosAPI {
|
|||||||
func extractChannel(from json: JSON) -> Channel {
|
func extractChannel(from json: JSON) -> Channel {
|
||||||
var thumbnailURL = json["authorThumbnails"].arrayValue.last?.dictionaryValue["url"]?.stringValue ?? ""
|
var thumbnailURL = json["authorThumbnails"].arrayValue.last?.dictionaryValue["url"]?.stringValue ?? ""
|
||||||
|
|
||||||
// append https protocol to unproxied thumbnail URL if it's missing
|
// append protocol to unproxied thumbnail URL if it's missing
|
||||||
if thumbnailURL.count > 2,
|
if thumbnailURL.count > 2,
|
||||||
String(thumbnailURL[..<thumbnailURL.index(thumbnailURL.startIndex, offsetBy: 2)]) == "//"
|
String(thumbnailURL[..<thumbnailURL.index(thumbnailURL.startIndex, offsetBy: 2)]) == "//",
|
||||||
|
let accountUrlComponents = URLComponents(string: account.url)
|
||||||
{
|
{
|
||||||
thumbnailURL = "https:\(thumbnailURL)"
|
thumbnailURL = "\(accountUrlComponents.scheme ?? "https"):\(thumbnailURL)"
|
||||||
}
|
}
|
||||||
|
|
||||||
return Channel(
|
return Channel(
|
||||||
@ -442,14 +443,15 @@ final class InvidiousAPI: Service, ObservableObject, VideosAPI {
|
|||||||
details["videoThumbnails"].arrayValue.compactMap { json in
|
details["videoThumbnails"].arrayValue.compactMap { json in
|
||||||
guard let url = json["url"].url,
|
guard let url = json["url"].url,
|
||||||
var components = URLComponents(url: url, resolvingAgainstBaseURL: false),
|
var components = URLComponents(url: url, resolvingAgainstBaseURL: false),
|
||||||
let quality = json["quality"].string
|
let quality = json["quality"].string,
|
||||||
|
let accountUrlComponents = URLComponents(string: account.url)
|
||||||
else {
|
else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// some of instances are not configured properly and return http thumbnails links
|
// some of instances are not configured properly and return thumbnails links
|
||||||
// http connections are not allowed in the app so we can safely convert it to https
|
// with incorrect scheme
|
||||||
components.scheme = "https"
|
components.scheme = accountUrlComponents.scheme
|
||||||
|
|
||||||
guard let thumbnailUrl = components.url else {
|
guard let thumbnailUrl = components.url else {
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user