Skip to content
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

lyrics: Remove French prefix which lyrics.ovh embeds into lyrics #153

Merged

Conversation

radioactiveman
Copy link
Member

https://lyrics.ovh embeds a French prefix for Lyrics of the song {title} by {artist} to all lyrics,
regardless of the lyrics language or user country (verified with proxies).

Examples:

Questions:

  • Is it safe to return the char pointer like this or should it be wrapped into a String or StringBuf?
  • Is there a way to trim also non-breaking-space characters? g_strchug() does not remove them.
    The 2nd example shows therefore unnecessary newlines below the header.

grafik

@jlindgren90
Copy link
Member

* Is it safe to return the char pointer like this or should it be wrapped into a String or StringBuf?

No, it's not safe because the char pointer points inside the temporary StringBuf.

* Is there a way to trim also non-breaking-space characters? `g_strchug()` does not remove them.
  The 2nd example shows therefore unnecessary newlines below the header.

g_strchug() handles ASCII only, but GLib has some UTF-8 functions that should work for this. I think this should work:

static String truncate_prefix (const String & lyrics, const char * prefix)
{
    if (! str_has_prefix_nocase (lyrics, prefix))
        return lyrics;

    const char * truncated = strstr (lyrics, "\r\n");
    if (! truncated || ! g_utf8_validate (truncated, -1, NULL))
        return lyrics;

    while ((* truncated) && g_unichar_isspace (g_utf8_get_char (truncated)))
        truncated = g_utf8_next_char (truncated);

    return String (truncated);
}

Co-authored-by: John Lindgren <john@jlindgren.net>
@radioactiveman
Copy link
Member Author

Works perfectly, thanks John.

@radioactiveman radioactiveman merged commit 33806d1 into audacious-media-player:master Mar 9, 2024
7 checks passed
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.

2 participants