Skip to content

Buscar por el nombre de la canción, no por el título del vídeo - #41

Merged
Isma-L154 merged 1 commit into
mainfrom
arreglo-lyrics-titulos
Sep 12, 2026
Merged

Isma-L154 merged 1 commit into
mainfrom
arreglo-lyrics-titulos

Conversation

@Isma-L154

Copy link
Copy Markdown
Owner

!lyrics funcionaba 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:

"Music n Lyrics" / "The Police   Every Breath You Take (Lyrics)"  ->  HTTP 404
"The Police"     / "Every Breath You Take"                        ->  sincronizada

search_terms ahora limpia el título:

  • quita el mobiliario de vídeo: (Official Video), (Lyrics), [4K],
    (Remastered), (Visualizer), (Video Oficial), (Letra)…
  • quita los créditos ft. / feat. y los | Nombre del álbum finales
  • separa el artista de la parte delantera, y se fía del título antes que del
    canal: uno llamado "Music n Lyrics" no es quien grabó la canción
  • toma el primero cuando hay varios artistas (KAROL G, Judeline, rusowsky)
  • trata una racha de dos o más espacios como separador, que es exactamente
    la forma que tenía el título reportado

Y deja en paz lo que no puede dar por seguro: (Acoustic Version) es parte del
nombre 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 mismo
nombre
. El respaldo a Genius construía un Cog en vez de un resultado:

TypeError: Lyrics.__init__() got an unexpected keyword argument 'title'

Ningún test llegaba a ese camino — los del seguidor inyectan un cargador y nunca
llaman a _find. Ahora lo cubre tests/test_lyrics_cog.py, y al dataclass se
llega por el módulo en vez de importarlo suelto.

3. Y una caída no debería ser silencio

utils/errors.py registraba los fallos inesperados y deliberadamente no decía
nada
, 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>, pero The Police - Every Breath You Take es como se
escribe de verdad; el segundo orden solo cuesta una petición cuando el primero no
encontró nada.

Cómo probarlo

pytest      # 476

Verificado contra el LRCLIB real con la pista reportada:

titulo crudo : 'The Police   Every Breath You Take (Lyrics)'
canal        : 'Music n Lyrics'
-> se busca  : ('Every Breath You Take', 'The Police')
RESULTADO: sincronizada=True  74 lineas

--- a los 0:40 ---
🎤 Every Breath You Take — The Police
 I'll be watching you
 Every single day
**▶ And every word you say**
 Every game you play
 Every night you stay

En Discord, tras desplegar:

  1. !play The Police Every Breath You Take → !lyrics — el caso que falló.
  2. Un vídeo con (Official Video) o [4K] en el título — debe encontrarla igual.
  3. !lyrics The Police - Every Breath You Take y al revés — ambos deben ir.
  4. Algo que no exista — ahora responde, no se queda callado.

`!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.
@Isma-L154
Isma-L154 merged commit 34c0728 into main Sep 12, 2026
3 checks passed
@Isma-L154
Isma-L154 deleted the arreglo-lyrics-titulos branch September 12, 2026 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant