a little bit of hacky Perl to pull filenames out of Rhythmbox's playlists.xml
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.2 KiB

  1. package Rhythmbox::Playlist;
  2. use strict;
  3. use warnings;
  4. use XML::Simple;
  5. use URI::Escape qw(uri_unescape);
  6. sub new {
  7. my $class = shift;
  8. my %params = @_;
  9. my $self = \%params;
  10. bless $self, $class;
  11. $self->read_file();
  12. return $self;
  13. }
  14. sub read_file {
  15. my $self = shift;
  16. # Get XML data:
  17. my $xml = new XML::Simple;
  18. my $data = $xml->XMLin($self->{file});
  19. $self->{playlists} = $data->{playlist};
  20. }
  21. sub lists {
  22. my $self = shift;
  23. my ($pattern) = @_;
  24. my @names = keys %{ $self->{playlists} };
  25. return sort grep { m/$pattern/ } @names;
  26. }
  27. sub songs_decoded {
  28. my $self = shift;
  29. my @songs = $self->songs(@_);
  30. foreach my $song (@songs) {
  31. $song =~ s{ (?:file|smb|ssh|sftp) :// (.*) }{$1}x;
  32. $song = uri_unescape($song);
  33. }
  34. return @songs;
  35. }
  36. sub songs {
  37. my $self = shift;
  38. my ($pattern) = @_;
  39. my @names = grep { m/$pattern/ }
  40. keys %{ $self->{playlists} };
  41. my @songs;
  42. foreach my $name (@names) {
  43. my $locations = $self->{playlists}->{$name}{'location'};
  44. next unless defined $locations;
  45. push @songs, (ref($locations) ? @{ $locations } : $locations);
  46. }
  47. @songs = sort grep { m/$self->{song_pattern}/ } @songs;
  48. return @songs;
  49. }
  50. 1;