Skip to content

Instantly share code, notes, and snippets.

@sturdysturge
Created February 17, 2023 06:41
Show Gist options
  • Select an option

  • Save sturdysturge/b11408c12db2ba34f8ed9a714ffaba31 to your computer and use it in GitHub Desktop.

Select an option

Save sturdysturge/b11408c12db2ba34f8ed9a714ffaba31 to your computer and use it in GitHub Desktop.
import Foundation
struct YTResponse: Codable {
let items: [Item]?
}
struct Item: Codable, Identifiable {
let fullID: ID?
let snippet: Snippet?
var id: String { fullID?.videoID ?? "" }
var defaultThumbnailURL: URL? {
URL(string: snippet?.thumbnails?.thumbnailsDefault?.url ?? "")
}
enum CodingKeys: String, CodingKey {
case snippet, fullID = "id"
}
}
struct ID: Codable {
let videoID: String?
enum CodingKeys: String, CodingKey {
case videoID = "videoId"
}
}
struct Snippet: Codable {
let title, description: String?
let thumbnails: Thumbnails?
}
struct Thumbnails: Codable {
let thumbnailsDefault, medium, high: Default?
enum CodingKeys: String, CodingKey {
case thumbnailsDefault = "default"
case medium, high
}
}
struct Default: Codable {
let url: String?
let width, height: Int?
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment