Use video preview if available
This commit is contained in:
parent
00cb83559c
commit
6c698c5b94
|
@ -73,10 +73,11 @@ struct RedditLinkData: Codable {
|
||||||
return mediaEmbedContent
|
return mediaEmbedContent
|
||||||
}
|
}
|
||||||
|
|
||||||
if isVideo ?? false {
|
if url.hasSuffix(".gif") {
|
||||||
guard let fallbackURL = media?.video?.fallbackURL else {
|
return "<figure><img src=\"\(url)\"></figure>"
|
||||||
return nil
|
}
|
||||||
}
|
|
||||||
|
if isVideo ?? false, let videoURL = media?.video?.fallbackURL {
|
||||||
var html = "<video "
|
var html = "<video "
|
||||||
if let previewImageURL = preview?.images?.first?.source?.url {
|
if let previewImageURL = preview?.images?.first?.source?.url {
|
||||||
html += "poster=\"\(previewImageURL)\" "
|
html += "poster=\"\(previewImageURL)\" "
|
||||||
|
@ -84,7 +85,19 @@ struct RedditLinkData: Codable {
|
||||||
if let width = media?.video?.width, let height = media?.video?.height {
|
if let width = media?.video?.width, let height = media?.video?.height {
|
||||||
html += "width=\"\(width)\" height=\"\(height)\" "
|
html += "width=\"\(width)\" height=\"\(height)\" "
|
||||||
}
|
}
|
||||||
html += "src=\"\(fallbackURL)\"></video>"
|
html += "src=\"\(videoURL)\"></video>"
|
||||||
|
return html
|
||||||
|
}
|
||||||
|
|
||||||
|
if let videoPreviewURL = preview?.videoPreview?.url {
|
||||||
|
var html = "<video "
|
||||||
|
if let previewImageURL = preview?.images?.first?.source?.url {
|
||||||
|
html += "poster=\"\(previewImageURL)\" "
|
||||||
|
}
|
||||||
|
if let width = preview?.videoPreview?.width, let height = preview?.videoPreview?.height {
|
||||||
|
html += "width=\"\(width)\" height=\"\(height)\" "
|
||||||
|
}
|
||||||
|
html += "src=\"\(videoPreviewURL)\"></video>"
|
||||||
return html
|
return html
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,9 +11,11 @@ import Foundation
|
||||||
struct RedditPreview: Codable {
|
struct RedditPreview: Codable {
|
||||||
|
|
||||||
let images: [RedditPreviewImage]?
|
let images: [RedditPreviewImage]?
|
||||||
|
let videoPreview: RedditVideoPreview?
|
||||||
|
|
||||||
enum CodingKeys: String, CodingKey {
|
enum CodingKeys: String, CodingKey {
|
||||||
case images = "images"
|
case images = "images"
|
||||||
|
case videoPreview = "reddit_video_preview"
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -41,3 +43,17 @@ struct RedditPreviewImageSource: Codable {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct RedditVideoPreview: Codable {
|
||||||
|
|
||||||
|
let url: String?
|
||||||
|
let width: Int?
|
||||||
|
let height: Int?
|
||||||
|
|
||||||
|
enum CodingKeys: String, CodingKey {
|
||||||
|
case url = "fallback_url"
|
||||||
|
case width = "width"
|
||||||
|
case height = "height"
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue