mirror of
https://github.com/yattee/yattee.git
synced 2025-10-15 11:58:14 +00:00
Popular videos, playing from mp4
This commit is contained in:
39
Model/Video.swift
Normal file
39
Model/Video.swift
Normal file
@@ -0,0 +1,39 @@
|
||||
import Alamofire
|
||||
import Foundation
|
||||
import SwiftyJSON
|
||||
|
||||
class Video: Identifiable, ObservableObject {
|
||||
let id: String
|
||||
var title: String
|
||||
var thumbnailURL: URL
|
||||
var author: String
|
||||
|
||||
@Published var url: URL?
|
||||
@Published var error: Bool = false
|
||||
|
||||
init(id: String, title: String, thumbnailURL: URL, author: String) {
|
||||
self.id = id
|
||||
self.title = title
|
||||
self.thumbnailURL = thumbnailURL
|
||||
self.author = author
|
||||
}
|
||||
|
||||
init(_ json: JSON) {
|
||||
id = json["videoId"].stringValue
|
||||
title = json["title"].stringValue
|
||||
thumbnailURL = json["videoThumbnails"][0]["url"].url!
|
||||
author = json["author"].stringValue
|
||||
url = formatStreamURL(from: json["formatStreams"].arrayValue)
|
||||
}
|
||||
|
||||
func formatStreamURL(from streams: [JSON]) -> URL? {
|
||||
if streams.isEmpty {
|
||||
error = true
|
||||
return nil
|
||||
}
|
||||
|
||||
let stream = streams.last!
|
||||
|
||||
return stream["url"].url
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user