/lib/DDG/Spice/Lastfm/Song.pm

https://github.com/pardocz/zeroclickinfo-spice · Perl · 42 lines · 34 code · 7 blank · 1 comment · 3 complexity · 2bf18d8275da504da1419c6922a01ce7 MD5 · raw file

  1. package DDG::Spice::Lastfm::Song;
  2. # ABSTRACT: Display song info.
  3. use DDG::Spice;
  4. primary_example_queries "Payphone song by Maroon 5";
  5. description "Song information";
  6. name "LastFM Song";
  7. icon_url "/i/www.last.fm.ico";
  8. source "Last.fm";
  9. code_url "https://github.com/duckduckgo/zeroclickinfo-spice/blob/master/lib/DDG/Spice/Lastfm/Song.pm";
  10. topics "entertainment", "music";
  11. category "entertainment";
  12. attribution github => ['https://github.com/jagtalon','Jag Talon'],
  13. twitter => ['http://twitter.com/juantalon','Jag Talon'];
  14. spice to => 'http://ws.audioscrobbler.com/2.0/?format=json&method=track.getinfo&track=$1&artist=$2&autocorrect=1&api_key={{ENV{DDG_SPICE_LASTFM_APIKEY}}}&callback={{callback}}';
  15. spice from => '(?:([^/]*)/([^/]*)|)';
  16. triggers query_lc => qr/ ^
  17. ([^\s]+(?:\s+[^\s]+)*)\s+
  18. (?:tracks?|songs?|music)\s+
  19. (?:by|from)\s+
  20. ([^\s]+(?:\s+[^\s]+)*)
  21. $|^
  22. (?:listen(?:\s+to)?)\s+
  23. ([^\s]+(?:\s+[^\s]+)*)\s+
  24. (?:by|from)\s+
  25. ([^\s]+(?:\s+[^\s]+)*)
  26. $/x;
  27. handle matches => sub {
  28. if($1 && $2) {
  29. return $1, $2;
  30. } elsif($3 && $4) {
  31. return $3, $4;
  32. }
  33. return;
  34. };
  35. 1;