Buscar por el nombre de la canción, no por el título del vídeo - #41
Merged
Merged
Conversation
`!lyrics` worked for some songs and did nothing at all for others. Two separate
faults, and the second is what made the first invisible.
**It searched with the raw video title and the channel name.** Reported against
the live bot: "The Police - Every Breath You Take" got no answer. What the bot
actually asked LRCLIB for was the title as YouTube stores it and the uploader as
the artist, and measured against the real service the difference is total:
"Music n Lyrics" / "The Police Every Breath You Take (Lyrics)" -> HTTP 404
"The Police" / "Every Breath You Take" -> synced
So `search_terms` tidies a video title into something a lyrics database
recognises: it drops video furniture — `(Official Video)`, `(Lyrics)`, `[4K]`,
`(Remastered)` — drops featured credits and trailing album tags, and splits the
artist off the front. It trusts the title over the channel when the title names
both, because a channel called "Music n Lyrics" is not who recorded the song. A
run of two or more spaces counts as a separator, which is exactly the shape the
reported title had.
It leaves alone what it cannot be sure about: `(Acoustic Version)` is part of a
song's name, not furniture, and stays.
**The command answered nothing because it crashed.** The cog's own class is
called `Lyrics`, and it shadowed the dataclass imported under the same name, so
the Genius fallback built a Cog and raised:
TypeError: Lyrics.__init__() got an unexpected keyword argument 'title'
No test reached that path — the follower's tests inject a loader and never call
`_find`. `tests/test_lyrics_cog.py` covers it now, and the dataclass is reached
through the module rather than imported bare.
**And a crash should never be silence.** `utils.errors` logged unexpected
failures and deliberately said nothing, on the grounds that a bug is the
operator's problem. That is half right: the cause belongs in the log, but from
the channel a crash was indistinguishable from the bot being offline — which is
the exact thing that module's own docstring opens by warning about. Unexpected
errors are now acknowledged with a plain sentence, no internals, traceback still
logged. The test that asserted the old silence now asserts the new answer.
Also: a typed query is tried both ways round. The help documents
`<title> - <artist>`, but `The Police - Every Breath You Take` is how people
actually type it, and the second order only costs a request when the first
found nothing.
Verified against the real LRCLIB with the reported track: 74 synced lines and
the right window, where before there was no answer at all.
Tests: 476, up from 427.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
!lyricsfuncionaba con unas canciones y no respondía nada con otras.Reportado en vivo:
The Police - Every Breath You Take→ silencio total.Dos fallos distintos, y el segundo es lo que hizo invisible al primero.
476 tests (antes 427).
1. Buscaba con el título del vídeo, no con el nombre de la canción
Lo que el bot le pedía a LRCLIB era el título tal cual lo guarda YouTube y el
canal como artista. Medido contra el servicio real, la diferencia es total:
search_termsahora limpia el título:(Official Video),(Lyrics),[4K],(Remastered),(Visualizer),(Video Oficial),(Letra)…ft./feat.y los| Nombre del álbumfinalescanal: uno llamado "Music n Lyrics" no es quien grabó la canción
KAROL G, Judeline, rusowsky)la forma que tenía el título reportado
Y deja en paz lo que no puede dar por seguro:
(Acoustic Version)es parte delnombre de la canción, no mobiliario, y se queda.
2. No respondía porque se caía
El cog se llama
Lyrics, y sombreaba al dataclass importado con ese mismonombre. El respaldo a Genius construía un Cog en vez de un resultado:
Ningún test llegaba a ese camino — los del seguidor inyectan un cargador y nunca
llaman a
_find. Ahora lo cubretests/test_lyrics_cog.py, y al dataclass sellega por el módulo en vez de importarlo suelto.
3. Y una caída no debería ser silencio
utils/errors.pyregistraba los fallos inesperados y deliberadamente no decíanada, con el argumento de que un bug es problema del operador. Eso es medio
cierto: la causa va al log, pero desde el canal una caída era indistinguible de
que el bot estuviera apagado — que es justo contra lo que advierte el propio
docstring de ese módulo en su primera frase.
Ahora un error inesperado se reconoce con una frase llana, sin filtrar internos,
y la traza sigue yendo al log. El test que afirmaba el silencio anterior ahora
afirma la respuesta nueva.
Sin esto, el bug del punto 2 habría seguido siendo invisible.
Extra
Una consulta escrita se prueba en los dos órdenes. La ayuda documenta
<título> - <artista>, peroThe Police - Every Breath You Takees como seescribe de verdad; el segundo orden solo cuesta una petición cuando el primero no
encontró nada.
Cómo probarlo
pytest # 476Verificado contra el LRCLIB real con la pista reportada:
En Discord, tras desplegar:
!play The Police Every Breath You Take→!lyrics— el caso que falló.(Official Video)o[4K]en el título — debe encontrarla igual.!lyrics The Police - Every Breath You Takey al revés — ambos deben ir.