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.

97 lines
1.8 KiB

15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
  1. #!/usr/bin/perl
  2. =pod
  3. =head1 NAME
  4. playlist.pl - Get file paths for rhythmbox playlists.
  5. =head1 SYNOPSIS
  6. ./playlist.pl [pattern]
  7. ./playlist.pl --list [pattern]
  8. ./playlist.pl --file path/to/playlists.xml
  9. =head1 OPTIONS
  10. =over
  11. =item B<--list [pattern]>
  12. Show available playlists, optionally restricted to those matching some regex.
  13. =item B<--song-pattern pattern>
  14. Restrict song URIs to those matching some pattern. Defaults to "file://".
  15. =item B<--raw-uri>
  16. Print a full URI, undecoded.
  17. =item B<--file filename>
  18. Specify a playlists.xml file.
  19. =back
  20. =head1 DESCRIPTION
  21. Worse is better, baby.
  22. This started at around 12 lines with a couple of regexen, and you could
  23. probably get most of it down to a one-liner without much trouble. I decided to
  24. add a couple of extra options instead.
  25. =head1 BUGS
  26. Are you kidding? I'd be shocked if this worked anywhere besides my laptop.
  27. =head1 AUTHOR
  28. Brennen Bearnes <bbearnes@gmail.com>
  29. http://p1k3.com/
  30. No Copyright
  31. =cut
  32. use strict;
  33. use warnings;
  34. use 5.10.00;
  35. use Rhythmbox::Playlist;
  36. use Getopt::Long qw(:config auto_help);
  37. # Set a few defaults:
  38. my %options = (
  39. file => "$ENV{HOME}/.gnome2/rhythmbox/playlists.xml",
  40. 'song_pattern' => 'file://',
  41. );
  42. my $list = undef;
  43. my $raw_uri = undef;
  44. GetOptions(
  45. 'file=s' => \$options{'file'},
  46. 'song-pattern=s' => \$options{'song_pattern'},
  47. 'list' => \$list,
  48. 'raw-uri' => \$raw_uri,
  49. );
  50. my $lists = Rhythmbox::Playlist->new(%options);
  51. # Take patterns from whatever's left in arguments:
  52. my @patterns = @ARGV;
  53. $patterns[0] //= '.*';
  54. for my $pattern (@patterns) {
  55. if ($list) {
  56. print join "\n", $lists->lists($pattern);
  57. } else {
  58. if ($raw_uri) {
  59. print join "\n", $lists->songs($pattern);
  60. } else {
  61. print join "\n", $lists->songs_decoded($pattern);
  62. }
  63. }
  64. }