@bupkes: With pleasure! :) It's small enough that I'll just paste it
here in this post... Yes I did contact Predixis about this and they
told me that there would have to be more interest about it, so feel
free to go "bug" them about it! ;)

@biggles: Glad to know I'm not the only one! :)

Without further ado, here's my script named conv_pl.pl (for convert
playlist):

-------------------------------------
#!/usr/bin/perl

use IO::Socket;

my $src_dir, $dst_dir, $pl_fspec, $win_root, $music_root;
my $server_ip, $server_cli;
my $delay, $timeout = 30;
my $terminate = 0;

my $init = $ARGV[0];

# Signal handlers
$SIG{TERM} = \&StopProc;
$SIG{INT}  = \&StopProc;

# Read init parameters
ReadInit($init);

# Initially check files after delay
$delay = 30;

until ($terminate)
{
if (--$delay > 0)
{
sleep 1;  # Allows aborting process while waiting
next;
}
else
{
$delay = $timeout;
}

if (<$src_dir/$pl_fspec>)
{
while (<$src_dir/$pl_fspec>)
{
s#.*/##;  # Only keep file name
ProcessPL($_);
}
SlimRescanPL();
}
}


#
# Function ReadInit
#
sub ReadInit
{
my $init = $_[0];
my %user_preferences;

open(CONFIG, "< $init") or die "Config file $init not found.\n";

while (<CONFIG>) 
{
chomp;                  # no newline
s/#.*//;                # no comments
s/^\s+//;               # no leading white
s/\s+$//;               # no trailing white
next unless length;     # anything left?
my ($var, $value) = split(/\s*=\s*/, $_, 2);
$user_preferences{$var} = $value;
}
close(CONFIG);

$src_dir    = $user_preferences{"src_dir"} or die "src_dir not
defined.";
$dst_dir    = $user_preferences{"dst_dir"} or die "dst_dir not
defined.";
$pl_fspec   = $user_preferences{"pl_fspec"} or die "pl_fspec not
defined.";
$win_root   = $user_preferences{"win_root"} or die "win_root not
defined.";
$music_root = $user_preferences{"music_root"} or die "music_root not
defined.";
$server_ip  = $user_preferences{"server_ip"};
$server_cli = $user_preferences{"server_cli"};

$win_root =~ s#\\#\\\\#g;  # Change '\' to '\\' to avoid special
meaning
}


#
# Function StopProc
#
sub StopProc
{
$terminate = 1;
}


#
# Function ProcessPL
#
sub ProcessPL
{
my $fname = $_[0];

open(IN, "< $src_dir/$fname") 
or die "Unable to open $src_dir/$fname for reading\n";

open(OUT, "> $dst_dir/$fname") 
or die "Unable to open $dst_dir/$fname for writing\n";

print OUT "\xef\xbb\xbf#CURTRACK 0\n";
while (<IN>)
{
chomp;
s/\r//;  # Remove any Cr from DOS files
if (/^$win_root/)
{
s#^$win_root#$music_root#;  # Change DOS to Linux roots
s#\\#/#g;  # Replace all '\' by '/'
}
elsif (/^#EXTINF:/)
{
s/:\d+,/:-1,/;  # Change number to -1 for slimserver compat
}

print OUT "$_\n";
}

close(IN);
close(OUT);

if (-s "$dst_dir/$fname")
{
unlink("$src_dir/$fname") or die "Could not delete
$src_dir/$fname\n";
}
}


#
# Function SlimRescanPL
#
sub SlimRescanPL
{
if ($server_ip and $server_cli)
{
# Try to open a connection to the SlimServer CLI
my $socket = IO::Socket::INET->new(PeerAddr => $server_ip,
PeerPort => $server_cli,
Proto => "tcp",
Type => SOCK_STREAM);

# Check if socket was opened successfully
if (defined($socket)) 
{
SendAndReceive("rescan playlists");

close($socket);
}
}
}


#
# Function SendAndReceive
#
sub SendAndReceive
{
my $cmd = $_[0];
return if ($cmd eq "");

print $socket "$cmd\n";
my $answer = <$socket>;
$answer =~ s/$cmd //i;
$answer =~ s/\n//;

return $answer;
}
-------------------------------------


And also the .ini file: (conv_pl.ini)
-------------------------------------
#
# Config file for conv_pl.pl MusicMagic to SlimServer playlist
converter
#

# Source directory where to get generated MMM playlist
src_dir = /mnt/music/_playlists

# Destination directory where to put converted playlist for SlimServer
dst_dir = /home/slimserver/playlists

# Playlist filespec to process
pl_fspec = *.m3u

# Windows root for music repository
win_root = M:

# SlimServer root for music repository
music_root = /mnt/music

# SlimServer IP address
server_ip = 192.168.1.4

# SlimServer CLI port address
server_cli = 9090
-------------------------------------

I'm at work right now so I don't have access to all my files but if
you'd like, I can host the files somewhere with the included startup
files for the LinkStation and all...

Daniel


-- 
dborn
------------------------------------------------------------------------
dborn's Profile: http://forums.slimdevices.com/member.php?userid=181
View this thread: http://forums.slimdevices.com/showthread.php?t=22522

_______________________________________________
plugins mailing list
[email protected]
http://lists.slimdevices.com/lists/listinfo/plugins

Reply via email to