/lib/DDG/Spice/Lastfm/Artist.pm

https://github.com/pardocz/zeroclickinfo-spice · Perl · 51 lines · 36 code · 9 blank · 6 comment · 5 complexity · bee37463f66ae817bd2328cbbeaa559b MD5 · raw file

  1. package DDG::Spice::Lastfm::Artist;
  2. # ABSTRACT: Search for musicians in Last.fm and get artists or bands similar to them.
  3. use DDG::Spice;
  4. primary_example_queries "ben folds five artist";
  5. secondary_example_queries "kanye west rapper", "bands similar to incubus", "weezer band", "musicians similar to lady gaga";
  6. description "Musician information";
  7. name "LastFM Artist";
  8. icon_url "/i/www.last.fm.ico";
  9. source "Last.fm";
  10. code_url "https://github.com/duckduckgo/zeroclickinfo-spice/blob/master/lib/DDG/Spice/Lastfm/Artist.pm";
  11. topics "entertainment", "music";
  12. category "entertainment";
  13. attribution github => ['https://github.com/jagtalon','Jag Talon'],
  14. twitter => ['http://twitter.com/juantalon','Jag Talon'];
  15. spice to => 'http://ws.audioscrobbler.com/2.0/?format=json&method=artist.getinfo&artist=$1&autocorrect=1&api_key={{ENV{DDG_SPICE_LASTFM_APIKEY}}}&callback={{callback}}_$2';
  16. spice from => '(?:([^/]*)/([^/]*)|)';
  17. triggers any => 'similar', 'band', 'bands', 'musician', 'musicians', 'artist', 'artists', 'performer', 'performers', 'singer', 'singers', 'rapper', 'dj', 'rappers', 'vocalist', 'vocalists', 'djs', 'songster', 'songsters';
  18. handle query_lc => sub {
  19. my $synonyms = "bands?|musicians?|players?|artists?|performers?|singers?|rappers?|djs?|vocalists?|songsters?";
  20. #Queries like "bands similar to incubus" or "artists similar ben folds"
  21. if(m{(?:$synonyms)\s+similar\s+(?:to\s+)?(\S+(?:\s+\S+)*)}) {
  22. return $1, 'similar';
  23. }
  24. #Queries like "similar bands to incubus" or "similar artists ben folds"
  25. if(m{similar\s+(?:$synonyms)\s+(?:to\s+)?(\S+(?:\s+\S+)*)}) {
  26. return $1, 'similar';
  27. }
  28. #Queries like "30 seconds to mars similar bands" or "ben folds similar musicians"
  29. if(m{(\S+(?:\s+\S+)*)\s+similar\s+(?:$synonyms)}) {
  30. return $1, 'similar';
  31. }
  32. #Queries like "weezer band"
  33. if(m{(\S+(?:\s+\S+)*)\s+(?:$synonyms)}) {
  34. return $1, 'all';
  35. }
  36. #Queries like "artist kanye west"
  37. if(m{(?:$synonyms)\s+(\S+(?:\s+\S+)*)}) {
  38. return $1, 'all';
  39. }
  40. return;
  41. };
  42. 1;