mirror of
https://github.com/yattee/yattee.git
synced 2025-08-09 20:24:06 +00:00
Add hiding short videos
This commit is contained in:
@@ -461,6 +461,7 @@ final class InvidiousAPI: Service, ObservableObject, VideosAPI {
|
||||
}
|
||||
|
||||
let description = json["description"].stringValue
|
||||
let length = json["lengthSeconds"].doubleValue
|
||||
|
||||
return Video(
|
||||
instanceID: account.instanceID,
|
||||
@@ -470,7 +471,7 @@ final class InvidiousAPI: Service, ObservableObject, VideosAPI {
|
||||
videoID: videoID,
|
||||
title: json["title"].stringValue,
|
||||
author: json["author"].stringValue,
|
||||
length: json["lengthSeconds"].doubleValue,
|
||||
length: length,
|
||||
published: published,
|
||||
views: json["viewCount"].intValue,
|
||||
description: description,
|
||||
@@ -480,6 +481,7 @@ final class InvidiousAPI: Service, ObservableObject, VideosAPI {
|
||||
indexID: indexID,
|
||||
live: json["liveNow"].boolValue,
|
||||
upcoming: json["isUpcoming"].boolValue,
|
||||
short: length <= Video.shortLength,
|
||||
publishedAt: publishedAt,
|
||||
likes: json["likeCount"].int,
|
||||
dislikes: json["dislikeCount"].int,
|
||||
|
@@ -481,6 +481,8 @@ final class PipedAPI: Service, ObservableObject, VideosAPI {
|
||||
chapters = extractChapters(from: description)
|
||||
}
|
||||
|
||||
let length = details["duration"]?.double ?? 0
|
||||
|
||||
return Video(
|
||||
instanceID: account.instanceID,
|
||||
app: .piped,
|
||||
@@ -488,13 +490,14 @@ final class PipedAPI: Service, ObservableObject, VideosAPI {
|
||||
videoID: extractID(from: content),
|
||||
title: details["title"]?.string ?? "",
|
||||
author: author,
|
||||
length: details["duration"]?.double ?? 0,
|
||||
length: length,
|
||||
published: published ?? "",
|
||||
views: details["views"]?.int ?? 0,
|
||||
description: description,
|
||||
channel: Channel(app: .piped, id: channelId, name: author, thumbnailURL: authorThumbnailURL, subscriptionsCount: subscriptionsCount),
|
||||
thumbnails: thumbnails,
|
||||
live: live,
|
||||
short: details["isShort"]?.bool ?? (length <= Video.shortLength),
|
||||
likes: details["likes"]?.int,
|
||||
dislikes: details["dislikes"]?.int,
|
||||
streams: extractStreams(from: content),
|
||||
|
@@ -1,5 +1,6 @@
|
||||
import Cache
|
||||
import CoreData
|
||||
import Defaults
|
||||
import Foundation
|
||||
import Siesta
|
||||
import SwiftyJSON
|
||||
@@ -237,6 +238,10 @@ final class FeedModel: ObservableObject, CacheModel {
|
||||
let watches = watchFetchRequestResult(videos, context: backgroundContext)
|
||||
let watchesIDs = watches.map(\.videoID)
|
||||
let unwatched = videos.filter { video in
|
||||
if Defaults[.hideShorts], video.short {
|
||||
return false
|
||||
}
|
||||
|
||||
if !watchesIDs.contains(video.videoID) {
|
||||
return true
|
||||
}
|
||||
|
@@ -5,6 +5,8 @@ import SwiftUI
|
||||
import SwiftyJSON
|
||||
|
||||
struct Video: Identifiable, Equatable, Hashable {
|
||||
static let shortLength = 61.0
|
||||
|
||||
enum VideoID {
|
||||
static func isValid(_ id: Video.ID) -> Bool {
|
||||
isYouTube(id) || isPeerTube(id)
|
||||
@@ -40,6 +42,7 @@ struct Video: Identifiable, Equatable, Hashable {
|
||||
|
||||
var live: Bool
|
||||
var upcoming: Bool
|
||||
var short: Bool
|
||||
|
||||
var streams = [Stream]()
|
||||
|
||||
@@ -74,6 +77,7 @@ struct Video: Identifiable, Equatable, Hashable {
|
||||
indexID: String? = nil,
|
||||
live: Bool = false,
|
||||
upcoming: Bool = false,
|
||||
short: Bool = false,
|
||||
publishedAt: Date? = nil,
|
||||
likes: Int? = nil,
|
||||
dislikes: Int? = nil,
|
||||
@@ -101,6 +105,7 @@ struct Video: Identifiable, Equatable, Hashable {
|
||||
self.indexID = indexID
|
||||
self.live = live
|
||||
self.upcoming = upcoming
|
||||
self.short = short
|
||||
self.publishedAt = publishedAt
|
||||
self.likes = likes
|
||||
self.dislikes = dislikes
|
||||
@@ -154,6 +159,7 @@ struct Video: Identifiable, Equatable, Hashable {
|
||||
"indexID": indexID ?? "",
|
||||
"live": live,
|
||||
"upcoming": upcoming,
|
||||
"short": short,
|
||||
"publishedAt": publishedAt
|
||||
]
|
||||
}
|
||||
@@ -180,6 +186,7 @@ struct Video: Identifiable, Equatable, Hashable {
|
||||
indexID: json["indexID"].stringValue,
|
||||
live: json["live"].boolValue,
|
||||
upcoming: json["upcoming"].boolValue,
|
||||
short: json["short"].boolValue,
|
||||
publishedAt: dateFormatter.date(from: json["publishedAt"].stringValue)
|
||||
)
|
||||
}
|
||||
|
Reference in New Issue
Block a user