我已经开始开发一个应用程序,它只记得一个 youtube chanel 及其播放列表。该频道有大量的播放列表,但我希望该应用程序只调用其中的几个播放列表我将如何做到这一点。目前,该应用程序将从频道加载所有播放列表。这是来自我的应用程序的 PlaylistRepository 的代码。
suspend fun getPlaylists(pageToken: String? = null) = withContext(Dispatchers.IO) {
val playlists= youtubeService
.playlists()
.list("contentDetails,id,localizations,player,snippet,status")
.setChannelId(YOUTUBE_CHANNEL_ID)
.setPageToken(pageToken)
.execute()
PlaylistPage(
playlists.items?.map { playlist ->
com.WVBS.android.worldVideoBibleSchool.model.Playlist(
playlist.id,
playlist.snippet.title
)
} ?: listOf(),
playlists.nextPageToken
)
}
suspend fun getItems(playlist: com.WVBS.android.worldVideoBibleSchool.model.Playlist) =
withContext(Dispatchers.IO) {
val playlistResponse = youtubeService.playlistItems()
.list("contentDetails,id,snippet,status")
.setPlaylistId(playlist.id)
.execute()
ArrayList(playlistResponse.items.mapNotNull { item ->
val videos = youtubeService.videos()
.list("contentDetails,id,liveStreamingDetails,localizations,player," +
"recordingDetails,snippet,statistics,status,topicDetails")
.setId(item.contentDetails.videoId)
.execute()
videos.items.firstOrNull()?.let { video ->
Video(
item.contentDetails.videoId,
video.snippet.title,
video.snippet.description,
video.snippet.thumbnails.high.url,
video.snippet.thumbnails.high.url,
video.snippet.channelTitle
)
}
})
}