iv: use html comments instead of plain text

It now correctly displays emojis hyphens
This commit is contained in:
Toni Förster 2024-04-01 15:08:08 +02:00
parent cf5262a86e
commit f84c6d319a
No known key found for this signature in database
GPG Key ID: 292F3E5086C83FC7

View File

@ -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 }