Created
February 26, 2022 14:54
-
-
Save rfc-2549/b26557ba8190fe500bc429c523f06717 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use LWP::UserAgent; | |
use JSON; | |
my $ua = LWP::UserAgent->new; | |
my $API_KEY = "XXXXXXXXXXXXXXXXXXX"; | |
my $USER = "xxx"; | |
my $url = "/2.0/?method=user.getrecenttracks&user=$USER&api_key=$API_KEY&format=json&limit=2"; | |
my $base_url = "http://ws.audioscrobbler.com"; | |
my $hash = decode_json($ua->get($base_url . $url)->content); | |
my $artist_name = $hash->{recenttracks}->{track}->[0]->{artist}->{'#text'}; | |
my $song_name = $hash->{recenttracks}->{track}->[0]->{name}; | |
my $now_playing = $hash->{recenttracks}->{track}->[0]->{'@attr'}->{nowplaying}; | |
if($now_playing eq "true") { | |
printf("%s - %s\n", $artist_name, $song_name); | |
} else { | |
printf "Offline"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment