I just noticed a problem with the encoding of the artists name int the
sid muscis. They use some special characters like this:


Code:
--------------------
    
  | Title        : So Alone                              |
  | Author       : Johan Åstrand (Zyron)                 |
  | Released     : 1996 Oxsid Planetary                  |
  +------------------------------------------------------+
  | Playlist     : 1/1 (tune 1/1[1])                     |
  | Song Length  : 03:30                                 |
  +------------------------------------------------------+
  Creating audio file, please wait...
  2005-11-15 15:28:39.0617 Malformed UTF-8 character (unexpected 
non-continuation byte 0x73, immediately after start byte 0xc5) in unpack at 
/home/slimserver/Slim/Display/Graphics.pm line 192.
  
--------------------


I guess I should convert from latin to UTF-8 before assigning the
string to the tags.

I found this code somewhere in the checkins I'll see if that help if I
use it on the strings. Wow it worked. I'm rescanning my entire library
which takes a bit of time. Here's the new and imporved Sid.pm:


Code:
--------------------
    
  package Slim::Formats::Sid;
  
  # SlimServer Copyright (c) 2001-2004 Sean Adams, Slim Devices Inc.
  # This program is free software; you can redistribute it and/or
  # modify it under the terms of the GNU General Public License,
  # version 2.
  
  # Written by WildCoder (who still don't know perl)
  # to play C64 Sid musics in slimserver
  # Last modification 2005-11-15
  
  use strict;
  
  # Given a file, return a hash of name value pairs,
  # where each name is a tag name.
  sub getTag {
  
  my $file = shift || "";
  
  my $filesize = -s $file;
  
  $::d_formats && msg( "Opening SID information for $file\n");
  
  # Make sure the file exists.
  return undef unless $filesize && -r $file;
  
  $::d_formats && msg( "Reading SID information for $file\n");
  
  my $tags = {};
  
  my $f;
  my $signature;
  
  open $f, "<$file" || return undef;
  
  $::d_formats && msg( "Checking SID header for $file\n");
  
  return undef if read($f, $signature, 4) < 4;
  return undef if ($signature ne 'PSID');
  
  my $chunkpos = 22;
  return undef unless seek($f, $chunkpos, 0);
  
  my $songname;
  my $artist;
  my $album;
  my $year;
  my $filer;
  
  return undef if read($f, $songname, 32) < 32;
  return undef if read($f, $artist, 32) < 32;
  return undef if read($f, $year, 4) < 4;
  return undef if read($f, $filer, 1) < 1;
  return undef if read($f, $album, 27) < 27;
  
  # Settings that sidplay2 uses to convert the sid tune (matches what's in 
convert.conf)
  
  my $endian           = 0; # little-endian
  my $numChannels      = 2; # Stereo.
  my $sampleSize       = 16;
  my $samplesPerSecond = 44100;
  my $numSampleFrames  = $samplesPerSecond * ((3 * 60)+30); # Default to 3:30 
minutes like sidplay2 output
  # This tags appears to be the minimum require to get it to work
  
  $tags->{'ENDIAN'}     = $endian;
  $tags->{'FS'}         = $filesize;
  $tags->{'CHANNELS'}   = $numChannels;
  $tags->{'SAMPLESIZE'} = $sampleSize;
  $tags->{'SIZE'}       = $numSampleFrames * $numChannels * $sampleSize / 8;
  $tags->{'OFFSET'}     = 0;
  $tags->{'RATE'}       = $samplesPerSecond;
  $tags->{'BITRATE'}    = $samplesPerSecond * $numChannels * $sampleSize;
  $tags->{'SECS'}       = $numSampleFrames / $samplesPerSecond;
  $tags->{'BLOCKALIGN'} = $numChannels * $sampleSize / 8;
  
  # These tags just make it look nicer
  
  $tags->{'ALBUM'} = latin1toUTF8 ($album);
  $tags->{'GENRE'} = "Computer SID Music";
  $tags->{'ARTIST'} = latin1toUTF8 ($artist);
  $tags->{'TITLE'} = latin1toUTF8 ($songname);
  $tags->{'YEAR'} = $year;
  #$tags->{'TRACKNUM'} = "Doubt we'll ever have tracks unless we can track down 
some musicdiscs";
  
  return $tags;
  }
  
  sub latin1toUTF8 {
  my $data = shift;
  
  if ($] > 5.007) {
  $data = eval { Encode::encode('utf8', $data, Encode::FB_QUIET()) } || $data;
  } else {
  $data =~ s/([\x80-\xFF])/chr(0xC0|ord($1)>>6).chr(0x80|ord($1)&0x3F)/eg;
  }
  return $data;
  }
  
  1;
  
--------------------


-WildCoder


-- 
WildCoder
------------------------------------------------------------------------
WildCoder's Profile: http://forums.slimdevices.com/member.php?userid=1827
View this thread: http://forums.slimdevices.com/showthread.php?t=18221

_______________________________________________
unix mailing list
unix@lists.slimdevices.com
http://lists.slimdevices.com/lists/listinfo/unix

Reply via email to