public function album_songs($params) { if (!$this->checkAuth($params)) { $this->error(400, 'Invalid Login'); } $songs = $this->collection->getSongs(0, $params['filter']); if (count($songs) > 0) { $artist = $this->collection->getArtistName($songs[0]['song_artist']); } else { $artist = ''; } $this->printSongs($songs, $artist); }
\OCP\JSON::encodedPrint($collection->getAlbums($arguments['artist'], $arguments['search'])); break; case 'get_songs': \OCP\JSON::encodedPrint($collection->getSongs($arguments['artist'], $arguments['album'], $arguments['search'])); break; case 'get_path_info': if (\OC\Files\Filesystem::file_exists($arguments['path'])) { $songId = $collection->getSongByPath($arguments['path']); if ($songId == 0) { unset($_SESSION['collection']); $scanner = new Scanner($collection); $songId = $scanner->scanFile($arguments['path']); } if ($songId > 0) { $song = $collection->getSong($songId); $song['artist'] = $collection->getArtistName($song['song_artist']); $song['album'] = $collection->getAlbumName($song['song_album']); \OCP\JSON::encodedPrint($song); } } break; case 'play': $ftype = \OC\Files\Filesystem::getMimeType($arguments['path']); if (substr($ftype, 0, 5) != 'audio' and $ftype != 'application/ogg') { echo 'Not an audio file'; exit; } $songId = $collection->getSongByPath($arguments['path']); $collection->registerPlay($songId); header('Content-Type:' . $ftype); \OCP\Response::enableCaching(3600 * 24);
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; }