1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 05:40:32 +05:30
yattee/Fixtures/Thumbnail+Fixtures.swift

37 lines
1.1 KiB
Swift
Raw Normal View History

2021-07-22 18:13:13 +05:30
import Foundation
extension Thumbnail {
static func fixture(videoId: String, quality: Thumbnail.Quality = .maxres) -> Thumbnail {
Thumbnail(url: fixtureUrl(videoId: videoId, quality: quality), quality: quality)
}
static func fixturesForAllQualities(videoId: String) -> [Thumbnail] {
Thumbnail.Quality.allCases.map { fixture(videoId: videoId, quality: $0) }
}
private static var fixturesHost: String {
"https://invidious.home.arekf.net"
}
private static func fixtureUrl(videoId: String, quality: Thumbnail.Quality) -> URL {
URL(string: "\(fixturesHost)/vi/\(videoId)/\(filenameForQuality(quality)).jpg")!
}
private static func filenameForQuality(_ quality: Thumbnail.Quality) -> String {
switch quality {
case .high:
return "hqdefault"
case .medium:
return "mqdefault"
case .start:
return "1"
case .middle:
return "2"
case .end:
return "3"
default:
return quality.rawValue
}
}
}