Skip to content

Commit

Permalink
Merge pull request #26 from devceline/feat/add-lang-selection
Browse files Browse the repository at this point in the history
feat: add lang support
  • Loading branch information
trizen authored Oct 25, 2024
2 parents f1cb6cf + bb91183 commit 4042d3f
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion clyrics
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ my $cache_dir = "$xdg_cache_home/$pkgname";

my @plugins_dirs;

my $language = "en-US,en";

# Plugins directory
{
my $plugins_dir = catdir($xdg_config_home, $pkgname);
Expand All @@ -73,7 +75,7 @@ if (-d "/usr/share/$pkgname") {

my %opt;
if ($#ARGV != -1 and substr($ARGV[0], 0, 1) eq '-') {
getopts('hvds:P:mcpkL:', \%opt);
getopts('hvds:P:mcpkL:l:', \%opt);
}

# Help
Expand Down Expand Up @@ -128,6 +130,16 @@ if (exists $opt{L}) {
}
}

# Language selection
if (exists $opt{l}) {
if (defined $opt{l}) {
$language = $opt{l};
}
else {
die "error: option '-l' requires a language as an argument! Eg: 'en-US,en'\n";
}
}

if (not -d $cache_dir) {
require File::Path;
File::Path::make_path($cache_dir)
Expand Down Expand Up @@ -210,6 +222,7 @@ options:
-c : start as a daemon for cmus player
-p : start as a daemon for playerctl media controller
-k : do not quit if player is not playing any song
-l : specify a language, useful for avoiding translated lyrics
-s <int> : sleep duration between lyrics updates (default: $SLEEP_SECONDS)
-P <dir> : directory containing the clyrics plugins
-L <dir> : directory where to save the lyrics
Expand Down Expand Up @@ -393,6 +406,9 @@ sub get_lyrics {
agent => 'Mozilla/5.0 (iPad; CPU OS 7_1_1 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Version/7.0 Mobile/11D201 Safari/9537.53',
);


$mech->add_header( 'Accept-Language' => "$language;q=0.5" );

state $sites = decode_utf8(join(' OR ', map { "site:$_->{site}" } @plugins));

require HTTP::Cookies;
Expand Down

0 comments on commit 4042d3f

Please sign in to comment.