Apache-iTunes

 view release on metacpan or  search on metacpan

lib/Apache/iTunes.pm  view on Meta::CPAN


=back

=head2 Environment variables

=over 4

=item APACHE_ITUNES_URL

The URL to the mod_perl handler so it can reference itself.

=item APACHE_ITUNES_HTML

The location of the template file.

=back

=head1 TO DO

* even though this is mod_perl, Mac::iTunes is still pretty slow.
when i get to the optimization stage, Mac::iTunes will get faster
and so will this.

=head1 SOURCE AVAILABILITY

This source is in GitHub

	https://github.com/CPAN-Adopt-Me/Apache-iTunes

=head1 AUTHOR

This module is currently unmaintained. If you want to take over
the care and feeding, write to modules@perl.org.

brian d foy, C<< <bdfoy@cpan.org> >>

=head1 COPYRIGHT AND LICENSE

Copyright (c) 2002-2007, brian d foy, All Rights Reserved.

You may redistribute this under the same terms as Perl itself.

=cut

# share these among all mod_perl children and from
# request to request
use vars qw( $Playlist $Controller %Commands %Set $Volume );

$Playlist      = 'Library';
$Controller    = Mac::iTunes->new()->controller;
%Commands      = map { $_, 1 }
	qw( play stop pause back_track next previous );
%Set           = map { $_, 1 }
	qw( playlist );
$Volume        = $Controller->volume;

sub handler
	{
	my $r = shift;

	my( undef, $command, @path_info )= split m|/|, ( $r->path_info || '' );
	$command = '' unless $command; # silence warning
	@path_info = map { unescape_uri( $_ ) } @path_info;

	my %params = $r->args;

	if( exists $Commands{ $command } )
		{
		$Controller->$command;
		}
	elsif( $command eq 'playlist' and defined $path_info[0]
		and $Controller->playlist_exists( $path_info[0] ) )
		{
		$Controller->set_playlist( $path_info[0] );
		$Playlist = $path_info[0];
		}
	elsif( $command eq 'track' )
		{
		my $number = int( $path_info[0] || 0 );
		$path_info[1] = $Playlist unless $path_info[1];
		my $Playlist = $path_info[1]
			if $Controller->playlist_exists( $path_info[1] );
		$Controller->play_track( $number, $Playlist );
		}
	elsif( $command eq 'volume' )
		{
		my $volume = $path_info[0];
		$volume = $volume > 100 ? 100 : $volume < 0 ? 0 : $volume;
		$Volume = $Controller->volume( $volume );
		}

	my %var;

	$var{version}   = $VERSION;
	$var{base}      = $ENV{APACHE_ITUNES_URL};
	$var{state}     = $Controller->player_state;
	$var{current}   = $Controller->current_track_name;
	$var{playlist}  = $Playlist;
	$var{playlists} = $Controller->get_playlists;
	$var{tracks}    = $Controller->get_track_names_in_playlist( $Playlist );

	my $html = Text::Template::fill_in_file(
		$ENV{APACHE_ITUNES_HTML}, HASH => \%var );

	$r->content_type( 'text/html' );
	$r->send_http_header;
	$r->print( $html );
	return OK;
	}

"See why 1984 won't be like 1984";



( run in 1.534 second using v1.01-cache-2.11-cpan-fe3c2283af0 )