Skip to content

Commit

Permalink
Adding the ability to add individual songs to the playlist
Browse files Browse the repository at this point in the history
  • Loading branch information
reyjrar committed Jun 24, 2012
1 parent 7f99345 commit cdb61ec
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/MusicManager.pm
Expand Up @@ -66,6 +66,7 @@ sub startup {
$r->route('/library')->to('library#artists'); $r->route('/library')->to('library#artists');
$r->route('/library/artists')->to('library#artists'); $r->route('/library/artists')->to('library#artists');
$r->route('/library/artist/:artist')->to('library#artist'); $r->route('/library/artist/:artist')->to('library#artist');
$r->route('/library/album/:album')->to('library#album');


# Now Playing # Now Playing
$r->route('/nowplaying/add/artist/:artist')->to(controller => 'NowPlaying', action => 'add_artist'); $r->route('/nowplaying/add/artist/:artist')->to(controller => 'NowPlaying', action => 'add_artist');
Expand Down
13 changes: 13 additions & 0 deletions lib/MusicManager/Controller/Library.pm
Expand Up @@ -22,4 +22,17 @@ sub artist {
$self->render(); $self->render();
} }


sub album {
my $self = shift;

# Grab the artist
my $album = $self->stash('album');

my @songs = sort mm_sort_smart $self->app->mpd->collection->songs_from_album( $album );
$self->stash( songs => \@songs );

$self->render();
}


1; 1;
5 changes: 5 additions & 0 deletions lib/MusicManager/Controller/NowPlaying.pm
Expand Up @@ -111,6 +111,11 @@ sub replace_artist_album {
$self->redirect_to('/'); $self->redirect_to('/');
} }


sub add_song {
my $self = shift;
my $mpd = $self->app->mpd;
}

sub del_song { sub del_song {
my $self = shift; my $self = shift;
my $id = $self->stash('song_id'); my $id = $self->stash('song_id');
Expand Down
11 changes: 10 additions & 1 deletion lib/MusicManager/Model/Files.pm
Expand Up @@ -6,7 +6,7 @@ use File::Find::Rule;


has 'media_dir'; has 'media_dir';


my %_valid_media_exts = map { $_ => 1 } qw(mp3 ogg aac); my %_valid_media_exts = map { $_ => 1 } qw(mp3 Mp3 MP3 ogg OGG aac AAC);


sub songs_from_path { sub songs_from_path {
my ($self,@dirs) = @_; my ($self,@dirs) = @_;
Expand All @@ -20,3 +20,12 @@ sub songs_from_path {


return wantarray ? @files : \@files; return wantarray ? @files : \@files;
} }

sub song_at {
my ($self,$path) = @_;

my @path = File::Spec->split_path( $path );
my @safe = File::Spec->no_upwards( @path );
my $safe_path = File::Spec->catfile( @safe );

}
26 changes: 26 additions & 0 deletions templates/library/album.html.ep
@@ -0,0 +1,26 @@
% layout 'default';
% title "MusicManager :: Album :: $album";

<table class="table">
<thead>
<tr>
<th>Arist</th>
<th>Album</th>
<th>Title</th>
<th>Functions</th>
</tr>
</thead>
<tbody>
% foreach my $song (@$songs) {
% my $song_id = $song->file;
<tr>
<td><%== $song->artist %></td>
<td><%== $song->album %></td>
<td><%== $song->title %></td>
<td><a href="<%= url_for "/nowplaying/add/song/$song_id" %>"
class="btn btn-success"><i class="icon-plus icon-white"></i> add song</a>
</td>
</tr>
% }
</tbody>
</table>
2 changes: 1 addition & 1 deletion templates/library/artist.html.ep
Expand Up @@ -18,7 +18,7 @@
class="btn btn-success"><i class="icon-plus icon-white"></i> add album</a> class="btn btn-success"><i class="icon-plus icon-white"></i> add album</a>
<a href="<%= url_for "/nowplaying/replace/album/$artist/$album" %>" <a href="<%= url_for "/nowplaying/replace/album/$artist/$album" %>"
class="btn btn-primary"><i class="icon-play icon-white"></i> play album</a> class="btn btn-primary"><i class="icon-play icon-white"></i> play album</a>
<a href="<%= url_for "/library/album/$artist" %>" <a href="<%= url_for "/library/album/$album" %>"
class="btn"><i class="icon-zoom-in"></i> view</a> class="btn"><i class="icon-zoom-in"></i> view</a>
</td> </td>
</tr> </tr>
Expand Down

0 comments on commit cdb61ec

Please sign in to comment.