If there are non utf8 caracters in the ID3 tags of a file FFPC return an empty value of tag instead of the tag value returned by getid3.

I've made a modif on ffpc_plugin_row_podcast.inc, dirty one but works for me just assign an utf8_encode() to all $info['tags']['id3v2'] values.

Because the file id3 tags could be utf8 and to prevent an double uft8 encoding I used the following function in the ffpc_plugin_row_podcast to be able to know if the id3 tag value is an utf8 string or not :

	function VerifyUtf8($str)
	{
	        $nLength = strlen($str);
	        $iDst = 0;
	        $nByteSequence = 0;
	        $nUcs4 = 0;

	        for($iSrc = 0; $iSrc < $nLength; ++$iSrc)
	        {
	  $nByte = ord($str[$iSrc]);

	  if( $nByteSequence == 0)
	  {
	         $nUcs4 = 0;

	         if( $nByte <= 0x7F)
	         {
	    // ascii
	    $iDst++;
	         }
	         else if( ($nByte & 0xE0) == 0xC0)
	         {
	    // 110xxxxx 10xxxxxx
	    $nUcs4 = $nByte & 0x1F;
	    $nByteSequence = 1;
	         }
	         else if( ($nByte & 0xF0) == 0xE0)
	         {
	    // 1110xxxx 10xxxxxx 10xxxxxx
	    $nUcs4 = $nByte & 0x0F;
	    $nByteSequence = 2;
	         }
	         else if( ($nByte & 0xF8) == 0xF0)
	         {
	    // 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
	    $nUcs4 = $nByte & 0x07;
	    $nByteSequence = 3;
	         }
	         else if( ($nByte & 0xFC) == 0xF8)
	         {
	    // 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
	    $nUcs4 = $nByte & 0x03;
	    $nByteSequence = 4;
	         }
	         else if( ($nByte & 0xFE) == 0xFC)
	         {
	    // 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
	    $nUcs4 = $nByte & 0x01;
	    $nByteSequence = 5;
	         }
	         else
	         {
	    // Bad byte sequence starter
	    $strBeg = substr($str, 0, $iSrc);
	    $strBeg = XhtmlSpecialChars($strBeg);
	    //echo "<p>$strBeg &lt;-- BAD UTF-8 SEQUENCE STARTER</p>";
	    return false;
	         }
	  }
	  else
	  {
	         // Remaining bytes
	         if( ($nByte & 0xC0) != 0x80)
	         {
	    // Bad byte in sequence
	    $strBeg = substr($str, 0, $iSrc);
	    $strBeg = XhtmlSpecialChars($strBeg);
	    //echo "<p>$strBeg &lt;-- BAD UTF-8 SEQUENCE BYTE</p>";
	    return false;
	         }

	         $nUcs4 <<= 6;
	         $nUcs4 |= ($nByte & 0x3F);
	         $nByteSequence--;

	         if( $nByteSequence == 0)
	         {
	    // OK - Store
	    //nUcs4
	    $iDst++;
	         }
	  }
	        }
	        return true;
	}

which allow to use this test :

'value' => ($this->VerifyUtf8($info['tags']['id3v2']['artist'][0]) ? $info['tags']['id3v2']['artist'][0] : uf8_encode($info['tags']['id3v2']['artist'][0])),

if you have ideas to clean this dirty code, you're welcome !

Comments

renoproc’s picture

Title: FFPC do not accept accents » FFPC do not accept non utf8 characters

Update,

for the encoding detection, there is a special getid3 tag for that : with $info = $getid3->analyze($file['filepath']); an 'encoding' key is available in $info. In my case I've $info['encoding'] = "ISO-8859-1"

mfer’s picture

What about using one of the drupal core utf8 functions?

http://api.drupal.org/api/search/6/utf8

renoproc’s picture

yep that's the best way :)

an update of ffpc module with this utf8 verification/conversion update could be really cool.