bool CKaraokeLyricsTextLRC::Load() { XFILE::CFile file; // Clear the lyrics array clearLyrics(); if ( !file.Open( m_lyricsFile ) ) return false; unsigned int lyricSize = (unsigned int) file.GetLength(); if ( !lyricSize ) { CLog::Log( LOGERROR, "LRC lyric loader: lyric file %s has zero length", m_lyricsFile.c_str() ); return false; } // Read the file into memory array std::vector<char> lyricData( lyricSize ); file.Seek( 0, SEEK_SET ); // Read the whole file if ( file.Read( &lyricData[0], lyricSize) != lyricSize ) return false; // disk error? file.Close(); // Parse the correction value int timing_correction = MathUtils::round_int( g_advancedSettings.m_karaokeSyncDelayLRC * 10 ); unsigned int offset = 0; CStdString ext, songfilename = getSongFile(); URIUtils::GetExtension( songfilename, ext ); // Skip windoze UTF8 file prefix, if any, and reject UTF16 files if ( lyricSize > 3 ) { if ( (unsigned char)lyricData[0] == 0xFF && (unsigned char)lyricData[1] == 0xFE ) { CLog::Log( LOGERROR, "LRC lyric loader: lyrics file is in UTF16 encoding, must be in UTF8" ); return false; } // UTF8 prefix added by some windoze apps if ( (unsigned char)lyricData[0] == 0xEF && (unsigned char)lyricData[1] == 0xBB && (unsigned char)lyricData[2] == 0xBF ) offset = 3; } if (checkMultiTime(&lyricData[offset], lyricSize - offset)) return ParserMultiTime(&lyricData[offset], lyricSize - offset, timing_correction); else return ParserNormal(&lyricData[offset], lyricSize - offset, timing_correction); }
bool CKaraokeLyricsTextLRC::Load() { XFILE::CFile file; // Clear the lyrics array clearLyrics(); XFILE::auto_buffer buf; if (file.LoadFile(m_lyricsFile, buf) <= 0) { CLog::Log(LOGERROR, "%s: can't load \"%s\" file", __FUNCTION__, m_lyricsFile.c_str()); return false; } file.Close(); // Parse the correction value int timing_correction = MathUtils::round_int( g_advancedSettings.m_karaokeSyncDelayLRC * 10 ); unsigned int offset = 0; CStdString songfilename = getSongFile(); // Skip windoze UTF8 file prefix, if any, and reject UTF16 files if (buf.size() > 3) { if ((unsigned char)buf.get()[0] == 0xFF && (unsigned char)buf.get()[1] == 0xFE) { CLog::Log( LOGERROR, "LRC lyric loader: lyrics file is in UTF16 encoding, must be in UTF8" ); return false; } // UTF8 prefix added by some windoze apps if ((unsigned char)buf.get()[0] == 0xEF && (unsigned char)buf.get()[1] == 0xBB && (unsigned char)buf.get()[2] == 0xBF) offset = 3; } if (checkMultiTime(buf.get() + offset, buf.size() - offset)) return ParserMultiTime(buf.get() + offset, buf.size() - offset, timing_correction); else return ParserNormal(buf.get() + offset, buf.size() - offset, timing_correction); }