summaryrefslogtreecommitdiff
path: root/info
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2022-09-18 09:15:23 +0200
committerPřemysl Eric Janouch <p@janouch.name>2022-09-20 11:04:39 +0200
commit28ed7a85a8cbf3173f17e8ca9f7c8a7d5a7c98ed (patch)
tree3e6f1af6d9bcf195b9b52c4485741ed2c5eec60c /info
parentb6dd94072080d29b356d2c22d9f317deac55331d (diff)
downloadnncmpp-28ed7a85a8cbf3173f17e8ca9f7c8a7d5a7c98ed.tar.gz
nncmpp-28ed7a85a8cbf3173f17e8ca9f7c8a7d5a7c98ed.tar.xz
nncmpp-28ed7a85a8cbf3173f17e8ca9f7c8a7d5a7c98ed.zip
Implement lyrics lookup
There is now a generic mechanism for loading lyrics, or any other arbitrary content related to songs.
Diffstat (limited to 'info')
-rwxr-xr-xinfo/10-azlyrics.pl43
1 files changed, 43 insertions, 0 deletions
diff --git a/info/10-azlyrics.pl b/info/10-azlyrics.pl
new file mode 100755
index 0000000..4b88bda
--- /dev/null
+++ b/info/10-azlyrics.pl
@@ -0,0 +1,43 @@
+#!/usr/bin/env perl
+# 10-azlyrics.pl: nncmpp info plugin to fetch song lyrics on AZLyrics
+#
+# Copyright (c) 2022, Přemysl Eric Janouch <p@janouch.name>
+# SPDX-License-Identifier: 0BSD
+#
+# Inspired by a similar ncmpc plugin.
+
+use warnings;
+use strict;
+use utf8;
+use open ':std', ':utf8';
+unless (@ARGV) {
+ print "Look up on AZLyrics\n";
+ exit;
+}
+
+use Encode;
+my ($title, $artist, $album) = map {decode_utf8($_)} @ARGV;
+
+# TODO: An upgrade would be transliteration with, e.g., Text::Unidecode.
+use Unicode::Normalize;
+$artist = lc(NFD($artist) =~ s/^the\s+//ir =~ s/[^A-Za-z0-9]//gr);
+$title = lc(NFD($title) =~ s/\(.*?\)//gr =~ s/[^A-Za-z0-9]//gr);
+
+# TODO: Consider caching the results in a location like
+# $XDG_CACHE_HOME/nncmpp/info/azlyrics/$artist-$title
+my $found = 0;
+if ($title ne '') {
+ open(my $curl, '-|', 'curl', '-sA', 'nncmpp/2.0',
+ "https://www.azlyrics.com/lyrics/$artist/$title.html") or die $!;
+ while (<$curl>) {
+ next unless /^<div>/ .. /^<\/div>/; s/<!--.*?-->//g; s/\s+$//gs;
+
+ $found = 1;
+ s/<\/?b>/\x01/g; s/<\/?i>/\x02/g; s/<br>/\n/; s/<.+?>//g;
+ s/&lt;/</g; s/&gt;/>/g; s/&quot;/"/g; s/&apos;/'/g; s/&amp;/&/g;
+ print;
+ }
+ close($curl) or die $?;
+}
+
+print "No lyrics have been found.\n" unless $found;