Skip to content

Commit

Permalink
Fix YT API change on albums
Browse files Browse the repository at this point in the history
Thanks @Malopieds for the fix
  • Loading branch information
z-huang committed Aug 19, 2024
1 parent 98902e9 commit f6c8077
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
43 changes: 27 additions & 16 deletions app/src/main/java/com/zionhuang/music/db/DatabaseDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,9 @@ interface DatabaseDao {
@Query("SELECT * FROM album WHERE id = :albumId")
fun albumWithSongs(albumId: String): Flow<AlbumWithSongs?>

@Query("SELECT * FROM album_artist_map WHERE albumId = :albumId")
fun albumArtistMaps(albumId: String): List<AlbumArtistMap>

@Transaction
@Query("SELECT *, (SELECT COUNT(*) FROM playlist_song_map WHERE playlistId = playlist.id) AS songCount FROM playlist ORDER BY rowId")
fun playlistsByCreateDateAsc(): Flow<List<Playlist>>
Expand Down Expand Up @@ -692,22 +695,27 @@ interface DatabaseDao {
)
}
.forEach(::upsert)
albumPage.album.artists
?.map { artist ->
ArtistEntity(
id = artist.id ?: artistByName(artist.name)?.id ?: ArtistEntity.generateArtistId(),
name = artist.name
)
}
?.onEach(::insert)
?.mapIndexed { index, artist ->
AlbumArtistMap(
albumId = albumPage.album.browseId,
artistId = artist.id,
order = index
)
}
?.forEach(::insert)

albumPage.album.artists?.let { artists ->
// Recreate album artists
albumArtistMaps(album.id).forEach(::delete)
artists
.map { artist ->
ArtistEntity(
id = artist.id ?: artistByName(artist.name)?.id ?: ArtistEntity.generateArtistId(),
name = artist.name
)
}
.onEach(::insert)
.mapIndexed { index, artist ->
AlbumArtistMap(
albumId = albumPage.album.browseId,
artistId = artist.id,
order = index
)
}
.forEach(::insert)
}
}

@Upsert
Expand All @@ -728,6 +736,9 @@ interface DatabaseDao {
@Delete
fun delete(album: AlbumEntity)

@Delete
fun delete(albumArtistMap: AlbumArtistMap)

@Delete
fun delete(playlist: PlaylistEntity)

Expand Down
3 changes: 2 additions & 1 deletion innertube/src/main/java/com/zionhuang/innertube/YouTube.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import com.zionhuang.innertube.models.YouTubeClient.Companion.WEB
import com.zionhuang.innertube.models.YouTubeClient.Companion.WEB_REMIX
import com.zionhuang.innertube.models.YouTubeLocale
import com.zionhuang.innertube.models.getContinuation
import com.zionhuang.innertube.models.oddElements
import com.zionhuang.innertube.models.response.AccountMenuResponse
import com.zionhuang.innertube.models.response.BrowseResponse
import com.zionhuang.innertube.models.response.GetQueueResponse
Expand Down Expand Up @@ -159,7 +160,7 @@ object YouTube {
browseId = browseId,
playlistId = playlistId,
title = response.contents?.twoColumnBrowseResultsRenderer?.tabs?.firstOrNull()?.tabRenderer?.content?.sectionListRenderer?.contents?.firstOrNull()?.musicResponsiveHeaderRenderer?.title?.runs?.firstOrNull()?.text!!,
artists = response.contents.twoColumnBrowseResultsRenderer.tabs.firstOrNull()?.tabRenderer?.content?.sectionListRenderer?.contents?.firstOrNull()?.musicResponsiveHeaderRenderer?.straplineTextOne?.runs?.map {
artists = response.contents.twoColumnBrowseResultsRenderer.tabs.firstOrNull()?.tabRenderer?.content?.sectionListRenderer?.contents?.firstOrNull()?.musicResponsiveHeaderRenderer?.straplineTextOne?.runs?.oddElements()?.map {
Artist(
name = it.text,
id = it.navigationEndpoint?.browseEndpoint?.browseId
Expand Down

0 comments on commit f6c8077

Please sign in to comment.