|
|
|
@ -30,7 +30,6 @@ class OC_MEDIA_SCANNER{ |
|
|
|
|
//these are used to store which artists and albums we found, it can save a lot of addArtist/addAlbum calls |
|
|
|
|
static private $artists=array(); |
|
|
|
|
static private $albums=array();//stored as "$artist/$album" to allow albums with the same name from different artists |
|
|
|
|
static private $useMp3Info=null; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* scan a folder for music |
|
|
|
@ -70,72 +69,55 @@ class OC_MEDIA_SCANNER{ |
|
|
|
|
* @return boolean |
|
|
|
|
*/ |
|
|
|
|
public static function scanFile($path){ |
|
|
|
|
if(is_null(self::$useMp3Info)){ |
|
|
|
|
self::$useMp3Info=OC_Helper::canExecute("mp3info"); |
|
|
|
|
} |
|
|
|
|
$file=OC_Filesystem::getLocalFile($path); |
|
|
|
|
if(substr($path,-3)=='mp3' and self::$useMp3Info){//use the command line tool id3info if possible |
|
|
|
|
$output=array(); |
|
|
|
|
$size=filesize($file); |
|
|
|
|
exec('mp3info -p "%a\n%l\n%t\n%n\n%S" "'.$file.'"',$output); |
|
|
|
|
if(count($output)>4){ |
|
|
|
|
$artist=$output[0]; |
|
|
|
|
$album=$output[1]; |
|
|
|
|
$title=$output[2]; |
|
|
|
|
$track=$output[3]; |
|
|
|
|
$length=$output[4]; |
|
|
|
|
}else{ |
|
|
|
|
return; //invalid mp3 file |
|
|
|
|
} |
|
|
|
|
if(!self::isMusic($path)){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if(!self::$getID3){ |
|
|
|
|
self::$getID3=@new getID3(); |
|
|
|
|
self::$getID3->encoding='UTF-8'; |
|
|
|
|
} |
|
|
|
|
$data=@self::$getID3->analyze($file); |
|
|
|
|
getid3_lib::CopyTagsToComments($data); |
|
|
|
|
if(!isset($data['comments'])){ |
|
|
|
|
OC_Log::write('media',"error reading id3 tags in '$file'",OC_Log::WARN); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if(!isset($data['comments']['artist'])){ |
|
|
|
|
OC_Log::write('media',"error reading artist tag in '$file'",OC_Log::WARN); |
|
|
|
|
$artist='unknown'; |
|
|
|
|
}else{ |
|
|
|
|
if(!self::isMusic($path)){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if(!self::$getID3){ |
|
|
|
|
self::$getID3=@new getID3(); |
|
|
|
|
self::$getID3->encoding='UTF-8'; |
|
|
|
|
} |
|
|
|
|
$data=@self::$getID3->analyze($file); |
|
|
|
|
getid3_lib::CopyTagsToComments($data); |
|
|
|
|
if(!isset($data['comments'])){ |
|
|
|
|
OC_Log::write('media',"error reading id3 tags in '$file'",OC_Log::WARN); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if(!isset($data['comments']['artist'])){ |
|
|
|
|
OC_Log::write('media',"error reading artist tag in '$file'",OC_Log::WARN); |
|
|
|
|
$artist='unknown'; |
|
|
|
|
}else{ |
|
|
|
|
$artist=stripslashes($data['comments']['artist'][0]); |
|
|
|
|
} |
|
|
|
|
if(!isset($data['comments']['album'])){ |
|
|
|
|
OC_Log::write('media',"error reading album tag in '$file'",OC_Log::WARN); |
|
|
|
|
$album='unknown'; |
|
|
|
|
}else{ |
|
|
|
|
$album=stripslashes($data['comments']['album'][0]); |
|
|
|
|
} |
|
|
|
|
if(!isset($data['comments']['title'])){ |
|
|
|
|
OC_Log::write('media',"error reading title tag in '$file'",OC_Log::WARN); |
|
|
|
|
$title='unknown'; |
|
|
|
|
}else{ |
|
|
|
|
$title=stripslashes($data['comments']['title'][0]); |
|
|
|
|
} |
|
|
|
|
$size=$data['filesize']; |
|
|
|
|
if (isset($data['comments']['track'])) |
|
|
|
|
{ |
|
|
|
|
$track = $data['comments']['track'][0]; |
|
|
|
|
} |
|
|
|
|
else if (isset($data['comments']['track_number'])) |
|
|
|
|
{ |
|
|
|
|
$track = $data['comments']['track_number'][0]; |
|
|
|
|
$track = explode('/',$track); |
|
|
|
|
$track = $track[0]; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
$track = 0; |
|
|
|
|
} |
|
|
|
|
$length=isset($data['playtime_seconds'])?round($data['playtime_seconds']):0; |
|
|
|
|
$artist=stripslashes($data['comments']['artist'][0]); |
|
|
|
|
} |
|
|
|
|
if(!isset($data['comments']['album'])){ |
|
|
|
|
OC_Log::write('media',"error reading album tag in '$file'",OC_Log::WARN); |
|
|
|
|
$album='unknown'; |
|
|
|
|
}else{ |
|
|
|
|
$album=stripslashes($data['comments']['album'][0]); |
|
|
|
|
} |
|
|
|
|
if(!isset($data['comments']['title'])){ |
|
|
|
|
OC_Log::write('media',"error reading title tag in '$file'",OC_Log::WARN); |
|
|
|
|
$title='unknown'; |
|
|
|
|
}else{ |
|
|
|
|
$title=stripslashes($data['comments']['title'][0]); |
|
|
|
|
} |
|
|
|
|
$size=$data['filesize']; |
|
|
|
|
if (isset($data['comments']['track'])) |
|
|
|
|
{ |
|
|
|
|
$track = $data['comments']['track'][0]; |
|
|
|
|
} |
|
|
|
|
else if (isset($data['comments']['track_number'])) |
|
|
|
|
{ |
|
|
|
|
$track = $data['comments']['track_number'][0]; |
|
|
|
|
$track = explode('/',$track); |
|
|
|
|
$track = $track[0]; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
$track = 0; |
|
|
|
|
} |
|
|
|
|
$length=isset($data['playtime_seconds'])?round($data['playtime_seconds']):0; |
|
|
|
|
|
|
|
|
|
if(!isset(self::$artists[$artist])){ |
|
|
|
|
$artistId=OC_MEDIA_COLLECTION::addArtist($artist); |
|
|
|
|
self::$artists[$artist]=$artistId; |
|
|
|
|