The new code would be like this:
(update.php, around line 746)
Code: Select all
$cd = 1;
$temp = DecodeEscapeCharacters($filename[$i]);
// START OF PATCH
// Funny processing stuff
// Check for the number of separators
$separators = substr_count($temp, '-');
$featuring = '';
// At least two parts are required.
if ($separators < 2) {
$track_artist = '*** UNKNOWN FILENAME FORMAT ***';
$title = '(' . $filename[$i] . ')';
} else {
// If three parts are present, we check if the first one
// is a track number. Basically we only allow 1 to 3 digits here.
// Anything above that is probably not a track number.
if (preg_match('/^(\d{1,3})\s*-\s*(.*)$/', $temp, $matches)) {
$track_number = $matches[1];
// Most likely a CD number in front (101 = CD 1 Track 1)
if ($track_number > 99) {
$cd = floor($track_numer / 100);
}
$temp = $matches[2]; // Strip the track number
}
preg_match('/^(.+)\s+-\s+(.*)(Feat\.\s+.*|)$/i', $temp, $matches);
$track_artist = $matches[1];
$title = $matches[2];
$featuring = $matches[3];
}
// END OF PATCH
$relative_file = substr($file[$i], strlen($cfg['media_dir']));
$query = mysql_query('SELECT album_id FROM track WHERE album_id = "' . mysql_real_escape_string($album_id) . '" AND BINARY relative_file = "' . mysql_real_escape_string($relative_file) . '"');
It looks for a track number in the beginning of the file that has to be numeric and between 1 and 3 digits long (largest track number is 999 as before). It then does the CD check and removes the track number from the string (to unify the processing afterwards).
Then it basically does everything in one regular expression.
The first part is the artist name which can be _anything_ but it has to be separated by ' - ' from the rest of the string. The rest of the string is then treated as the title until (optionally) 'Feat.' followed by one or more spaces is encountered. The rest is then treated as the "featuring" part.
If you want to include this go ahead (GPL'd anyway). If you have certain requests regarding this code before you want to include it (i.e. change the regular expression pattern a bit), go ahead and ask.
cu,
Sebastian
ps: Filenames it does parse correctly include:
15 - Static-X - Skinnyman.mp3 (Previously parsed correctly i think)
15 - Kärtsy Hatakka & Kimmo Kajasto - Variations - Max Payne (Cello Base).mp3
Especially the last one gave me a lot of trouble since the entire album looks like that.