Merge pull request #7142 from FineFindus/fix/local-feed-short-videos

fix(Feed): extract shorts uploadDate from feedInfo
This commit is contained in:
Bnyro 2025-03-03 13:39:00 +01:00 committed by GitHub
commit 2c73287d71
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 24 deletions

View File

@ -87,25 +87,31 @@ private fun AudioStream.toPipedStream() = PipedStream(
) )
fun StreamInfoItem.toStreamItem( fun StreamInfoItem.toStreamItem(
uploaderAvatarUrl: String? = null uploaderAvatarUrl: String? = null,
) = StreamItem( feedInfo: StreamInfoItem? = null,
type = TYPE_STREAM, ): StreamItem {
url = url.toID(), val uploadDate = uploadDate ?: feedInfo?.uploadDate
title = name, val textualUploadDate = textualUploadDate ?: feedInfo?.textualUploadDate
uploaded = uploadDate?.offsetDateTime()?.toEpochSecond()?.times(1000) ?: -1,
uploadedDate = textualUploadDate ?: uploadDate?.offsetDateTime()?.toLocalDateTime() return StreamItem(
?.toLocalDate() type = TYPE_STREAM,
?.toString(), url = url.toID(),
uploaderName = uploaderName, title = name,
uploaderUrl = uploaderUrl.toID(), uploaded = uploadDate?.offsetDateTime()?.toEpochSecond()?.times(1000) ?: -1,
uploaderAvatar = uploaderAvatarUrl ?: uploaderAvatars.maxByOrNull { it.height }?.url, uploadedDate = textualUploadDate ?: uploadDate?.offsetDateTime()?.toLocalDateTime()
thumbnail = thumbnails.maxByOrNull { it.height }?.url, ?.toLocalDate()
duration = duration, ?.toString(),
views = viewCount, uploaderName = uploaderName,
uploaderVerified = isUploaderVerified, uploaderUrl = uploaderUrl.toID(),
shortDescription = shortDescription, uploaderAvatar = uploaderAvatarUrl ?: uploaderAvatars.maxByOrNull { it.height }?.url,
isShort = isShortFormContent thumbnail = thumbnails.maxByOrNull { it.height }?.url,
) duration = duration,
views = viewCount,
uploaderVerified = isUploaderVerified,
shortDescription = shortDescription,
isShort = isShortFormContent
)
}
fun InfoItem.toContentItem() = when (this) { fun InfoItem.toContentItem() = when (this) {
is StreamInfoItem -> ContentItem( is StreamInfoItem -> ContentItem(

View File

@ -120,6 +120,7 @@ class LocalFeedRepository : FeedRepository {
): List<StreamItem> { ): List<StreamItem> {
val channelUrl = "$YOUTUBE_FRONTEND_URL/channel/${channelId}" val channelUrl = "$YOUTUBE_FRONTEND_URL/channel/${channelId}"
val feedInfo = FeedInfo.getInfo(channelUrl) val feedInfo = FeedInfo.getInfo(channelUrl)
val feedInfoItems = feedInfo.relatedItems.associateBy { it.url }
val mostRecentChannelVideo = feedInfo.relatedItems.maxBy { val mostRecentChannelVideo = feedInfo.relatedItems.maxBy {
it.uploadDate?.offsetDateTime()?.toInstant()?.toEpochMilli() ?: 0 it.uploadDate?.offsetDateTime()?.toInstant()?.toEpochMilli() ?: 0
@ -146,13 +147,15 @@ class LocalFeedRepository : FeedRepository {
}.getOrElse { emptyList() } }.getOrElse { emptyList() }
}.flatten().filterIsInstance<StreamInfoItem>() }.flatten().filterIsInstance<StreamInfoItem>()
val channelAvatar = channelInfo.avatars.maxByOrNull { it.height }?.url
return related.map { item -> return related.map { item ->
// avatar is not always included in these info items, thus must be taken from channel info response // avatar is not always included in these info items, thus must be taken from channel info response
item.toStreamItem(channelInfo.avatars.maxByOrNull { it.height }?.url) item.toStreamItem(
}.filter { channelAvatar,
// shorts don't have upload dates apparently // shorts fetched via the shorts tab don't have upload dates so we fall back to the feedInfo
it.isShort || it.uploaded > minimumDateMillis feedInfoItems[item.url]
} )
}.filter { it.uploaded > minimumDateMillis }
} }
companion object { companion object {