Skip to content

Commit 470c3bb

Browse files
authored
Merge pull request libre-tube#7111 from Bnyro/master
fix: no shorts in locally generated subscriptions feed
2 parents 301f80f + 77b6c08 commit 470c3bb

5 files changed

Lines changed: 23 additions & 9 deletions

File tree

app/src/main/java/com/github/libretube/api/StreamsExtractor.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import com.github.libretube.api.obj.PreviewFrames
1010
import com.github.libretube.api.obj.StreamItem
1111
import com.github.libretube.api.obj.Streams
1212
import com.github.libretube.api.obj.Subtitle
13+
import com.github.libretube.extensions.toID
1314
import com.github.libretube.helpers.PlayerHelper
1415
import com.github.libretube.ui.dialogs.ShareDialog.Companion.YOUTUBE_FRONTEND_URL
1516
import kotlinx.datetime.toKotlinInstant
@@ -40,13 +41,13 @@ fun StreamInfoItem.toStreamItem(
4041
uploaderAvatarUrl: String? = null
4142
): StreamItem = StreamItem(
4243
type = StreamItem.TYPE_STREAM,
43-
url = url.replace(YOUTUBE_FRONTEND_URL, ""),
44+
url = url.toID(),
4445
title = name,
45-
uploaded = uploadDate?.offsetDateTime()?.toEpochSecond()?.times(1000) ?: 0,
46+
uploaded = uploadDate?.offsetDateTime()?.toEpochSecond()?.times(1000) ?: -1,
4647
uploadedDate = textualUploadDate ?: uploadDate?.offsetDateTime()?.toLocalDateTime()?.toLocalDate()
4748
?.toString(),
4849
uploaderName = uploaderName,
49-
uploaderUrl = uploaderUrl.replace(YOUTUBE_FRONTEND_URL, ""),
50+
uploaderUrl = uploaderUrl.toID(),
5051
uploaderAvatar = uploaderAvatarUrl ?: uploaderAvatars.maxByOrNull { it.height }?.url,
5152
thumbnail = thumbnails.maxByOrNull { it.height }?.url,
5253
duration = duration,
@@ -68,7 +69,7 @@ object StreamsExtractor {
6869
description = resp.description.content,
6970
uploader = resp.uploaderName,
7071
uploaderAvatar = resp.uploaderAvatars.maxBy { it.height }.url,
71-
uploaderUrl = resp.uploaderUrl.replace(YOUTUBE_FRONTEND_URL, ""),
72+
uploaderUrl = resp.uploaderUrl.toID(),
7273
uploaderVerified = resp.isUploaderVerified,
7374
uploaderSubscriberCount = resp.uploaderSubscriberCount,
7475
category = resp.category,

app/src/main/java/com/github/libretube/api/obj/StreamItem.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ data class StreamItem(
2828
val shortDescription: String? = null,
2929
val isShort: Boolean = false
3030
) : Parcelable {
31-
val isLive get() = (duration == null) || (duration <= 0L)
31+
val isLive get() = !isShort && ((duration == null) || (duration <= 0L))
3232
val isUpcoming get() = uploaded > System.currentTimeMillis()
3333

3434
fun toLocalPlaylistItem(playlistId: String): LocalPlaylistItem {

app/src/main/java/com/github/libretube/db/dao/SubscriptionsFeedDao.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ interface SubscriptionsFeedDao {
1717
@Query("SELECT EXISTS (SELECT * FROM feedItem WHERE videoId = :videoId)")
1818
suspend fun contains(videoId: String): Boolean
1919

20-
@Query("DELETE FROM feedItem WHERE uploaded < :olderThan")
20+
@Query("DELETE FROM feedItem WHERE (uploaded < :olderThan AND uploaded != -1)")
2121
suspend fun cleanUpOlderThan(olderThan: Long)
2222

2323
@Query("DELETE FROM feedItem WHERE uploaderUrl NOT IN (:channelUrls)")
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
package com.github.libretube.extensions
22

3+
import com.github.libretube.ui.dialogs.ShareDialog.Companion.YOUTUBE_FRONTEND_URL
4+
35
/**
46
* format a Piped route to an ID
57
*/
68
fun String.toID(): String {
79
return this
10+
.replace(YOUTUBE_FRONTEND_URL, "")
811
.replace("/watch?v=", "") // videos
912
.replace("/channel/", "") // channels
1013
.replace("/playlist?list=", "") // playlists
14+
// channel urls for different categories than the main one
15+
.removeSuffix("/shorts")
16+
.removeSuffix("/streams")
17+
.removeSuffix("/videos")
1118
}

app/src/main/java/com/github/libretube/repo/LocalFeedRepository.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ class LocalFeedRepository : FeedRepository {
3939

4040
val channelIds = SubscriptionHelper.getSubscriptionChannelIds()
4141
// remove videos from channels that are no longer subscribed
42-
DatabaseHolder.Database.feedDao().deleteAllExcept(channelIds.map { id -> "/channel/${id}" })
42+
DatabaseHolder.Database.feedDao().deleteAllExcept(
43+
// TODO: the /channel/ prefix is allowed for compatibility reasons and will be removed in the future
44+
channelIds + channelIds.map { id -> "/channel/${id}" }
45+
)
4346

4447
if (!forceRefresh) {
4548
val feed = DatabaseHolder.Database.feedDao().getAll()
@@ -104,7 +107,7 @@ class LocalFeedRepository : FeedRepository {
104107
mostRecentChannelVideo.uploadDate?.offsetDateTime()?.toInstant()?.toEpochMilli() ?: 0
105108
val hasNewerUploads =
106109
mostRecentUploadTime > minimumDateMillis && !DatabaseHolder.Database.feedDao()
107-
.contains(mostRecentChannelVideo.url.replace(YOUTUBE_FRONTEND_URL, "").toID())
110+
.contains(mostRecentChannelVideo.url.toID())
108111
if (!hasNewerUploads) return emptyList()
109112

110113
val channelInfo = ChannelInfo.getInfo(channelUrl)
@@ -122,7 +125,10 @@ class LocalFeedRepository : FeedRepository {
122125
return related.map { item ->
123126
// avatar is not always included in these info items, thus must be taken from channel info response
124127
item.toStreamItem(channelInfo.avatars.maxByOrNull { it.height }?.url)
125-
}.filter { it.uploaded > minimumDateMillis }
128+
}.filter {
129+
// shorts don't have upload dates apparently
130+
it.isShort || it.uploaded > minimumDateMillis
131+
}
126132
}
127133

128134
companion object {

0 commit comments

Comments
 (0)