/**
  *
  */
 public static function updateFile($params)
 {
     $path = $params['path'];
     require_once 'lib_scanner.php';
     require_once 'lib_collection.php';
     //fix a bug where there were multiply '/' in front of the path, it should only be one
     while ($path[0] == '/') {
         $path = substr($path, 1);
     }
     $path = '/' . $path;
     error_log("{$path} was updated");
     OC_MEDIA_SCANNER::scanFile($path);
 }
Exemplo n.º 2
0
 /**
  * scan a file for music
  * @param string $path
  * @return boolean
  */
 public static function scanFile($path)
 {
     if (!self::isMusic($path)) {
         return;
     }
     if (!self::$getID3) {
         self::$getID3 = @new getID3();
         self::$getID3->encoding = 'UTF-8';
     }
     $file = OC_Filesystem::getLocalFile($path);
     $data = @self::$getID3->analyze($file);
     getid3_lib::CopyTagsToComments($data);
     if (!isset($data['comments'])) {
         OCP\Util::writeLog('media', "error reading id3 tags in '{$file}'", OCP\Util::WARN);
         return;
     }
     if (!isset($data['comments']['artist'])) {
         OCP\Util::writeLog('media', "error reading artist tag in '{$file}'", OCP\Util::WARN);
         $artist = 'unknown';
     } else {
         $artist = OCP\Util::sanitizeHTML(stripslashes($data['comments']['artist'][0]));
     }
     if (!isset($data['comments']['album'])) {
         OCP\Util::writeLog('media', "error reading album tag in '{$file}'", OCP\Util::WARN);
         $album = 'unknown';
     } else {
         $album = OCP\Util::sanitizeHTML(stripslashes($data['comments']['album'][0]));
     }
     if (!isset($data['comments']['title'])) {
         OCP\Util::writeLog('media', "error reading title tag in '{$file}'", OCP\Util::WARN);
         $title = 'unknown';
     } else {
         $title = OCP\Util::sanitizeHTML(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;
     } else {
         $artistId = self::$artists[$artist];
     }
     if (!isset(self::$albums[$artist . '/' . $album])) {
         $albumId = OC_MEDIA_COLLECTION::addAlbum($album, $artistId);
         self::$albums[$artist . '/' . $album] = $albumId;
     } else {
         $albumId = self::$albums[$artist . '/' . $album];
     }
     $songId = OC_MEDIA_COLLECTION::addSong($title, $path, $artistId, $albumId, $length, $track, $size);
     return !($title == 'unknown' && $artist == 'unknown' && $album == 'unknown') ? $songId : 0;
 }
Exemplo n.º 3
0
     break;
 case 'get_artists':
     OCP\JSON::encodedPrint(OC_MEDIA_COLLECTION::getArtists($arguments['search']));
     break;
 case 'get_albums':
     OCP\JSON::encodedPrint(OC_MEDIA_COLLECTION::getAlbums($arguments['artist'], $arguments['search']));
     break;
 case 'get_songs':
     OCP\JSON::encodedPrint(OC_MEDIA_COLLECTION::getSongs($arguments['artist'], $arguments['album'], $arguments['search']));
     break;
 case 'get_path_info':
     if (OC_Filesystem::file_exists($arguments['path'])) {
         $songId = OC_MEDIA_COLLECTION::getSongByPath($arguments['path']);
         if ($songId == 0) {
             unset($_SESSION['collection']);
             $songId = OC_MEDIA_SCANNER::scanFile($arguments['path']);
         }
         if ($songId > 0) {
             $song = OC_MEDIA_COLLECTION::getSong($songId);
             $song['artist'] = OC_MEDIA_COLLECTION::getArtistName($song['song_artist']);
             $song['album'] = OC_MEDIA_COLLECTION::getAlbumName($song['song_album']);
             OCP\JSON::encodedPrint($song);
         }
     }
     break;
 case 'play':
     @ob_end_clean();
     $ftype = OC_Filesystem::getMimeType($arguments['path']);
     if (substr($ftype, 0, 5) != 'audio' and $ftype != 'application/ogg') {
         echo 'Not an audio file';
         exit;
function findMusic($path = '')
{
    $music = array();
    $dh = OC_Filesystem::opendir($path);
    if ($dh) {
        while ($filename = readdir($dh)) {
            if ($filename[0] != '.') {
                $file = $path . '/' . $filename;
                if (OC_Filesystem::is_dir($file)) {
                    $music = array_merge($music, findMusic($file));
                } else {
                    if (OC_MEDIA_SCANNER::isMusic($filename)) {
                        $music[] = $file;
                    }
                }
            }
        }
    }
    return $music;
}
 /**
  * scan a file for music
  * @param string $path
  * @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
         }
     } else {
         if (!self::isMusic($path)) {
             return;
         }
         if (!self::$getID3) {
             self::$getID3 = @new getID3();
         }
         $data = @self::$getID3->analyze($file);
         getid3_lib::CopyTagsToComments($data);
         if (!isset($data['comments'])) {
             if (defined("DEBUG") && DEBUG) {
                 error_log("error reading id3 tags in '{$file}'");
             }
             return;
         }
         if (!isset($data['comments']['artist'])) {
             if (defined("DEBUG") && DEBUG) {
                 error_log("error reading artist tag in '{$file}'");
             }
             $artist = 'unknown';
         } else {
             $artist = stripslashes($data['comments']['artist'][0]);
             $artist = utf8_encode($artist);
         }
         if (!isset($data['comments']['album'])) {
             if (defined("DEBUG") && DEBUG) {
                 error_log("error reading album tag in '{$file}'");
             }
             $album = 'unknown';
         } else {
             $album = stripslashes($data['comments']['album'][0]);
             $album = utf8_encode($album);
         }
         if (!isset($data['comments']['title'])) {
             if (defined("DEBUG") && DEBUG) {
                 error_log("error reading title tag in '{$file}'");
             }
             $title = 'unknown';
         } else {
             $title = stripslashes($data['comments']['title'][0]);
             $title = utf8_encode($title);
         }
         $size = $data['filesize'];
         $track = isset($data['comments']['track']) ? $data['comments']['track'][0] : 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;
     } else {
         $artistId = self::$artists[$artist];
     }
     if (!isset(self::$albums[$artist . '/' . $album])) {
         $albumId = OC_MEDIA_COLLECTION::addAlbum($album, $artistId);
         self::$albums[$artist . '/' . $album] = $albumId;
     } else {
         $albumId = self::$albums[$artist . '/' . $album];
     }
     $songId = OC_MEDIA_COLLECTION::addSong($title, $path, $artistId, $albumId, $length, $track, $size);
     return !($title == 'unkown' && $artist == 'unkown' && $album == 'unkown') ? $songId : 0;
 }