Skip to content

Commit

Permalink
lyrics: Remove French prefix which lyrics.ovh embeds into lyrics
Browse files Browse the repository at this point in the history
Co-authored-by: John Lindgren <john@jlindgren.net>
  • Loading branch information
radioactiveman and jlindgren90 committed Mar 9, 2024
1 parent b6a86db commit 8b93ed5
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/lyrics-common/lyrics_ovh_provider.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2010-2019 Ariadne Conill <ariadne@dereferenced.org>
* Copyright (c) 2024 Thomas Lange <thomas-lange2@gmx.de>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand All @@ -20,6 +21,21 @@

#include "lyrics.h"

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, nullptr))
return lyrics;

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

return String (truncated);
}

bool LyricsOVHProvider::match (LyricsState state)
{
fetch (state);
Expand Down Expand Up @@ -51,6 +67,9 @@ void LyricsOVHProvider::fetch (LyricsState state)
return;
}

// Remove French prefix for "Lyrics of the song {title} by {artist}"
// which lyrics.ovh embeds into every lyrics, regardless of the language.
new_state.lyrics = truncate_prefix (lyrics, "Paroles de la chanson");
new_state.source = LyricsState::Source::LyricsOVH;

update_lyrics_window (new_state.title, new_state.artist, new_state.lyrics);
Expand Down

0 comments on commit 8b93ed5

Please sign in to comment.