As promised, here's my old script which still works perfectly to prepare
a playlist for LMS. It reads a full directory of m3u files and
modifies/copies all of them into a directory MODDED so the originals are
untouched. 

I keep all my files for tagging purposes on a Win 10 machine. My LMS is
on a Ubuntu machine with an external HD so the file paths are modded by
this script from Win to Linux as a bonus - you may not need this kind of
thing. The main thing is the call to  *uri_escape_utf8($line,
"\x00-\x1f\x7f-\xff");* which escapes all control chars and hi-bit
chars. I'm not sure if my BOM character << print OUT "&#65279;"; #BOM >>
will survive being posted on the forum but there is a BOM marker in
there that displays correctly in VS Code.


Code:
--------------------
    
  #!/bin/perl
  
  # Modifies a playlist to URI-escape control and hi-bit characters for LMS
  # (c) philchillbill 2012
  
  use URI::Escape;
  use locale;
  
  my $c = 0;
  my @files = glob "*.m3u"; 
  my $p = scalar(@files);
  mkdir('MODDED');
  
  # 
  my $original = "D:\\My Music\\";
  my $target = "file:///seagate/music/";
  
  foreach my $file (@files) {
  
  open(IN, $file); @lines = <IN>; chomp(@lines); close(IN);
  
  my @processed = ();
  foreach my $line (@lines) {
  $line =~ s/^\Q$original\E//;
  $line=~s|\\|/|g;
  if ($line =~ /^#/) {
  $line =~ s/(#EXTINF:\d+,)/\1 /;
  } else {
  $c++;
  my $modified = uri_escape_utf8($line, "\x00-\x1f\x7f-\xff");
  $line = $target.$modified;
  }
  push(@processed, $line);
  }
  
  my $mfile = '.\\MODDED\\'.$file; 
  open(OUT, '>', $mfile);
  binmode(OUT, ":utf8");
  print OUT "&#65279;"; #BOM
  print OUT "#CURTRACK 0\n";
  foreach my $line (@processed) { print OUT "$line\n" };
  close(OUT);
  }
  
  print "\nFinished. Processed $c songs in $p playlists\n";
  
  sleep 2;
  
--------------------


------------------------------------------------------------------------
philchillbill's Profile: http://forums.slimdevices.com/member.php?userid=68920
View this thread: http://forums.slimdevices.com/showthread.php?t=114635

_______________________________________________
Squeezecenter mailing list
Squeezecenter@lists.slimdevices.com
http://lists.slimdevices.com/mailman/listinfo/squeezecenter

Reply via email to