From 0ffb9d0606b80e8d8537df83570ca7b64c394ce7 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Sun, 15 Oct 2023 14:08:38 +0200 Subject: [PATCH] Fix date parsing for piped videos --- Model/Applications/PipedAPI.swift | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Model/Applications/PipedAPI.swift b/Model/Applications/PipedAPI.swift index 6b27ff5f..41bb180a 100644 --- a/Model/Applications/PipedAPI.swift +++ b/Model/Applications/PipedAPI.swift @@ -496,7 +496,17 @@ final class PipedAPI: Service, ObservableObject, VideosAPI { let uploaded = details["uploaded"]?.double var published = (uploaded.isNil || uploaded == -1) ? nil : (uploaded! / 1000).formattedAsRelativeTime() - if published.isNil { + var publishedAt: Date? + + let dateFormatter = ISO8601DateFormatter() + dateFormatter.formatOptions = [.withInternetDateTime] + + if published.isNil, + let date = details["uploadDate"]?.string, + let formattedDate = dateFormatter.date(from: date) + { + publishedAt = formattedDate + } else { published = (details["uploadedDate"] ?? details["uploadDate"])?.string ?? "" } @@ -526,6 +536,7 @@ final class PipedAPI: Service, ObservableObject, VideosAPI { thumbnails: thumbnails, live: live, short: details["isShort"]?.bool ?? (length <= Video.shortLength), + publishedAt: publishedAt, likes: details["likes"]?.int, dislikes: details["dislikes"]?.int, streams: extractStreams(from: content),