@@ -14,6 +14,7 @@ import com.github.libretube.ui.dialogs.ShareDialog.Companion.YOUTUBE_FRONTEND_UR
14
14
import org.schabi.newpipe.extractor.channel.ChannelInfo
15
15
import org.schabi.newpipe.extractor.channel.tabs.ChannelTabInfo
16
16
import org.schabi.newpipe.extractor.channel.tabs.ChannelTabs
17
+ import org.schabi.newpipe.extractor.feed.FeedInfo
17
18
import org.schabi.newpipe.extractor.stream.StreamInfoItem
18
19
import java.time.Duration
19
20
import java.time.Instant
@@ -41,9 +42,9 @@ class LocalFeedRepository : FeedRepository {
41
42
val oneDayAgo = nowMillis - Duration .ofDays(1 ).toMillis()
42
43
43
44
// only refresh if feed is empty or last refresh was more than a day ago
44
- val lastRefresh =
45
+ val lastRefreshMillis =
45
46
PreferenceHelper .getLong(PreferenceKeys .LAST_FEED_REFRESH_TIMESTAMP_MILLIS , 0 )
46
- if (feed.isNotEmpty() && lastRefresh > oneDayAgo) {
47
+ if (feed.isNotEmpty() && lastRefreshMillis > oneDayAgo) {
47
48
return DatabaseHolder .Database .feedDao().getAll()
48
49
.map(SubscriptionsFeedItem ::toStreamItem)
49
50
}
@@ -60,20 +61,29 @@ class LocalFeedRepository : FeedRepository {
60
61
for (channelIdChunk in channelIds.chunked(CHUNK_SIZE )) {
61
62
val collectedFeedItems = channelIdChunk.parallelMap { channelId ->
62
63
try {
63
- getRelatedStreams(channelId)
64
+ getRelatedStreams(channelId, minimumDateMillis )
64
65
} catch (e: Exception ) {
65
66
Log .e(channelId, e.stackTraceToString())
66
67
null
67
68
}
68
69
}.filterNotNull().flatten().map(StreamItem ::toFeedItem)
69
- .filter { it.uploaded > minimumDateMillis }
70
70
71
71
DatabaseHolder .Database .feedDao().insertAll(collectedFeedItems)
72
72
}
73
73
}
74
74
75
- private suspend fun getRelatedStreams (channelId : String ): List <StreamItem > {
76
- val channelInfo = ChannelInfo .getInfo(" $YOUTUBE_FRONTEND_URL /channel/${channelId} " )
75
+ private suspend fun getRelatedStreams (channelId : String , minimumDateMillis : Long ): List <StreamItem > {
76
+ val channelUrl = " $YOUTUBE_FRONTEND_URL /channel/${channelId} "
77
+ val feedInfo = FeedInfo .getInfo(channelUrl)
78
+
79
+ val hasNewerUploads = feedInfo.relatedItems.any {
80
+ (it.uploadDate?.offsetDateTime()?.toInstant()?.toEpochMilli()
81
+ ? : 0 ) > minimumDateMillis
82
+ }
83
+ if (! hasNewerUploads) return emptyList()
84
+
85
+ val channelInfo = ChannelInfo .getInfo(channelUrl)
86
+
77
87
val relevantInfoTabs = channelInfo.tabs.filter { tab ->
78
88
relevantTabs.any { tab.contentFilters.contains(it) }
79
89
}
@@ -102,7 +112,7 @@ class LocalFeedRepository : FeedRepository {
102
112
shortDescription = item.shortDescription,
103
113
isShort = item.isShortFormContent
104
114
)
105
- }
115
+ }.filter { it.uploaded > minimumDateMillis }
106
116
}
107
117
108
118
companion object {
0 commit comments