From 4362456995a3e528ee9eb390614db89d99001494 Mon Sep 17 00:00:00 2001 From: vfsfitvnm Date: Sat, 24 Sep 2022 13:12:54 +0200 Subject: [PATCH] Retrieve YouTube artists subscribers count --- .../vimusic/ui/views/YouTubeItems.kt | 44 ++++++++++++++----- .../it/vfsfitvnm/youtubemusic/YouTube.kt | 7 ++- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/app/src/main/kotlin/it/vfsfitvnm/vimusic/ui/views/YouTubeItems.kt b/app/src/main/kotlin/it/vfsfitvnm/vimusic/ui/views/YouTubeItems.kt index fa59313..467eb79 100644 --- a/app/src/main/kotlin/it/vfsfitvnm/vimusic/ui/views/YouTubeItems.kt +++ b/app/src/main/kotlin/it/vfsfitvnm/vimusic/ui/views/YouTubeItems.kt @@ -164,12 +164,16 @@ fun VideoItem( overflow = TextOverflow.Ellipsis, ) - BasicText( - text = video.views.firstOrNull()?.name ?: "", - style = typography.xxs.medium.secondary, - maxLines = 1, - overflow = TextOverflow.Ellipsis, - ) + video.views.firstOrNull()?.name?.let { viewsText -> + BasicText( + text = viewsText, + style = typography.xxs.medium.secondary, + maxLines = 1, + overflow = TextOverflow.Ellipsis, + modifier = Modifier + .padding(top = 8.dp) + ) + } } } } @@ -200,7 +204,10 @@ fun VideoItemShimmer( Column { TextPlaceholder() TextPlaceholder() - TextPlaceholder() + TextPlaceholder( + modifier = Modifier + .padding(top = 8.dp) + ) } } } @@ -287,7 +294,6 @@ fun PlaylistItemShimmer( Column(verticalArrangement = Arrangement.spacedBy(4.dp)) { TextPlaceholder() TextPlaceholder() - TextPlaceholder() } } } @@ -369,7 +375,10 @@ fun AlbumItemShimmer( Column(verticalArrangement = Arrangement.spacedBy(4.dp)) { TextPlaceholder() TextPlaceholder() - TextPlaceholder() + TextPlaceholder( + modifier = Modifier + .padding(top = 8.dp) + ) } } } @@ -405,6 +414,17 @@ fun ArtistItem( maxLines = 2, overflow = TextOverflow.Ellipsis ) + + artist.subscribersCountText?.let { subscribersCountText -> + BasicText( + text = subscribersCountText, + style = typography.xxs.semiBold.secondary, + maxLines = 1, + overflow = TextOverflow.Ellipsis, + modifier = Modifier + .padding(top = 4.dp) + ) + } } } } @@ -430,7 +450,11 @@ fun ArtistItemShimmer( ) Column(verticalArrangement = Arrangement.spacedBy(4.dp)) { - TextPlaceholder() + TextPlaceholder() + TextPlaceholder( + modifier = Modifier + .padding(top = 4.dp) + ) } } } diff --git a/youtube-music/src/main/kotlin/it/vfsfitvnm/youtubemusic/YouTube.kt b/youtube-music/src/main/kotlin/it/vfsfitvnm/youtubemusic/YouTube.kt index 5407590..7eec479 100644 --- a/youtube-music/src/main/kotlin/it/vfsfitvnm/youtubemusic/YouTube.kt +++ b/youtube-music/src/main/kotlin/it/vfsfitvnm/youtubemusic/YouTube.kt @@ -320,6 +320,7 @@ object YouTube { data class Artist( val info: Info, + val subscribersCountText: String?, override val thumbnail: ThumbnailRenderer.MusicThumbnailRenderer.Thumbnail.Thumbnail? ) : Item() { override val key: String? @@ -329,7 +330,7 @@ object YouTube { val Filter = Filter("EgWKAQIgAWoKEAkQChAFEAMQBA%3D%3D") override fun from(content: MusicShelfRenderer.Content): Artist { - val (mainRuns) = content.runs + val (mainRuns, otherRuns) = content.runs return Artist( info = Info( @@ -341,6 +342,10 @@ object YouTube { .navigationEndpoint ?.browseEndpoint ), + subscribersCountText = otherRuns + .lastOrNull() + ?.last() + ?.text, thumbnail = content .thumbnail )