Create a short description if there isn't one available.
This commit is contained in:
3 files changed
+18
-4
No files matched your search
@@ -241,9 +241,27 @@ public class MetadataResult : NSObject {
|
||||
dictionary.merge(result.dictionary) { (_, new) in new }
|
||||
}
|
||||
|
||||
private func truncate(string: String, to index: Int) -> String {
|
||||
let words = string.split(separator: " ")
|
||||
var accumulatedCounts = words.map { $0.count + 1 }
|
||||
for index in 1..<accumulatedCounts.count {
|
||||
accumulatedCounts[index] += accumulatedCounts[index - 1]
|
||||
}
|
||||
let endIndex = accumulatedCounts.filter { $0 < index }.endIndex
|
||||
return words[0..<endIndex].joined(separator: " ") + "…"
|
||||
}
|
||||
|
||||
public func mappedMetadata(to map: MetadataResultMap, keepEmptyKeys: Bool) -> MP42Metadata {
|
||||
let metadata = MP42Metadata()
|
||||
|
||||
if dictionary[.description] == nil, let longDesc = dictionary[.longDescription] as? String {
|
||||
if longDesc.count > 254 {
|
||||
dictionary[.description] = truncate(string: longDesc, to: 254)
|
||||
} else {
|
||||
dictionary[.description] = longDesc
|
||||
}
|
||||
}
|
||||
|
||||
metadata.addItems(map.items.compactMap {
|
||||
let value = $0.value.reduce("", {
|
||||
if let key = Key(rawValue: $1.text) {
|
||||
|
||||
@@ -41,7 +41,6 @@ public struct TheMovieDB: MetadataService {
|
||||
metadata[.serviceSeriesID] = result.id
|
||||
metadata[.name] = result.title
|
||||
metadata[.releaseDate] = result.release_date
|
||||
metadata[.description] = result.overview
|
||||
metadata[.longDescription] = result.overview;
|
||||
|
||||
return metadata
|
||||
@@ -131,7 +130,6 @@ public struct TheMovieDB: MetadataService {
|
||||
|
||||
metadata[.name] = result.title
|
||||
metadata[.releaseDate] = result.release_date
|
||||
metadata[.description] = result.overview
|
||||
metadata[.longDescription] = result.overview
|
||||
|
||||
metadata[.genre] = cleanList(items: result.genres)
|
||||
@@ -260,7 +258,6 @@ public struct TheMovieDB: MetadataService {
|
||||
metadata[.serviceEpisodeID] = result.id
|
||||
metadata[.name] = result.name
|
||||
metadata[.releaseDate] = result.air_date
|
||||
metadata[.description] = result.overview
|
||||
metadata[.longDescription] = result.overview;
|
||||
|
||||
metadata[.season] = result.season_number
|
||||
|
||||
@@ -123,7 +123,6 @@ public struct TheTVDB : MetadataService, MetadataNameService {
|
||||
result[.serviceEpisodeID] = episode.id
|
||||
result[.name] = episode.episodeName
|
||||
result[.releaseDate] = episode.firstAired
|
||||
result[.description] = episode.overview
|
||||
result[.longDescription] = episode.overview
|
||||
|
||||
result[.season] = episode.airedSeason
|
||||
|
||||
Reference in new issue
Block a user