Skip to content

Commit a042657

Browse files
FineFindusBnyro
authored andcommitted
fix(Feed): extract shorts uploadDate from feedInfo
Shorts extracted from the Shorts tab do not have an uploadDate. They are currently saved with their uploadDate set to -1. This results in them to appear at the end of the feed. To fix this, we can use the generic FeedInfo that contains the uploadDate. This also fixes an issue, where old shorts were fetched on every refresh. Ref: libre-tube#7111
1 parent d266f93 commit a042657

2 files changed

Lines changed: 33 additions & 24 deletions

File tree

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

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -87,25 +87,31 @@ private fun AudioStream.toPipedStream() = PipedStream(
8787
)
8888

8989
fun StreamInfoItem.toStreamItem(
90-
uploaderAvatarUrl: String? = null
91-
) = StreamItem(
92-
type = TYPE_STREAM,
93-
url = url.toID(),
94-
title = name,
95-
uploaded = uploadDate?.offsetDateTime()?.toEpochSecond()?.times(1000) ?: -1,
96-
uploadedDate = textualUploadDate ?: uploadDate?.offsetDateTime()?.toLocalDateTime()
97-
?.toLocalDate()
98-
?.toString(),
99-
uploaderName = uploaderName,
100-
uploaderUrl = uploaderUrl.toID(),
101-
uploaderAvatar = uploaderAvatarUrl ?: uploaderAvatars.maxByOrNull { it.height }?.url,
102-
thumbnail = thumbnails.maxByOrNull { it.height }?.url,
103-
duration = duration,
104-
views = viewCount,
105-
uploaderVerified = isUploaderVerified,
106-
shortDescription = shortDescription,
107-
isShort = isShortFormContent
108-
)
90+
uploaderAvatarUrl: String? = null,
91+
feedInfo: StreamInfoItem? = null,
92+
): StreamItem {
93+
val uploadDate = uploadDate ?: feedInfo?.uploadDate
94+
val textualUploadDate = textualUploadDate ?: feedInfo?.textualUploadDate
95+
96+
return StreamItem(
97+
type = TYPE_STREAM,
98+
url = url.toID(),
99+
title = name,
100+
uploaded = uploadDate?.offsetDateTime()?.toEpochSecond()?.times(1000) ?: -1,
101+
uploadedDate = textualUploadDate ?: uploadDate?.offsetDateTime()?.toLocalDateTime()
102+
?.toLocalDate()
103+
?.toString(),
104+
uploaderName = uploaderName,
105+
uploaderUrl = uploaderUrl.toID(),
106+
uploaderAvatar = uploaderAvatarUrl ?: uploaderAvatars.maxByOrNull { it.height }?.url,
107+
thumbnail = thumbnails.maxByOrNull { it.height }?.url,
108+
duration = duration,
109+
views = viewCount,
110+
uploaderVerified = isUploaderVerified,
111+
shortDescription = shortDescription,
112+
isShort = isShortFormContent
113+
)
114+
}
109115

110116
fun InfoItem.toContentItem() = when (this) {
111117
is StreamInfoItem -> ContentItem(

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ class LocalFeedRepository : FeedRepository {
120120
): List<StreamItem> {
121121
val channelUrl = "$YOUTUBE_FRONTEND_URL/channel/${channelId}"
122122
val feedInfo = FeedInfo.getInfo(channelUrl)
123+
val feedInfoItems = feedInfo.relatedItems.associateBy { it.url }
123124

124125
val mostRecentChannelVideo = feedInfo.relatedItems.maxBy {
125126
it.uploadDate?.offsetDateTime()?.toInstant()?.toEpochMilli() ?: 0
@@ -146,13 +147,15 @@ class LocalFeedRepository : FeedRepository {
146147
}.getOrElse { emptyList() }
147148
}.flatten().filterIsInstance<StreamInfoItem>()
148149

150+
val channelAvatar = channelInfo.avatars.maxByOrNull { it.height }?.url
149151
return related.map { item ->
150152
// avatar is not always included in these info items, thus must be taken from channel info response
151-
item.toStreamItem(channelInfo.avatars.maxByOrNull { it.height }?.url)
152-
}.filter {
153-
// shorts don't have upload dates apparently
154-
it.isShort || it.uploaded > minimumDateMillis
155-
}
153+
item.toStreamItem(
154+
channelAvatar,
155+
// shorts fetched via the shorts tab don't have upload dates so we fall back to the feedInfo
156+
feedInfoItems[item.url]
157+
)
158+
}.filter { it.uploaded > minimumDateMillis }
156159
}
157160

158161
companion object {

0 commit comments

Comments
 (0)