Last active
August 16, 2016 09:30
-
-
Save a3f/064ba8b47f9e316163c09a78c965bfd6 to your computer and use it in GitHub Desktop.
print a user's playing track on last.fm (or Spotify if last.fm is connected)
This file contains hidden or 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
| apikey = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | |
| secret = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | |
| user = xxx | |
| ^F3:: | |
| { | |
| dhw := A_DetectHiddenWindows | |
| DetectHiddenWindows On | |
| Run "%ComSpec%" /k,, Hide, pid | |
| while !(hConsole := WinExist("ahk_pid" pid)) | |
| Sleep 10 | |
| DllCall("AttachConsole", "UInt", pid) | |
| DetectHiddenWindows %dhw% | |
| shell := ComObjCreate("WScript.Shell") | |
| exec := shell.Exec("perl playingTrack.pl " apikey " " secret " " user) | |
| track := regexreplace(exec.StdOut.ReadAll(), "[\r\n]+$") | |
| if track is not space | |
| SendInput % track | |
| else | |
| SendInput, n/a | |
| DllCall("FreeConsole") | |
| Process Exist, %pid% | |
| if (ErrorLevel == pid) | |
| Process Close, %pid% | |
| } |
This file contains hidden or 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
| cpan Net::LastFM |
This file contains hidden or 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 strict; | |
| use warnings; | |
| use Net::LastFM; | |
| # you can add your info here if you want, or over command line | |
| my $api_key; | |
| my $secret; | |
| my $user; | |
| my $lastfm = Net::LastFM->new( | |
| api_key => shift // $api_key, | |
| api_secret => shift // $secret, | |
| ); | |
| my $data = $lastfm->request_signed( | |
| method => 'user.getRecentTracks', | |
| user => shift // $user, | |
| ); | |
| my $p; | |
| foreach my $track (@{$data->{recenttracks}{track}}) { | |
| if ($track->{'@attr'}{nowplaying}) { | |
| $p = $track; | |
| last; | |
| } | |
| } | |
| print "$p->{artist}{'#text'} ~ $p->{name} ($p->{album}{'#text'})\n" if defined $p; |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to use:
installDeps.cmdscript to install dependenciesbindPastePlayingTrack.ahkscript to add your API key and username. The fourth Line is the shortcut(Ctrl+F3)bindPastePlayingTrack.ahkand enjoy :)Note: This does a HTTP request and might take a second or two