Audio-DB
view release on metacpan or search on metacpan
DB/Util/Playlists.pm view on Meta::CPAN
# Playlists.pm provides a variety of methods for dealing with playlists.
# This includes the basics (like adding and deleting songs from playlists),
# To actual streaming of recalled playlists,
# to retrieving all playlists from all users for display
# Flow
# 1. Authenticate (either through mod_auth or by reading cookie)
# 2. Grab the user id from the cookie
# 3. Use that to do any sort of deletes or inserts...
# Handles:
# Displaying a given users list of playlists
# Retrieval of a single playlist
# Let's them add a new playlist
# NEED TO STANDARDIZE THE NAVIGATION ELEMENTS
# Lists of playlists need
# stream fetch
# Each playlist needs
# stream fetch for each song and stream fetch for whole playlist
package Audio::DB::Util::Playlists;
# $Id: Playlists.pm,v 1.2 2005/02/27 16:56:25 todd Exp $
use strict 'vars';
use CGI qw/:standard *table/;
use Audio::DB::Web;
use Audio::DB::Util::Rearrange; # Ubiquitous rearrange...
use vars qw($VERSION @ISA);
@ISA = 'Audio::DB::Web';
my $MAIN = 'My Playlists';
my $EDIT = 'images/edit.gif';
my $DELE = 'images/edit.gif';
# Need to store a dbh handle here
# as well as the user ID...
sub new {
my ($self,$dbh,$user_id) = @_;
my $this = bless { dbh => $dbh,
user_id => $user_id
},$self;
$this->process_requests();
return $this;
}
sub process_requests {
my $self = shift;
my $coderef = url_param('playlist');
# Some coderefs are actually NOT url_params, things
# like adding songs to playlists, etc
$coderef = param('todo') if param('todo');
$coderef =~ s/\s/_/g;
$self->$coderef;
# Print out the appropriate title...
# Better to do it here so that I can jump in later
DB/Util/Playlists.pm view on Meta::CPAN
# First I need to print a header for the playlist, letting user edit the name
# and shared properties.
# print
# hidden(-name=>'playlist_id',-value=>$h->{playlist_id});
# print
# TR(td(textfield({-name=>'playlist',-value=>$h->{playlist},-size=>15})),
## td(textfield({-name=>'description',-value=>$h->{description},-size=>15})),
# td(textfield({-name=>'email',-value=>$h->{created},-size=>20})),
# td(popup_menu({-name=>'is_shared',-values=>[qw/yes no/]})));
#
# $sth->execute();
# while (my $h = $sth->fetchrow_hashref) {
#
# }
print end_table;
print submit(-name=>'submit',-label=>'Update Users');
print end_div;
}
sub delete_playlist {
}
sub delete_all_playlists {
}
sub playlist_popup {
my $self = shift;
# Flow
# 1. Create the popup window
# 2. Fetch user playlists
# 3. Display form
# Processing...
# Should songs be added to new playlist?
# Creat playlist, then add songs.
# Should songs be added to existing playlist?
# Popupmen presents: view playlist or return...
# Example code for creating a javapopup window
# <script language="javascript" type="text/javascript">
# function OpenComments (c) {
# window.open('<$MTCGIPath$>mt-comments.cgi?' +
# 'entry_id=' + c,
# 'comments',
# 'width=480,height=480,scrollbars=yes,status=yes');
#}
#</script>
#
#}
}
#######################################################
# SUPPORT: Fetching, streaming, linking, navigating
#######################################################
# Fetch all the current playlists associated with
# this user and return
# This could be generalized to get lists of all playlists
# from all users
# Or perhaps that should just be a seperate sub
# Could also be modified to return a filled list
# This might actually be usefull, because then I can build the page
# from that
# Should this be a factory churning out Playlistlist objects?
sub fetch_playlists {
my ($self,@p) = @_;
my ($type,$id) = rearrange([qw/TYPE ID/],@p);
# Cases:
# 1. fetch playlists for a specific user,
# 2. Browse all playlists
# 3. fetch an individual playlist
# UI could present a popupmenu for each user
# Or alternatively, could expand them all
my $user_id = $self->{user_id};
my $dbh = $self->dbh;
# This is the flat query that simply returns all the playlists
# but does not actually list the song ids
my %queries = ( by_user => qq{select * from playlists where user_id=?},
all => qq{select * from playlists,users where
playlists.user_id=users.user_id
ORDER BY last_name},
expanded => qq{select *,count(song_id) from playlists,playlist_songs
where
playlists.user_id=?
and playlists.playlist_id=playlist_songs.playlist_id
GROUP BY playlist_id},
filled => qq{select * from playlists,playlist_songs,songs,artists,albums,genres
where
playlists.playlist_id=?
and playlists.playlist_id=playlist_songs.playlist_id
and playlist_songs.song_id=songs.song_id
and songs.artist_id=artists.artist_id
and songs.genre_id=genres.genre_id
and songs.album_id=albums.album_id});
my $results = [];
my $sth = $dbh->prepare($queries{$type});
if ($type eq 'by_user') {
$sth->execute($user_id);
} elsif ($type eq 'filled') {
# Argh! What should this be and where should it come from?
$sth->execute($id);
} elsif ($type eq 'all') {
$sth->execute();
} else {
$sth->execute();
}
my $c;
while (my $h = $sth->fetchrow_hashref) {
push (@$results,$h);
$c++;
}
return '' if $c < 1;
return $results;
}
# This will be a generic link in, and not for streaming
sub link_playlist {
my ($self,$playlist,$id) = @_;
my $url = url();
return a({-href=>$url . '?playlist=' . 'display_playlist&id=' . $id },$playlist);
}
sub stream_link {
}
# THIS CONTROLS NAVIGATIONAL FORMATTING
sub print_navigation {
my ($self,@fields) = @_;
print start_div({-class=>'actiontitle'}),
$self->build_nav_link(-class=>'playlist',-action=>'display_options',
-text=>$MAIN);
print ' / ' if (@fields);
print join (' / ',@fields);
print end_div;
}
1;
=pod
Methods:
user management
multiplaylists / user (and option to share with others)
user ratings (for songs and playlists)
browse by letter of alphabet, genre, album
Stats reporting
=head1 NAME
Apache::Audio::DB - Generate a database of your tunes complete with searchable interface and nifty statistical analyses!
=head1 SYNOPSIS
# httpd.conf or srm.conf
AddType audio/mpeg mp3 MP3
# httpd.conf or access.conf
<Location /songs>
SetHandler perl-script
PerlHandler Apache::MP3::Sorted
PerlSetVar SortFields Album,Title,-Duration
PerlSetVar Fields Title,Artist,Album,Duration
</Location>
=head1 TODO
Streaming code and links
( run in 0.871 second using v1.01-cache-2.11-cpan-39bf76dae61 )