Browse Source

Moved most stuff into a class, added $ENV{HOME} to default file path.

master
Brennen Bearnes 16 years ago
parent
commit
e0e35e51fb
1 changed files with 61 additions and 0 deletions
  1. +61
    -0
      Rhythmbox/Playlist.pm

+ 61
- 0
Rhythmbox/Playlist.pm View File

@ -0,0 +1,61 @@
package Rhythmbox::Playlist;
use strict;
use warnings;
use XML::Simple;
use URI::Escape qw(uri_unescape);
sub new {
my $class = shift;
my %params = @_;
my $self = \%params;
bless $self, $class;
$self->read_file();
return $self;
}
sub read_file {
my $self = shift;
# Get XML data:
my $xml = new XML::Simple;
my $data = $xml->XMLin($self->{file});
$self->{playlists} = $data->{playlist};
}
sub lists {
my $self = shift;
my ($pattern) = @_;
my @names = keys %{ $self->{playlists} };
return sort grep { m/$pattern/ } @names;
}
sub songs {
my $self = shift;
my ($pattern) = @_;
my @names = grep { m/$pattern/ }
keys %{ $self->{playlists} };
my @songs;
foreach my $name (@names) {
my $locations = $self->{playlists}->{$name}{'location'};
next unless defined $locations;
push @songs, (ref($locations) ? @{ $locations } : $locations);
}
@songs = sort grep { m/$self->{song_pattern}/ } @songs;
unless ($self->{raw_uri}) {
foreach my $song (@songs) {
$song =~ s{ (?:file|smb|ssh|sftp) :// (.*) }{$1}x;
$song = uri_unescape($song);
}
}
return @songs;
}
1;

|||||||
x
 
000:0
Loading…
Cancel
Save