Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,25 +87,31 @@ private fun AudioStream.toPipedStream() = PipedStream(
)

fun StreamInfoItem.toStreamItem(
uploaderAvatarUrl: String? = null
) = StreamItem(
type = TYPE_STREAM,
url = url.toID(),
title = name,
uploaded = uploadDate?.offsetDateTime()?.toEpochSecond()?.times(1000) ?: -1,
uploadedDate = textualUploadDate ?: uploadDate?.offsetDateTime()?.toLocalDateTime()
?.toLocalDate()
?.toString(),
uploaderName = uploaderName,
uploaderUrl = uploaderUrl.toID(),
uploaderAvatar = uploaderAvatarUrl ?: uploaderAvatars.maxByOrNull { it.height }?.url,
thumbnail = thumbnails.maxByOrNull { it.height }?.url,
duration = duration,
views = viewCount,
uploaderVerified = isUploaderVerified,
shortDescription = shortDescription,
isShort = isShortFormContent
)
uploaderAvatarUrl: String? = null,
feedInfo: StreamInfoItem? = null,
): StreamItem {
val uploadDate = uploadDate ?: feedInfo?.uploadDate
val textualUploadDate = textualUploadDate ?: feedInfo?.textualUploadDate

return StreamItem(
type = TYPE_STREAM,
url = url.toID(),
title = name,
uploaded = uploadDate?.offsetDateTime()?.toEpochSecond()?.times(1000) ?: -1,
uploadedDate = textualUploadDate ?: uploadDate?.offsetDateTime()?.toLocalDateTime()
?.toLocalDate()
?.toString(),
uploaderName = uploaderName,
uploaderUrl = uploaderUrl.toID(),
uploaderAvatar = uploaderAvatarUrl ?: uploaderAvatars.maxByOrNull { it.height }?.url,
thumbnail = thumbnails.maxByOrNull { it.height }?.url,
duration = duration,
views = viewCount,
uploaderVerified = isUploaderVerified,
shortDescription = shortDescription,
isShort = isShortFormContent
)
}

fun InfoItem.toContentItem() = when (this) {
is StreamInfoItem -> ContentItem(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class LocalFeedRepository : FeedRepository {
): List<StreamItem> {
val channelUrl = "$YOUTUBE_FRONTEND_URL/channel/${channelId}"
val feedInfo = FeedInfo.getInfo(channelUrl)
val feedInfoItems = feedInfo.relatedItems.associateBy { it.url }

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

val channelAvatar = channelInfo.avatars.maxByOrNull { it.height }?.url
return related.map { item ->
// 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)
}.filter {
// shorts don't have upload dates apparently
it.isShort || it.uploaded > minimumDateMillis
}
item.toStreamItem(
channelAvatar,
// shorts fetched via the shorts tab don't have upload dates so we fall back to the feedInfo
feedInfoItems[item.url]
)
}.filter { it.uploaded > minimumDateMillis }
}

companion object {
Expand Down
Loading