POE::Component::Client::MPD::Playlist - module handling playlist commands


POE-Component-Client-MPD documentation Contained in the POE-Component-Client-MPD distribution.

Index


Code Index:

NAME

Top

POE::Component::Client::MPD::Playlist - module handling playlist commands

VERSION

Top

version 1.100430

DESCRIPTION

Top

POE::Component::Client::MPD::Playlist is responsible for handling general purpose commands. They are in a dedicated module to achieve easier code maintenance.

To achieve those commands, send the corresponding event to the POCOCM session you created: it will be responsible for dispatching the event where it is needed. Under no circumstance should you call directly subs or methods from this module directly.

Read POCOCM's pod to learn how to deal with answers from those commands.

Following is a list of playlist-related events accepted by POCOCM.

RETRIEVING INFORMATION

Top

pl.as_items( )

Return an array of Audio::MPD::Common::Item::Songs, one for each of the songs in the current playlist.

pl.items_changed_since( $plversion )

Return a list with all the songs (as Audio::MPD::Common::Item::Song objects) added to the playlist since playlist $plversion.

ADDING / REMOVING SONGS

Top

pl.add( $path, $path, ... )

Add the songs identified by $path (relative to MPD's music directory) to the current playlist.

pl.delete( $number, $number, ... )

Remove song $number (starting from 0) from the current playlist.

pl.deleteid( $songid, $songid, ... )

Remove the specified $songid (as assigned by mpd when inserted in playlist) from the current playlist.

pl.clear( )

Remove all the songs from the current playlist.

pl.crop( )

Remove all of the songs from the current playlist *except* the current one.

CHANGING PLAYLIST ORDER

Top

pl.shuffle( )

Shuffle the current playlist.

pl.swap( $song1, $song2 )

Swap positions of song number $song1 and $song2 in the current playlist.

pl.swapid( $songid1, $songid2 )

Swap positions of song id $songid1 and $songid2 in the current playlist.

pl.move( $song, $newpos )

Move song number $song to the position $newpos.

pl.moveid( $songid, $newpos )

Move song id $songid to the position $newpos.

MANAGING PLAYLISTS

Top

pl.load( $playlist )

Load list of songs from specified $playlist file.

pl.save( $playlist )

Save the current playlist to a file called $playlist in MPD's playlist directory.

pl.rm( $playlist )

Delete playlist named $playlist from MPD's playlist directory.

AUTHOR

Top

  Jerome Quelin

COPYRIGHT AND LICENSE

Top


POE-Component-Client-MPD documentation Contained in the POE-Component-Client-MPD distribution.

# 
# This file is part of POE-Component-Client-MPD
# 
# This software is copyright (c) 2007 by Jerome Quelin.
# 
# This is free software; you can redistribute it and/or modify it under
# the same terms as the Perl 5 programming language system itself.
# 
use 5.010;
use strict;
use warnings;

package POE::Component::Client::MPD::Playlist;
our $VERSION = '1.100430';
# ABSTRACT: module handling playlist commands

use Moose;
use MooseX::Has::Sugar;
use POE;
use Readonly;

use POE::Component::Client::MPD::Message;


# -- attributes

has mpd => ( ro, required, weak_ref, );# isa=>'POE::Component::Client::MPD' );


# -- Playlist: retrieving information


sub _do_as_items {
    my ($self, $msg) = @_;

    $msg->_set_commands ( [ 'playlistinfo' ] );
    $msg->_set_cooking  ( 'as_items' );
    $self->mpd->_send_to_mpd( $msg );
}



sub _do_items_changed_since {
    my ($self, $msg) = @_;
    my $plid = $msg->params->[0];

    $msg->_set_commands ( [ "plchanges $plid" ] );
    $msg->_set_cooking  ( 'as_items' );
    $self->mpd->_send_to_mpd( $msg );
}


# -- Playlist: adding / removing songs



sub _do_add {
    my ($self, $msg) = @_;

    my $args   = $msg->params;
    my @pathes = @$args;         # args of the poe event
    my @commands = (             # build the commands
        'command_list_begin',
        map( qq{add "$_"}, @pathes ),
        'command_list_end',
    );
    $msg->_set_commands ( \@commands );
    $msg->_set_cooking  ( 'raw' );
    $self->mpd->_send_to_mpd( $msg );
}



sub _do_delete {
    my ($self, $msg) = @_;

    my $args    = $msg->params;
    my @numbers = @$args;
    my @commands = (              # build the commands
        'command_list_begin',
        map( qq{delete $_}, reverse sort {$a<=>$b} @numbers ),
        'command_list_end',
    );
    $msg->_set_commands ( \@commands );
    $msg->_set_cooking  ( 'raw' );
    $self->mpd->_send_to_mpd( $msg );
}



sub _do_deleteid {
    my ($self, $msg) = @_;

    my $args    = $msg->params;
    my @songids = @$args;
    my @commands = (              # build the commands
        'command_list_begin',
        map( qq{deleteid $_}, @songids ),
        'command_list_end',
    );
    $msg->_set_commands ( \@commands );
    $msg->_set_cooking  ( 'raw' );
    $self->mpd->_send_to_mpd( $msg );
}



sub _do_clear {
    my ($self, $msg) = @_;

    $msg->_set_commands ( [ 'clear' ] );
    $msg->_set_cooking  ( 'raw' );
    $self->mpd->_send_to_mpd( $msg );
}



sub _do_crop {
    my ($self, $msg) = @_;

    if ( not defined $msg->_data ) {
        # no status yet - fire an event
        $msg->_set_post( 'pl.crop' );
        $self->mpd->_dispatch('status', $msg);
        return;
    }

    # now we know what to remove
    my $cur = $msg->_data->song;
    my $len = $msg->_data->playlistlength - 1;
    my @commands = (
        'command_list_begin',
        map( { $_ != $cur ? "delete $_" : '' } reverse 0..$len ),
        'command_list_end'
    );

    $msg->_set_cooking  ( 'raw' );
    $msg->_set_commands ( \@commands );
    $self->mpd->_send_to_mpd( $msg );
}


# -- Playlist: changing playlist order



sub _do_shuffle {
    my ($self, $msg) = @_;

    $msg->_set_cooking  ( 'raw' );
    $msg->_set_commands ( [ 'shuffle' ] );
    $self->mpd->_send_to_mpd( $msg );
}



sub _do_swap {
    my ($self, $msg) = @_;
    my ($from, $to) = @{ $msg->params }[0,1];

    $msg->_set_cooking  ( 'raw' );
    $msg->_set_commands ( [ "swap $from $to" ] );
    $self->mpd->_send_to_mpd( $msg );
}



sub _do_swapid {
    my ($self, $msg) = @_;
    my ($from, $to) = @{ $msg->params }[0,1];

    $msg->_set_cooking  ( 'raw' );
    $msg->_set_commands ( [ "swapid $from $to" ] );
    $self->mpd->_send_to_mpd( $msg );
}



sub _do_move {
    my ($self, $msg) = @_;
    my ($song, $pos) = @{ $msg->params }[0,1];

    $msg->_set_cooking  ( 'raw' );
    $msg->_set_commands ( [ "move $song $pos" ] );
    $self->mpd->_send_to_mpd( $msg );
}



sub _do_moveid {
    my ($self, $msg) = @_;
    my ($songid, $pos) = @{ $msg->params }[0,1];

    $msg->_set_cooking  ( 'raw' );
    $msg->_set_commands ( [ "moveid $songid $pos" ] );
    $self->mpd->_send_to_mpd( $msg );
}


# -- Playlist: managing playlists



sub _do_load {
    my ($self, $msg) = @_;
    my $playlist = $msg->params->[0];

    $msg->_set_cooking  ( 'raw' );
    $msg->_set_commands ( [ qq{load "$playlist"} ] );
    $self->mpd->_send_to_mpd( $msg );
}



sub _do_save {
    my ($self, $msg) = @_;
    my $playlist = $msg->params->[0];

    $msg->_set_cooking  ( 'raw' );
    $msg->_set_commands ( [ qq{save "$playlist"} ] );
    $self->mpd->_send_to_mpd( $msg );
}



sub _do_rm {
    my ($self, $msg) = @_;
    my $playlist = $msg->params->[0];

    $msg->_set_cooking  ( 'raw' );
    $msg->_set_commands ( [ qq{rm "$playlist"} ] );
    $self->mpd->_send_to_mpd( $msg );
}


no Moose;
__PACKAGE__->meta->make_immutable;
1;



__END__