mirror of
https://github.com/yattee/yattee.git
synced 2024-12-22 21:43:41 +00:00
Merge pull request #632 from stonerl/invidious-html-comments
iv: use html comments instead of plain text
This commit is contained in:
commit
96a2119a05
@ -123,7 +123,7 @@ final class InvidiousAPI: Service, ObservableObject, VideosAPI {
|
|||||||
content.json.dictionaryValue["videos"]?.arrayValue.map(self.extractVideo) ?? []
|
content.json.dictionaryValue["videos"]?.arrayValue.map(self.extractVideo) ?? []
|
||||||
}
|
}
|
||||||
|
|
||||||
["latest", "playlists", "streams", "shorts", "channels", "videos", "releases", "podcasts"].forEach { type in
|
for type in ["latest", "playlists", "streams", "shorts", "channels", "videos", "releases", "podcasts"] {
|
||||||
configureTransformer(pathPattern("channels/*/\(type)"), requestMethods: [.get]) { (content: Entity<JSON>) -> ChannelPage in
|
configureTransformer(pathPattern("channels/*/\(type)"), requestMethods: [.get]) { (content: Entity<JSON>) -> ChannelPage in
|
||||||
self.extractChannelPage(from: content.json)
|
self.extractChannelPage(from: content.json)
|
||||||
}
|
}
|
||||||
@ -691,6 +691,8 @@ final class InvidiousAPI: Service, ObservableObject, VideosAPI {
|
|||||||
let author = details["author"]?.string ?? ""
|
let author = details["author"]?.string ?? ""
|
||||||
let channelId = details["authorId"]?.string ?? UUID().uuidString
|
let channelId = details["authorId"]?.string ?? UUID().uuidString
|
||||||
let authorAvatarURL = details["authorThumbnails"]?.arrayValue.last?.dictionaryValue["url"]?.string ?? ""
|
let authorAvatarURL = details["authorThumbnails"]?.arrayValue.last?.dictionaryValue["url"]?.string ?? ""
|
||||||
|
let htmlContent = details["contentHtml"]?.string ?? ""
|
||||||
|
let decodedContent = decodeHtml(htmlContent)
|
||||||
return Comment(
|
return Comment(
|
||||||
id: UUID().uuidString,
|
id: UUID().uuidString,
|
||||||
author: author,
|
author: author,
|
||||||
@ -699,12 +701,25 @@ final class InvidiousAPI: Service, ObservableObject, VideosAPI {
|
|||||||
pinned: false,
|
pinned: false,
|
||||||
hearted: false,
|
hearted: false,
|
||||||
likeCount: details["likeCount"]?.int ?? 0,
|
likeCount: details["likeCount"]?.int ?? 0,
|
||||||
text: details["content"]?.string ?? "",
|
text: decodedContent,
|
||||||
repliesPage: details["replies"]?.dictionaryValue["continuation"]?.string,
|
repliesPage: details["replies"]?.dictionaryValue["continuation"]?.string,
|
||||||
channel: Channel(app: .invidious, id: channelId, name: author)
|
channel: Channel(app: .invidious, id: channelId, name: author)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func decodeHtml(_ htmlEncodedString: String) -> String {
|
||||||
|
if let data = htmlEncodedString.data(using: .utf8) {
|
||||||
|
let options: [NSAttributedString.DocumentReadingOptionKey: Any] = [
|
||||||
|
.documentType: NSAttributedString.DocumentType.html,
|
||||||
|
.characterEncoding: String.Encoding.utf8.rawValue
|
||||||
|
]
|
||||||
|
if let attributedString = try? NSAttributedString(data: data, options: options, documentAttributes: nil) {
|
||||||
|
return attributedString.string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return htmlEncodedString
|
||||||
|
}
|
||||||
|
|
||||||
private func extractCaptions(from content: JSON) -> [Captions] {
|
private func extractCaptions(from content: JSON) -> [Captions] {
|
||||||
content["captions"].arrayValue.compactMap { details in
|
content["captions"].arrayValue.compactMap { details in
|
||||||
guard let url = URL(string: details["url"].stringValue, relativeTo: account.url) else { return nil }
|
guard let url = URL(string: details["url"].stringValue, relativeTo: account.url) else { return nil }
|
||||||
|
Loading…
Reference in New Issue
Block a user