Advertisement
mightyroot

Linux ident song artist and title

Feb 3rd, 2013
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.01 KB | None | 0 0
  1. #!/usr/bin/perl
  2. # http://developer.echonest.com/docs/v4/song.html#identify
  3. # wget https://github.com/echonest/echoprint-codegen
  4. # cat README.md
  5. #----------------------------------------------
  6.  
  7. use LWP::Simple;
  8. use JSON qw( decode_json );
  9. use JSON::Parse;
  10. use Data::Dumper;
  11. use strict;
  12. use warnings;
  13.  
  14.  
  15. system('./codegen.Linux-i686 "'.$ARGV[0].'" 30 30 > /tmp/sng.tmp');
  16.  
  17. open FILE, "/tmp/sng.tmp" or die $!;
  18. my @file_lines = <FILE>;
  19. close FILE;
  20.  
  21. my $decoded_json = decode_json( $file_lines[1] );
  22.  
  23. my $mus_code = $decoded_json->{'code'};
  24. print "code: ", $mus_code, "\n";
  25.  
  26.  
  27. my $trendsurl = "http://developer.echonest.com/api/v4/song/identify?api_key=FILDTEOIK2HBORODV&code=".$mus_code."";
  28.  
  29. my $json = get( $trendsurl );
  30. die "Could not get $trendsurl!" unless defined $json;
  31.  
  32. $decoded_json = decode_json( $json );
  33.  
  34. print Dumper $decoded_json;
  35.  
  36. print "artist_name: ", $decoded_json->{'response'}{'songs'}[0]{'artist_name'}, "\n";
  37. print "title: ", $decoded_json->{'response'}{'songs'}[0]{'title'}, "\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement