/lib/DDG/Spice/Lastfm/ArtistTracks.pm

https://github.com/pardocz/zeroclickinfo-spice · Perl · 32 lines · 24 code · 6 blank · 2 comment · 2 complexity · f58f8db2fc5b6fca7430f83cc8ae7218 MD5 · raw file

  1. package DDG::Spice::Lastfm::ArtistTracks;
  2. # ABSTRACT: Get the tracks of a musician.
  3. use DDG::Spice;
  4. primary_example_queries "songs by she & him";
  5. secondary_example_queries "songs from maroon 5";
  6. description "Top tracks from an artist";
  7. name "LastFM Artist Tracks";
  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/ArtistTracks.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/?limit=5&format=json&method=artist.gettoptracks&artist=$1&autocorrect=1&api_key={{ENV{DDG_SPICE_LASTFM_APIKEY}}}&callback={{callback}}';
  16. #Queries like "songs by ben folds" and "ben folds songs"
  17. my $synonyms = "songs?|tracks?|music";
  18. triggers query_lc => qr/^(?:(?:all|the)\s+)?(?:$synonyms)\s+(?:(?:by|from|of)\s+)?([^\s]+(?:\s+[^\s]+)*)$
  19. |
  20. ^([^\s]+(?:\s+[^\s]+)*)\s+(?:$synonyms)$/x;
  21. handle query_lc => sub {
  22. return $1 if $1;
  23. return $2 if $2;
  24. return;
  25. };
  26. 1;