public function doGet(Option $q, HttpGet $get, LoggedIn $me, Option $compilations) { $artist = $get->get("artist")->map("urldecode"); $album = $get->get("album")->map("urldecode"); $genre = $get->get("genre")->map("urldecode"); $order_field = $get->getOrElse("sort", "auto"); $filter = $q->map("trim")->reject(""); $query = (new SelectQuery(TSongs::_NAME))->where(TSongs::USER_ID, $me->getId())->where(TSongs::FILE_ID . " IS NOT NULL"); $query->select(TSongs::defaultSelection()); if ($compilations->nonEmpty()) { $query->where(TSongs::IS_COMP, $compilations->get()); } Context::contextify($query); if ($artist->nonEmpty()) { $query->where(TSongs::A_ARTIST, $artist->get()); } if ($album->nonEmpty()) { $query->where(TSongs::T_ALBUM, $album->get()); } if ($genre->nonEmpty()) { $query->where(TSongs::T_GENRE, $genre->get()); } if ($filter->nonEmpty()) { if (strpos($filter->get(), ":") !== false) { list($key, $value) = explode(":", $filter->get(), 2); switch ($key) { case "id": $query->where(TSongs::ID, $value); break; } } else { $query->where(TSongs::FTS_ANY . " @@ plainto_tsquery(?)", [$filter->get()]); } } else { switch ($order_field) { case 'upload': $query->orderBy(TSongs::C_DATE . " DESC")->orderBy(TSongs::ID); break; default: $query->orderBy(TSongs::A_ARTIST)->orderBy(TSongs::T_ALBUM)->orderBy(TSongs::DISC)->orderBy(TSongs::T_NUMBER)->orderBy(TSongs::ID); } } ob_start("ob_gzhandler"); $query->renderAllAsJson(function ($row) { $artist_encoded = escape_url($row["album_artist"]); $album_encoded = escape_url($row["track_album"]); $genre_encoded = escape_url($row["track_genre"]); $row["artist_url"] = "artist/{$artist_encoded}"; $row["album_url"] = "artist/{$artist_encoded}/{$album_encoded}"; $row["genre_url"] = "genre/{$genre_encoded}"; return $row; }); }
public function doGet(LoggedIn $me, Option $sync_token) { $token = $sync_token->getOrElse(0); $new_tracks = (new SelectQuery(TSongs::_NAME))->select(TSongs::getFullColumnNames())->innerJoin(TSongsLog::_NAME, TSongs::_NAME . "." . TSongs::ID, TSongsLog::SONG_ID)->where(TSongsLog::_NAME . "." . TSongsLog::USER_ID, $me->getId())->where(TSongsLog::_NAME . "." . TSongsLog::ACTION, TSongsLog::ACTION_ADD)->where(TSongsLog::_NAME . "." . TSongsLog::ID . " > ?", array($token))->fetchAll(); // $updated_tracks = (new SelectQuery(TSongs::_NAME)) // ->select(TSongs::getFullColumnNames()) // ->innerJoin(TSongsLog::_NAME, TSongs::_NAME . "." . TSongs::ID, TSongsLog::SONG_ID) // ->where(TSongsLog::_NAME . "." . TSongsLog::USER_ID, $me->getId()) // ->where(TSongsLog::_NAME . "." . TSongsLog::ACTION, TSongsLog::ACTION_UPDATE) // ->where(TSongsLog::_NAME . "." . TSongsLog::ID . " > ?", array($token)) // ->fetchAll(); // echo json_encode(array( // "new" => $new_tracks, // "updated" => $updated_tracks // )); }
public function doGet(LoggedIn $me, $playlist_id) { $query = (new SelectQuery(TSongs::_NAME))->innerJoin(TPlaylistSongLinks::_NAME, TPlaylistSongLinks::_NAME . "." . TPlaylistSongLinks::SONG_ID, TSongs::_NAME . "." . TSongs::ID)->where(TPlaylistSongLinks::PLAYLIST_ID, $playlist_id)->where(TSongs::USER_ID, $me->getId())->where(TSongs::FILE_ID . " IS NOT NULL")->orderBy(TPlaylistSongLinks::ORDER_ID); $query->select(TSongs::defaultSelection()); $query->select(TPlaylistSongLinks::LINK_ID); $query->select(TPlaylistSongLinks::ORDER_ID); ob_start("ob_gzhandler"); $query->renderAllAsJson(function ($row) use($playlist_id) { $artist_encoded = escape_url($row["album_artist"]); $album_encoded = escape_url($row["track_album"]); $genre_encoded = escape_url($row["track_genre"]); $ror["playlist_id"] = $playlist_id; $row["playlist_url"] = "playlist/{$playlist_id}"; $row["artist_url"] = "artist/{$artist_encoded}"; $row["album_url"] = "artist/{$artist_encoded}/{$album_encoded}"; $row["genre_url"] = "genre/{$genre_encoded}"; return $row; }); }
/** * @param $song_id * @param array $metadata * @return array */ public static function edit($song_id, array $metadata) { $allowed_keys = [TSongs::T_TITLE, TSongs::T_ARTIST, TSongs::T_ALBUM, TSongs::A_ARTIST, TSongs::IS_COMP, TSongs::T_GENRE, TSongs::T_YEAR, TSongs::T_NUMBER, TSongs::DISC]; $numeric_keys = [TSongs::T_NUMBER, TSongs::DISC]; $filtered_metadata = array_intersect_key($metadata, array_flip($allowed_keys)); $query = (new UpdateQuery(TSongs::_NAME))->where(TSongs::ID, explode(",", $song_id))->where(TSongs::USER_ID, self::$me->getId()); foreach ($filtered_metadata as $key => $value) { if (in_array($key, $numeric_keys)) { $query->set($key, is_numeric($value) ? $value : null); } else { $query->set($key, $value); } } $query->returning(TSongs::defaultSelection()); return $query->fetchAll(); }