function search($query) { $collection = new Collection(\OCP\User::getUser()); $l = \OC_L10N::get('media'); $app_name = (string) $l->t('Music'); $artists = $collection->getArtists($query); $albums = $collection->getAlbums(0, $query); $songs = $collection->getSongs(0, 0, $query); $results = array(); foreach ($artists as $artist) { $results[] = new \OC_Search_Result($artist['artist_name'], '', \OCP\Util::linkTo('media', 'index.php') . '#artist=' . urlencode($artist['artist_name']), $app_name); } foreach ($albums as $album) { $artist = $collection->getArtistName($album['album_artist']); $results[] = new \OC_Search_Result($album['album_name'], 'by ' . $artist, \OCP\Util::linkTo('media', 'index.php') . '#artist=' . urlencode($artist) . '&album=' . urlencode($album['album_name']), $app_name); } foreach ($songs as $song) { $minutes = floor($song['song_length'] / 60); $seconds = $song['song_length'] % 60; $artist = $collection->getArtistName($song['song_artist']); $album = $collection->getalbumName($song['song_album']); $results[] = new \OC_Search_Result($song['song_name'], "by {$artist}, in {$album} {$minutes}:{$seconds}", \OCP\Util::linkTo('media', 'index.php') . '#artist=' . urlencode($artist) . '&album=' . urlencode($album) . '&song=' . urlencode($song['song_name']), $app_name); } return $results; }
public function search_songs($params) { if (!$this->checkAuth($params)) { $this->error(400, 'Invalid Login'); } $filter = isset($params['filter']) ? $params['filter'] : ''; $artists = $this->collection->getArtists($filter); $albums = $this->collection->getAlbums(0, $filter); $songs = $this->collection->getSongs(0, 0, $filter); foreach ($artists as $artist) { $songs = array_merge($songs, $this->collection->getSongs($artist['artist_id'])); } foreach ($albums as $album) { $songs = array_merge($songs, $this->collection->getSongs($album['album_artist'], $album['album_id'])); } $this->printSongs($songs); }
$collection = new Collection(\OCP\USER::getUser()); if ($arguments['action']) { switch ($arguments['action']) { case 'delete': \OCP\JSON::callCheck(); $path = $arguments['path']; $collection->deleteSongByPath($path); $paths = explode(PATH_SEPARATOR, \OCP\Config::getUserValue(\OCP\USER::getUser(), 'media', 'paths', '')); if (array_search($path, $paths) !== false) { unset($paths[array_search($path, $paths)]); \OCP\Config::setUserValue(\OCP\USER::getUser(), 'media', 'paths', implode(PATH_SEPARATOR, $paths)); } break; case 'get_collection': $data = array(); $data['artists'] = $collection->getArtists(); $data['albums'] = $collection->getAlbums(); $data['songs'] = $collection->getSongs(); \OCP\JSON::encodedPrint($data); break; case 'scan': \OCP\DB::beginTransaction(); set_time_limit(0); //recursive scan can take a while $eventSource = new \OC_EventSource(); $watcher = new ScanWatcher($eventSource); $scanner = new Scanner($collection); \OC_Hook::connect('media', 'song_count', $watcher, 'count'); \OC_Hook::connect('media', 'song_scanned', $watcher, 'scanned'); $scanner->scanCollection(); $watcher->done();