| 1 | package Bot::BasicBot::Pluggable::Module::Spotify; | ||||||||||||||||||
| 2 | |||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 5 | |||||||||||||||||||
| 6 | 2 | ▶ | use Net::Spotify (); | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 7 | 2 | ▶ | use XML::TreePP (); | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 8 | |||||||||||||||||||
| 9 | 2 | ▶ | use base 'Bot::BasicBot::Pluggable::Module::Base'; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 10 | |||||||||||||||||||
| 11 | 2 | our $VERSION = '0.01'; | |||||||||||||||||
| 12 | |||||||||||||||||||
| 13 | 2 | my $spotify = Net::Spotify->new(); | |||||||||||||||||
| 14 | 2 | my $tpp = XML::TreePP->new(); | |||||||||||||||||
| 15 | |||||||||||||||||||
| 16 | 0 | ▶ | sub help { | ||||||||||||||||
|
Subroutine
help: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||
| 17 | 0 | return 'Will parse those cryptic Spotify URIs showing the interesting information :)'; | |||||||||||||||||
| 18 | } | ||||||||||||||||||
| 19 | |||||||||||||||||||
| 20 | 0 | ▶ | sub said { | ||||||||||||||||
|
Subroutine
said: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||
| 21 | 0 | my ($self, $mess, $pri) = @_; | |||||||||||||||||
| 22 | |||||||||||||||||||
| 23 | 0 | ▶ | return unless $pri == 2; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 24 | |||||||||||||||||||
| 25 | 0 | my @data = $self->parse_spotify_uris($mess->{body}); | |||||||||||||||||
| 26 | |||||||||||||||||||
| 27 | 0 | ▶ | if (! scalar @data) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 28 | 0 | return; | |||||||||||||||||
| 29 | } | ||||||||||||||||||
| 30 | |||||||||||||||||||
| 31 | 0 | foreach my $info (@data) { | |||||||||||||||||
| 32 | 0 | $self->tell($mess->{channel}, $info) | |||||||||||||||||
| 33 | } | ||||||||||||||||||
| 34 | |||||||||||||||||||
| 35 | 0 | return; | |||||||||||||||||
| 36 | } | ||||||||||||||||||
| 37 | |||||||||||||||||||
| 38 | 0 | ▶ | sub parse_spotify_uris { | ||||||||||||||||
|
Subroutine
parse_spotify_uris: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||
| 39 | 0 | my ($self, $text) = @_; | |||||||||||||||||
| 40 | |||||||||||||||||||
| 41 | 0 | my @data = (); | |||||||||||||||||
| 42 | |||||||||||||||||||
| 43 | 0 | ▶ | while ($text =~ m{ \b (spotify:(artist|album|track):\w+) \b }gmx) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 44 | 0 | my ($uri, $type) = ($1, $2); | |||||||||||||||||
| 45 | |||||||||||||||||||
| 46 | 0 | my $xml = $spotify->lookup(uri => $uri); | |||||||||||||||||
| 47 | |||||||||||||||||||
| 48 | 0 | ▶ | if (my $tree = $tpp->parse($xml)) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 49 | 0 | ▶ | if ($type eq 'artist') { | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 50 | push @data, sprintf( | ||||||||||||||||||
| 51 | '%s -> Artist: %s', | ||||||||||||||||||
| 52 | $uri, | ||||||||||||||||||
| 53 | $tree->{artist}->{name}, | ||||||||||||||||||
| 54 | 0 | ); | |||||||||||||||||
| 55 | } | ||||||||||||||||||
| 56 | elsif ($type eq 'album') { | ||||||||||||||||||
| 57 | push @data, sprintf( | ||||||||||||||||||
| 58 | '%s -> Album: %s, Artist: %s, Year: %s', | ||||||||||||||||||
| 59 | $uri, | ||||||||||||||||||
| 60 | $tree->{album}->{name}, $tree->{album}->{artist}->{name}, | ||||||||||||||||||
| 61 | $tree->{album}->{released} | ||||||||||||||||||
| 62 | 0 | ); | |||||||||||||||||
| 63 | } | ||||||||||||||||||
| 64 | elsif ($type eq 'track') { | ||||||||||||||||||
| 65 | push @data, sprintf( | ||||||||||||||||||
| 66 | '%s -> Track: %s, Album: %s, Artist: %s', | ||||||||||||||||||
| 67 | $uri, | ||||||||||||||||||
| 68 | $tree->{track}->{name}, | ||||||||||||||||||
| 69 | $tree->{track}->{album}->{name}, | ||||||||||||||||||
| 70 | $tree->{track}->{artist}->{name}, | ||||||||||||||||||
| 71 | 0 | ); | |||||||||||||||||
| 72 | } | ||||||||||||||||||
| 73 | } | ||||||||||||||||||
| 74 | } | ||||||||||||||||||
| 75 | |||||||||||||||||||
| 76 | 0 | return @data; | |||||||||||||||||
| 77 | } | ||||||||||||||||||
| 78 | |||||||||||||||||||
| 79 | 2 | 1; | |||||||||||||||||
| 80 | |||||||||||||||||||
| 81 | __END__ | ||||||||||||||||||