| 1 | package WebService::Audioscrobbler; | ||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use CLASS; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | ▶ | use base 'Class::Data::Accessor'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use base 'Class::Accessor::Fast'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 1 | ▶ | use NEXT; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 1 | ▶ | use UNIVERSAL::require; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 1 | ▶ | use URI; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | =head1 NAME | ||||||||||
| 15 | |||||||||||
| 16 | WebService::Audioscrobbler - An object-oriented interface to the Audioscrobbler WebService API | ||||||||||
| 17 | |||||||||||
| 18 | =cut | ||||||||||
| 19 | |||||||||||
| 20 | 1 | our $VERSION = '0.08'; | |||||||||
| 21 | |||||||||||
| 22 | 1 | CLASS->mk_classaccessor("base_url" => URI->new("http://ws.audioscrobbler.com/1.0/")); | |||||||||
| 23 | |||||||||||
| 24 | # defining default classes | ||||||||||
| 25 | 1 | CLASS->mk_classaccessor("artist_class" => CLASS . '::Artist'); | |||||||||
| 26 | 1 | CLASS->mk_classaccessor("track_class" => CLASS . '::Track'); | |||||||||
| 27 | 1 | CLASS->mk_classaccessor("tag_class" => CLASS . '::Tag'); | |||||||||
| 28 | 1 | CLASS->mk_classaccessor("user_class" => CLASS . '::User'); | |||||||||
| 29 | 1 | CLASS->mk_classaccessor("data_fetcher_class" => CLASS . '::DataFetcher'); | |||||||||
| 30 | |||||||||||
| 31 | # requiring stuff | ||||||||||
| 32 | 1 | ▶ | CLASS->artist_class->require or die $@; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 1 | ▶ | CLASS->track_class->require or die $@; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | 1 | ▶ | CLASS->tag_class->require or die $@; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | 1 | ▶ | CLASS->user_class->require or die $@; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 1 | ▶ | CLASS->data_fetcher_class->require or die $@; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | |||||||||||
| 38 | # object accessors | ||||||||||
| 39 | 1 | CLASS->mk_accessors(qw/data_fetcher/); | |||||||||
| 40 | |||||||||||
| 41 | =head1 SYNOPSIS | ||||||||||
| 42 | |||||||||||
| 43 | B<WARNING: This module UNMAINTAINED and broken at this point in time.> | ||||||||||
| 44 | B<It doesn't work anymore as the APIs used were taken offline.> | ||||||||||
| 45 | If you feel like taking over and developing it further, feel free to contact the | ||||||||||
| 46 | author. | ||||||||||
| 47 | |||||||||||
| 48 | Thisa module aims to be a full implementation of a an object-oriented interface | ||||||||||
| 49 | to the Audioscrobbler WebService API (as available on | ||||||||||
| 50 | L<http://www.audioscrobbler.net/data/webservices/>). Since version 0.04, the | ||||||||||
| 51 | module fully supports data caching and, thus, complies to the service's | ||||||||||
| 52 | recommended usage guides. | ||||||||||
| 53 | |||||||||||
| 54 | use WebService::Audioscrobbler; | ||||||||||
| 55 | |||||||||||
| 56 | my $ws = WebService::Audioscrobbler->new; | ||||||||||
| 57 | |||||||||||
| 58 | # get an object for artist named 'foo' | ||||||||||
| 59 | my $artist = $ws->artist('foo'); | ||||||||||
| 60 | |||||||||||
| 61 | # retrieves tracks from 'foo' | ||||||||||
| 62 | my @tracks = $artist->tracks; | ||||||||||
| 63 | |||||||||||
| 64 | # retrieves tags associated with 'foo' | ||||||||||
| 65 | my @tags = $artist->tags; | ||||||||||
| 66 | |||||||||||
| 67 | # fetch artists similar to 'foo' | ||||||||||
| 68 | my @similar = $artist->similar_artists; | ||||||||||
| 69 | |||||||||||
| 70 | # prints each one of their names | ||||||||||
| 71 | for my $similar (@similar) { | ||||||||||
| 72 | print $similar->name . "\n"; | ||||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | ... | ||||||||||
| 76 | |||||||||||
| 77 | # get an object for tag 'bar' | ||||||||||
| 78 | my $tag = $ws->tag('bar'); | ||||||||||
| 79 | |||||||||||
| 80 | # fetch tracks tagged with 'bar' | ||||||||||
| 81 | my @bar_tracks = $tag->tracks; | ||||||||||
| 82 | |||||||||||
| 83 | ... | ||||||||||
| 84 | |||||||||||
| 85 | my $user = $ws->user('baz'); | ||||||||||
| 86 | |||||||||||
| 87 | my @baz_neighbours = $user->neighbours; | ||||||||||
| 88 | |||||||||||
| 89 | Audioscrobbler is a great service for tracking musical data of various sorts, | ||||||||||
| 90 | and its integration with the LastFM service (L<http://www.last.fm>) makes it | ||||||||||
| 91 | work even better. Audioscrobbler provides data regarding similarity between | ||||||||||
| 92 | artists, artists discography, tracks by musical genre (actually, by tags), | ||||||||||
| 93 | top artists / tracks / albums / tags and how all of that related to your own | ||||||||||
| 94 | musical taste. | ||||||||||
| 95 | |||||||||||
| 96 | Currently, only of subset of these data feeds are implemented, which can be | ||||||||||
| 97 | viewed as the core part of the service: artists, tags, tracks and users. Since | ||||||||||
| 98 | this module was developed as part of a automatic playlist building application | ||||||||||
| 99 | (still in development) these functions were more than enough for its initial | ||||||||||
| 100 | purposes but a (nearly) full WebServices API is planned. | ||||||||||
| 101 | |||||||||||
| 102 | In any case, code or documentation patches are welcome. | ||||||||||
| 103 | |||||||||||
| 104 | =head1 METHODS | ||||||||||
| 105 | |||||||||||
| 106 | =cut | ||||||||||
| 107 | |||||||||||
| 108 | =head2 C<new([$cache_root]> | ||||||||||
| 109 | |||||||||||
| 110 | Creates a new C<WebService::Audioscrobbler> object. This object can then be | ||||||||||
| 111 | used to retrieve various bits of information from the Audioscrobbler database. | ||||||||||
| 112 | If C<$cache_root> is specified, Audioscrobbler data will be cached under this | ||||||||||
| 113 | directory, otherwise it will use L<Cache::FileCache> defaults. | ||||||||||
| 114 | |||||||||||
| 115 | =cut | ||||||||||
| 116 | |||||||||||
| 117 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 118 | 0 | my $class = shift; | |||||||||
| 119 | 0 | my ($cache_root) = @_; | |||||||||
| 120 | |||||||||||
| 121 | 0 | my $self = bless {}, $class; | |||||||||
| 122 | |||||||||||
| 123 | # creates the data fetcher object which will be extensively used | ||||||||||
| 124 | 0 | $self->data_fetcher( | |||||||||
| 125 | $self->data_fetcher_class->new( { | ||||||||||
| 126 | base_url => $self->base_url, | ||||||||||
| 127 | cache_root => $cache_root | ||||||||||
| 128 | } ) | ||||||||||
| 129 | ); | ||||||||||
| 130 | |||||||||||
| 131 | 0 | $self; | |||||||||
| 132 | } | ||||||||||
| 133 | |||||||||||
| 134 | =head2 C<artist($name)> | ||||||||||
| 135 | |||||||||||
| 136 | Returns an L<WebService::Audioscrobbler::Artist> object constructed using the | ||||||||||
| 137 | given C<$name>. Note that this call doesn't actually check if the artist exists | ||||||||||
| 138 | since no remote calls are dispatched - the object is only constructed. | ||||||||||
| 139 | |||||||||||
| 140 | =cut | ||||||||||
| 141 | |||||||||||
| 142 | 0 | ▶ | sub artist { | ||||||||
|
Subroutine
artist: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 143 | 0 | my ($self, $artist) = @_; | |||||||||
| 144 | 0 | return $self->artist_class->new($artist, $self->data_fetcher); | |||||||||
| 145 | } | ||||||||||
| 146 | |||||||||||
| 147 | =head2 C<track($artist, $title)> | ||||||||||
| 148 | |||||||||||
| 149 | Returns an L<WebService::Audioscrobbler::Track> object constructed used the | ||||||||||
| 150 | given C<$artist> and C<$title>. The C<$artist> parameter can either be a | ||||||||||
| 151 | L<WebService::Audioscrobbler::Artist> object or a string (in this case, a | ||||||||||
| 152 | L<WebService::Audioscrobbler::Artist> will be created behind the scenes). Note | ||||||||||
| 153 | that this call doesn't actually check if the track exists since no remote calls | ||||||||||
| 154 | are dispatched - the object is only constructed. | ||||||||||
| 155 | |||||||||||
| 156 | =cut | ||||||||||
| 157 | |||||||||||
| 158 | 0 | ▶ | sub track { | ||||||||
|
Subroutine
track: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 159 | 0 | my ($self, $artist, $title) = @_; | |||||||||
| 160 | |||||||||||
| 161 | 0 | ▶ | $artist = $self->artist($artist) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 162 | unless ref $artist; # assume the user knows what he's doing | ||||||||||
| 163 | |||||||||||
| 164 | 0 | return $self->track_class->new($artist, $title, $self->data_fetcher); | |||||||||
| 165 | } | ||||||||||
| 166 | |||||||||||
| 167 | =head2 C<tag($name)> | ||||||||||
| 168 | |||||||||||
| 169 | Returns an L<WebService::Audioscrobbler::Tag> object constructed using the given | ||||||||||
| 170 | C<$name>. Note that this call doesn't actually check if the tag exists since no | ||||||||||
| 171 | remote calls are dispatched - the object is only constructed. | ||||||||||
| 172 | |||||||||||
| 173 | =cut | ||||||||||
| 174 | |||||||||||
| 175 | 0 | ▶ | sub tag { | ||||||||
|
Subroutine
tag: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 176 | 0 | my ($self, $tag) = @_; | |||||||||
| 177 | 0 | return $self->tag_class->new($tag, $self->data_fetcher); | |||||||||
| 178 | } | ||||||||||
| 179 | |||||||||||
| 180 | =head2 C<user($name)> | ||||||||||
| 181 | |||||||||||
| 182 | Returns an L<WebService::Audioscrobbler::User> object constructed using the given | ||||||||||
| 183 | C<$name>. Note that this call doesn't actually check if the user exists since no | ||||||||||
| 184 | remote calls are dispatched - the object is only constructed. | ||||||||||
| 185 | |||||||||||
| 186 | =cut | ||||||||||
| 187 | |||||||||||
| 188 | 0 | ▶ | sub user { | ||||||||
|
Subroutine
user: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 189 | 0 | my ($self, $user) = @_; | |||||||||
| 190 | 0 | return $self->user_class->new($user, $self->data_fetcher); | |||||||||
| 191 | } | ||||||||||
| 192 | |||||||||||
| 193 | =head1 AUTHOR | ||||||||||
| 194 | |||||||||||
| 195 | Nilson Santos Figueiredo Junior, C<< <nilsonsfj at cpan.org> >> | ||||||||||
| 196 | |||||||||||
| 197 | =head1 BUGS | ||||||||||
| 198 | |||||||||||
| 199 | Please report any bugs or feature requests to | ||||||||||
| 200 | C<bug-webservice-audioscrobbler at rt.cpan.org>, or through the web interface at | ||||||||||
| 201 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WebService-Audioscrobbler>. | ||||||||||
| 202 | I will be notified, and then you'll automatically be notified of progress on | ||||||||||
| 203 | your bug as I make changes. | ||||||||||
| 204 | |||||||||||
| 205 | =head1 SUPPORT | ||||||||||
| 206 | |||||||||||
| 207 | You can find documentation for this module with the perldoc command. | ||||||||||
| 208 | |||||||||||
| 209 | perldoc WebService::Audioscrobbler | ||||||||||
| 210 | |||||||||||
| 211 | You can also look for information at: | ||||||||||
| 212 | |||||||||||
| 213 | =over 4 | ||||||||||
| 214 | |||||||||||
| 215 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||
| 216 | |||||||||||
| 217 | L<http://annocpan.org/dist/WebService-Audioscrobbler> | ||||||||||
| 218 | |||||||||||
| 219 | =item * CPAN Ratings | ||||||||||
| 220 | |||||||||||
| 221 | L<http://cpanratings.perl.org/d/WebService-Audioscrobbler> | ||||||||||
| 222 | |||||||||||
| 223 | =item * RT: CPAN's request tracker | ||||||||||
| 224 | |||||||||||
| 225 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=WebService-Audioscrobbler> | ||||||||||
| 226 | |||||||||||
| 227 | =item * Search CPAN | ||||||||||
| 228 | |||||||||||
| 229 | L<http://search.cpan.org/dist/WebService-Audioscrobbler> | ||||||||||
| 230 | |||||||||||
| 231 | =back | ||||||||||
| 232 | |||||||||||
| 233 | =head1 COPYRIGHT & LICENSE | ||||||||||
| 234 | |||||||||||
| 235 | Copyright 2006-2007 Nilson Santos Figueiredo Junior, all rights reserved. | ||||||||||
| 236 | |||||||||||
| 237 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 238 | under the same terms as Perl itself. | ||||||||||
| 239 | |||||||||||
| 240 | B<NOTE>: The datafeed from audioscrobbler.net is for | ||||||||||
| 241 | I<non-commercial use only>. Please see | ||||||||||
| 242 | L<http://www.audioscrobbler.net/data/webservices/> for | ||||||||||
| 243 | more licensing information. | ||||||||||
| 244 | |||||||||||
| 245 | =head1 SEE ALSO | ||||||||||
| 246 | |||||||||||
| 247 | =over 4 | ||||||||||
| 248 | |||||||||||
| 249 | =item * L<http://www.audioscrobbler.net/data/webservices/> and L<http://www.last.fm/> | ||||||||||
| 250 | |||||||||||
| 251 | =item * L<WebService::LastFM::SimilarArtists>, L<WebServices::LastFM>, L<Audio::Scrobbler> | ||||||||||
| 252 | |||||||||||
| 253 | =item * L<LWP::Simple>, L<XML::Simple>, L<Cache::FileCache>, L<URI> | ||||||||||
| 254 | |||||||||||
| 255 | =back | ||||||||||
| 256 | |||||||||||
| 257 | =cut | ||||||||||
| 258 | |||||||||||
| 259 | 1 | 1; # End of WebService::Audioscrobbler | |||||||||