-
Notifications
You must be signed in to change notification settings - Fork 593
fix(artists): properly handle artist conjunctions in YouTube Music API responses #3695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
82187a8
4598adc
bdc8f97
2e91b6a
f083963
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ import com.metrolist.innertube.models.PlaylistItem | |
| import com.metrolist.innertube.models.SongItem | ||
| import com.metrolist.innertube.models.YTItem | ||
| import com.metrolist.innertube.models.oddElements | ||
| import com.metrolist.innertube.models.splitArtistsByConjunction | ||
| import com.metrolist.innertube.models.splitBySeparator | ||
| import com.metrolist.innertube.utils.parseTime | ||
|
|
||
|
|
@@ -20,20 +21,21 @@ data class ArtistItemsPage( | |
| companion object { | ||
| fun fromMusicResponsiveListItemRenderer(renderer: MusicResponsiveListItemRenderer): SongItem? { | ||
| // Split the secondary line by bullet separator to separate artists from other metadata (like views) | ||
| val secondaryLineRuns = renderer.flexColumns | ||
| val artistRuns = renderer.flexColumns | ||
| .getOrNull(1) | ||
| ?.musicResponsiveListItemFlexColumnRenderer | ||
| ?.text | ||
| ?.runs | ||
| ?.splitBySeparator() | ||
|
|
||
| // Extract artists from the first segment after splitting | ||
| val artists = secondaryLineRuns?.firstOrNull()?.oddElements()?.map { | ||
| Artist( | ||
| name = it.text, | ||
| id = it.navigationEndpoint?.browseEndpoint?.browseId | ||
| ) | ||
| } | ||
| ?.getOrNull(0) | ||
| ?.splitArtistsByConjunction() | ||
| ?.filter { it.text.isNotBlank() && it.text != "&" && it.text != "," } | ||
| ?.map { run -> | ||
| Artist( | ||
| name = run.text.trim(), | ||
| id = run.navigationEndpoint?.browseEndpoint?.browseId | ||
| ) | ||
| } | ||
|
|
||
| // Extract album from last flexColumn (like SimpMusic does) | ||
| val album = renderer.flexColumns.lastOrNull() | ||
|
|
@@ -55,7 +57,7 @@ data class ArtistItemsPage( | |
| title = renderer.flexColumns.firstOrNull() | ||
| ?.musicResponsiveListItemFlexColumnRenderer?.text | ||
| ?.runs?.firstOrNull()?.text ?: return null, | ||
| artists = artists ?: return null, | ||
| artists = artistRuns ?: return null, | ||
| album = album, | ||
| duration = renderer.fixedColumns?.firstOrNull() | ||
| ?.musicResponsiveListItemFlexColumnRenderer?.text | ||
|
|
@@ -89,21 +91,37 @@ data class ArtistItemsPage( | |
| } != null | ||
| ) | ||
| // Video | ||
| renderer.isSong -> SongItem( | ||
| id = renderer.navigationEndpoint.watchEndpoint?.videoId ?: return null, | ||
| title = renderer.title.runs?.firstOrNull()?.text ?: return null, | ||
| artists = renderer.subtitle?.runs?.splitBySeparator()?.firstOrNull()?.oddElements()?.map { | ||
| Artist( | ||
| name = it.text, | ||
| id = it.navigationEndpoint?.browseEndpoint?.browseId | ||
| ) | ||
| } ?: return null, | ||
| album = null, | ||
| duration = null, | ||
| musicVideoType = renderer.musicVideoType, | ||
| thumbnail = renderer.thumbnailRenderer.musicThumbnailRenderer?.getThumbnailUrl() ?: return null, | ||
| endpoint = renderer.navigationEndpoint.watchEndpoint | ||
| ) | ||
| renderer.isSong -> { | ||
| val subtitleRuns = renderer.subtitle?.runs ?: return null | ||
| // Split any runs that contain conjunctions (&, ,) to properly extract individual artists | ||
| val expandedRuns = subtitleRuns.splitArtistsByConjunction() | ||
| // Filter out separator runs (like "&", ",") to get only artist runs | ||
| val artistRuns = expandedRuns.filter { | ||
| it.text.isNotBlank() && it.text != "&" && it.text != "," | ||
| } | ||
| SongItem( | ||
| id = renderer.navigationEndpoint.watchEndpoint?.videoId ?: return null, | ||
| title = renderer.title.runs?.firstOrNull()?.text ?: return null, | ||
| artists = artistRuns.filter { | ||
| it.navigationEndpoint?.browseEndpoint?.browseId?.startsWith("UC") == true || | ||
| it.navigationEndpoint?.browseEndpoint != null | ||
| }.map { | ||
| Artist( | ||
| name = it.text.trim(), | ||
| id = it.navigationEndpoint?.browseEndpoint?.browseId | ||
| ) | ||
| }.ifEmpty { | ||
| artistRuns.firstOrNull()?.let { | ||
| listOf(Artist(name = it.text.trim(), id = null)) | ||
| } ?: emptyList() | ||
| }, | ||
|
Comment on lines
+95
to
+117
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Two-row songs still collapse unlinked split artists back to the first name. After Suggested direction- val subtitleRuns = renderer.subtitle?.runs ?: return null
- // Split any runs that contain conjunctions (&, ,) to properly extract individual artists
- val expandedRuns = subtitleRuns.splitArtistsByConjunction()
- // Filter out separator runs (like "&", ",") to get only artist runs
- val artistRuns = expandedRuns.filter {
- it.text.isNotBlank() && it.text != "&" && it.text != ","
- }
+ val artistRuns = renderer.subtitle?.runs
+ ?.splitBySeparator()
+ ?.firstOrNull()
+ .orEmpty()
+ .splitArtistsByConjunction()
+ .filter { it.text.isNotBlank() }
SongItem(
id = renderer.navigationEndpoint.watchEndpoint?.videoId ?: return null,
title = renderer.title.runs?.firstOrNull()?.text ?: return null,
- artists = artistRuns.filter {
- it.navigationEndpoint?.browseEndpoint?.browseId?.startsWith("UC") == true ||
- it.navigationEndpoint?.browseEndpoint != null
- }.map {
+ artists = artistRuns.map {
Artist(
name = it.text.trim(),
id = it.navigationEndpoint?.browseEndpoint?.browseId
)
- }.ifEmpty {
- artistRuns.firstOrNull()?.let {
- listOf(Artist(name = it.text.trim(), id = null))
- } ?: emptyList()
- },
+ }.ifEmpty { return null },🤖 Prompt for AI Agents |
||
| album = null, | ||
| duration = null, | ||
| musicVideoType = renderer.musicVideoType, | ||
| thumbnail = renderer.thumbnailRenderer.musicThumbnailRenderer?.getThumbnailUrl() ?: return null, | ||
| endpoint = renderer.navigationEndpoint.watchEndpoint | ||
| ) | ||
| } | ||
| renderer.isPlaylist -> PlaylistItem( | ||
| id = renderer.navigationEndpoint.browseEndpoint?.browseId?.removePrefix("VL") ?: return null, | ||
| title = renderer.title.runs?.firstOrNull()?.text ?: return null, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't treat commas as an unconditional artist separator.
Line 34 will split legitimate single-artist names like
Tyler, The Creatorinto multiple artists, which is a worse misclassification than the one this PR is fixing. The shared helper needs a narrower heuristic for commas than,in the global regex.🤖 Prompt for AI Agents