Esempio n. 1
0
 public function doGet(JsonResponse $response, LoggedIn $me)
 {
     ob_start("ob_gzhandler", 8192);
     set_time_limit(0);
     $last_token = (new SelectQuery(TSongsLog::_NAME))->select(TSongsLog::ID)->fetchColumn()->toInt()->getOrElse(0);
     $tracks = (new SelectQuery(TSongs::_NAME))->select(TSongs::$columns)->where(TSongs::FILE_ID . " IS NOT NULL")->where(TSongs::USER_ID, $me->getId())->fetchAll();
     $response->write(array("last_token" => $last_token));
 }
Esempio n. 2
0
 public function addTracks($song_ids)
 {
     $next_order_id = count(PlaylistSongDao::getList([TPlaylistSongLinks::PLAYLIST_ID => $this->playlist[TPlaylists::ID]]));
     foreach (explode(",", $song_ids) as $song_id) {
         (new SelectQuery(TSongs::_NAME))->where(TSongs::ID, $song_id)->where(TSongs::USER_ID, self::$me->getId())->select(TSongs::ID)->fetchColumn()->then(function ($id) use(&$next_order_id) {
             PlaylistSongDao::create([TPlaylistSongLinks::PLAYLIST_ID => $this->playlist[TPlaylists::ID], TPlaylistSongLinks::SONG_ID => $id, TPlaylistSongLinks::ORDER_ID => $next_order_id++]);
         });
     }
 }
Esempio n. 3
0
 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;
     });
 }
Esempio n. 4
0
 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
     //        ));
 }
Esempio n. 5
0
 /**
  * @param $track_artist
  * @return MLArray
  */
 public static function deleteByArtist($track_artist)
 {
     $songs = SongDao::getList([TSongs::T_ARTIST => $track_artist, TSongs::USER_ID => self::$me->getId()]);
     $to_remove = $songs->map(Mapper::key(TSongs::ID));
     if (count($to_remove) == 0) {
         return array();
     }
     return (new DeleteQuery(TSongs::_NAME))->where(TSongs::ID, $to_remove->mkArray())->returning("*")->fetchAll();
 }
Esempio n. 6
0
 public function doGet(Option $q, LoggedIn $me)
 {
     $filter = $q->map("trim")->reject("");
     $query = (new SelectQuery(TSongs::_NAME))->select(TSongs::A_ARTIST)->where(TSongs::USER_ID, $me->getId())->selectAlias("MIN(" . TSongs::C_BIG_ID . ")", TSongs::C_BIG_ID)->selectAlias("MIN(" . TSongs::C_MID_ID . ")", TSongs::C_MID_ID)->selectAlias("MIN(" . TSongs::C_SMALL_ID . ")", TSongs::C_SMALL_ID);
     $query->where(TSongs::IS_COMP, "0");
     Context::contextify($query);
     if ($filter->nonEmpty()) {
         $query->where(TSongs::FTS_ARTIST . " @@ plainto_tsquery(?)", [$filter->get()]);
     }
     $query->addGroupBy(TSongs::A_ARTIST);
     $query->orderBy(TSongs::A_ARTIST);
     ob_start("ob_gzhandler");
     $query->renderAllAsJson(function ($row) {
         $artist_encoded = escape_url($row["album_artist"]);
         $row["artist_url"] = "artist/{$artist_encoded}";
         return $row;
     });
 }
Esempio n. 7
0
 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;
     });
 }
Esempio n. 8
0
 public function doGet()
 {
     $logged_in = LoggedIn::isLoggedIn();
     //        $logged_in = false;
     if ($logged_in) {
         http_response_code(HttpStatusCodes::HTTP_FOUND);
         header("Location: /library/");
     } else {
         TinyView::show("login.tmpl");
     }
 }
Esempio n. 9
0
 public function doGet(JsonResponse $response, LoggedIn $me, $album_artist)
 {
     $artist_stats = (new SelectQuery(TSongs::_NAME))->selectAlias("COUNT(DISTINCT " . TSongs::T_ALBUM . ")", "albums_count")->selectAlias("COUNT(" . TSongs::ID . ")", "tracks_count")->selectAlias("SUM(" . TSongs::LENGTH . ")", "tracks_duration")->selectAlias("MIN(" . TSongs::C_BIG_ID . ")", TSongs::C_BIG_ID)->selectAlias("MIN(" . TSongs::C_MID_ID . ")", TSongs::C_MID_ID)->selectAlias("MIN(" . TSongs::C_SMALL_ID . ")", TSongs::C_SMALL_ID)->where(TSongs::USER_ID, $me->getId())->where(TSongs::A_ARTIST, $album_artist)->fetchOneRow()->get();
     $artist_stats["album_artist"] = $album_artist;
     $response->write($artist_stats);
 }
Esempio n. 10
0
 public function doPost(JsonResponse $response, PasswordForm $form, LoggedIn $userModel)
 {
     $userModel->changePassword($form->getPassword());
 }
Esempio n. 11
0
 /**
  * @throws BadAccessException
  */
 private function checkPermission()
 {
     if ($this->track_data[TSongs::USER_ID] !== $this->me->getId()) {
         throw new BadAccessException();
     }
 }
Esempio n. 12
0
 /**
  * @return string
  */
 public static function myPrefix()
 {
     return self::CACHE_NAME . ":ID_" . self::$me->getId();
 }
Esempio n. 13
0
 public static function filterAlbums(SelectQuery $query)
 {
     $query->where(sprintf("EXISTS (SELECT %s FROM %s INNER JOIN %s USING (id) WHERE %s = %s AND %s = %s)", MetadataTable::ALBUM_ID_FULL, MetadataTable::TABLE_NAME, AudiosTable::TABLE_NAME, MetadataTable::ALBUM_ID_FULL, MetaAlbumsTable::ID_FULL, AudiosTable::USER_ID_FULL, self::$me->getId()));
 }
Esempio n. 14
0
 public function doGet(JsonResponse $response, LoggedIn $me)
 {
     $songs_count = (new SelectQuery(TSongs::_NAME))->select("COUNT(" . TSongs::ID . ")")->where(TSongs::USER_ID, $me->getId())->fetchColumn()->get();
     $response->write(["email" => $me->getEmail(), "name" => $me->getName(), "id" => $me->getId(), "stats" => ["tracks_count" => $songs_count, "artists_count" => 0, "albums_count" => 0, "genres_count" => 0, "compilations_count" => 0]]);
 }
Esempio n. 15
0
 public function doGet(JsonResponse $response, LoggedIn $me)
 {
     $playlists = PlaylistDao::getList([TPlaylists::USER_ID => $me->getId()]);
     $playlist_objects = $playlists->map(Mapper::call(Playlist::class, "new"));
     $response->write($playlist_objects);
 }