diff --git a/app/src/main/java/com/zionhuang/music/viewmodels/HomeViewModel.kt b/app/src/main/java/com/zionhuang/music/viewmodels/HomeViewModel.kt index a5f6e06fe..28f526621 100644 --- a/app/src/main/java/com/zionhuang/music/viewmodels/HomeViewModel.kt +++ b/app/src/main/java/com/zionhuang/music/viewmodels/HomeViewModel.kt @@ -195,6 +195,25 @@ class HomeViewModel @Inject constructor( } init { + viewModelScope.launch(Dispatchers.IO) { + val mostPlayedArtists = database.mostPlayedArtists(System.currentTimeMillis() - 86400000 * 7 * 2) + viewModelScope.launch { + mostPlayedArtists.collect { artists -> + artists + .map { it.artist } + .filter { + it.thumbnailUrl == null + } + .forEach { artist -> + YouTube.artist(artist.id).onSuccess { artistPage -> + database.query { + update(artist, artistPage) + } + } + } + } + } + } viewModelScope.launch(Dispatchers.IO) { isRefreshing.value = true load()