# Workaround for SqueezeCenter bug 8172: Playlists containing remote URLs # are broken. [ http://bugs.slimdevices.com/show_bug.cgi?id=8172 ] # Note that this works only for my specific case, where I use playlists as # my exclusive way to hit remote streams from the Squeezebox. I'm sure there # are dozens of edge cases this doesn't work for. This code is public domain # and unsupported, comes with no warranty express or implied, I am not # responsible if it keys your car or kicks your puppy or anything. # -- Chris Doherty # slimdevices@randomcamel.net use strict; use warnings; use DBD::mysql; use DBI; my $p_dir = shift @ARGV or die "need a playlist directory"; chdir $p_dir or die "could not chdir to $p_dir: $!"; my @playlists = qx{egrep -l -e '(http|mms)://' *m3u *pls | sort}; #print "@playlists\n"; my $dbh = DBI->connect('dbi:mysql:hostname=127.0.0.1;port=9092;database=slimserver'); FILE: for my $file (@playlists) { chomp $file; my $name = $file; next unless $name; # check for an id in TRACKS. if it's not there, no need to continue. $name =~ s/\.\w+$//; my $pl_id = $dbh->selectcol_arrayref(qq{SELECT id FROM tracks WHERE title='$name'}); $pl_id = $pl_id->[0]; if (!$pl_id) { print "Failed to find a TRACKS id for $file\n"; next; } # extract URLs from the file. my @urls; open F, $file or warn "could not open $file: $!" and next; LINE: while () { next if /^\s*#/; if ( m#://# ) { chomp; s/^File\d*=//; push @urls, $_; } } close F or warn "WTF, close failed: $!"; my $pos = 0; for my $url ( @urls ) { $dbh->do( qq{INSERT INTO tracks (url) VALUES ('$url')} ); my $track_id = $dbh->selectcol_arrayref('SELECT max(id) FROM tracks'); $track_id = $track_id->[0]; $dbh->do( qq{INSERT INTO playlist_track (position, playlist, track) VALUES ($pos, $pl_id, $track_id)} ); $pos++; } }