feat: search and download from YouTube Music
CI / chart (push) Successful in 3s
CI / test (push) Successful in 2m6s
CI / chart-push (push) Successful in 4s
CI / image (push) Successful in 3m25s

- search music.youtube.com with the Songs filter and resolve each hit so
  results carry canonical artist, album and duration
- fall back to plain ytsearch when the Music search fails
- download the Music watch URL first and the regular YouTube URL second
- parse explicit artist fields and drop channel/album/playlist entries
- update the smoke stub, docs and tests
This commit is contained in:
TapTap committed 2026-11-16 18:38:53 +00:00
1 parent 61d8b58223
commit 515b9bbe1b
6 files changed
+215 -29

No files matched your search

@@ -31,6 +31,43 @@ class DiscoveryServiceTest {
assertEquals(YtCandidate("c", "Loud", "Gamma", null, 90, null), parsed[2])
}
@Test
fun `parses resolved YouTube Music songs and drops browse entries`() {
val json = """
{"id":"daft punk","entries":[
{"id":"wU26xVT_vBU","title":"One More Time (Radio Edit)","artist":"Daft Punk",
"artists":["Daft Punk"],"album":"One More Time","duration":320,
"thumbnails":[{"url":"http://t/1.jpg"},{"url":"http://t/2.jpg"}]},
{"id":"4D7u5KF7SP8","title":"Get Lucky (feat. Pharrell Williams and Nile Rodgers)",
"artists":["Daft Punk","Pharrell Williams","Nile Rodgers"],
"album":"Random Access Memories","duration":370},
{"id":"UCRr1xG_2WIDs18a6cIiCxeA","ie_key":"YoutubeTab","title":"Daft Punk - Topic"},
{"id":"MPREb_uWQeJO6Z53u","ie_key":"YoutubeTab","title":"Album - One More Time"},
{"id":"khnokW3Mw24","title":"Instant Crush (feat. Julian Casablancas)","artist":"Daft Punk",
"album":"NA","duration":338}
]}
""".trimIndent()
val parsed = parseYtSearchOutput(json)
assertEquals(3, parsed.size)
assertEquals(
YtCandidate(
videoId = "wU26xVT_vBU",
title = "One More Time (Radio Edit)",
artist = "Daft Punk",
album = "One More Time",
duration = 320,
thumbnail = "http://t/2.jpg",
),
parsed[0],
)
// A dash inside a real song title must not be treated as an artist split.
assertEquals("Get Lucky (feat. Pharrell Williams and Nile Rodgers)", parsed[1].title)
assertEquals("Daft Punk, Pharrell Williams, Nile Rodgers", parsed[1].artist)
assertEquals(null, parsed[2].album)
}
@Test
fun `parses a single resolved video`() {
val json = """