mirror of
https://github.com/Yetangitu/ampache
synced 2025-10-06 11:59:56 +02:00
Add bookmarks feature
This commit is contained in:
parent
bb24bedfa6
commit
5c763ec920
3 changed files with 159 additions and 29 deletions
|
@ -2046,6 +2046,77 @@ class Subsonic_Api
|
||||||
self::apiOutput($input, $r);
|
self::apiOutput($input, $r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getBookmarks
|
||||||
|
* Get all user bookmarks.
|
||||||
|
* Takes no parameter.
|
||||||
|
* Not supported.
|
||||||
|
*/
|
||||||
|
public static function getbookmarks($input)
|
||||||
|
{
|
||||||
|
self::check_version($input, "1.9.0");
|
||||||
|
|
||||||
|
$r = Subsonic_XML_Data::createSuccessResponse();
|
||||||
|
$bookmarks = Bookmark::get_bookmarks();
|
||||||
|
Subsonic_XML_Data::addBookmarks($r, $bookmarks);
|
||||||
|
self::apiOutput($input, $r);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* createBookmark
|
||||||
|
* Creates or updates a bookmark.
|
||||||
|
* Takes the file id and position with optional comment in parameters.
|
||||||
|
* Not supported.
|
||||||
|
*/
|
||||||
|
public static function createbookmark($input)
|
||||||
|
{
|
||||||
|
self::check_version($input, "1.9.0");
|
||||||
|
$id = self::check_parameter($input, 'id');
|
||||||
|
$position = self::check_parameter($input, 'position');
|
||||||
|
$comment = $input['comment'];
|
||||||
|
$type = Subsonic_XML_Data::getAmpacheType($id);
|
||||||
|
|
||||||
|
if (!empty($type)) {
|
||||||
|
$bookmark = new Bookmark(Subsonic_XML_Data::getAmpacheId($id), $type);
|
||||||
|
if ($bookmark->id) {
|
||||||
|
$bookmark->update($position);
|
||||||
|
} else {
|
||||||
|
Bookmark::create(array(
|
||||||
|
'object_id' => Subsonic_XML_Data::getAmpacheId($id),
|
||||||
|
'object_type' => $type,
|
||||||
|
'comment' => $comment,
|
||||||
|
'position' => $position
|
||||||
|
));
|
||||||
|
}
|
||||||
|
$r = Subsonic_XML_Data::createSuccessResponse();
|
||||||
|
} else {
|
||||||
|
$r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_DATA_NOTFOUND);
|
||||||
|
}
|
||||||
|
self::apiOutput($input, $r);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* deleteBookmark
|
||||||
|
* Delete an existing bookmark.
|
||||||
|
* Takes the file id in parameter.
|
||||||
|
* Not supported.
|
||||||
|
*/
|
||||||
|
public static function deletebookmark($input)
|
||||||
|
{
|
||||||
|
self::check_version($input, "1.9.0");
|
||||||
|
$id = self::check_parameter($input, 'id');
|
||||||
|
$type = Subsonic_XML_Data::getAmpacheType($id);
|
||||||
|
|
||||||
|
$bookmark = new Bookmark(Subsonic_XML_Data::getAmpacheId($id), $type);
|
||||||
|
if ($bookmark->id) {
|
||||||
|
$bookmark->remove();
|
||||||
|
$r = Subsonic_XML_Data::createSuccessResponse();
|
||||||
|
} else {
|
||||||
|
$r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_DATA_NOTFOUND);
|
||||||
|
}
|
||||||
|
self::apiOutput($input, $r);
|
||||||
|
}
|
||||||
|
|
||||||
/**** CURRENT UNSUPPORTED FUNCTIONS ****/
|
/**** CURRENT UNSUPPORTED FUNCTIONS ****/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2075,44 +2146,30 @@ class Subsonic_Api
|
||||||
$r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_DATA_NOTFOUND);
|
$r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_DATA_NOTFOUND);
|
||||||
self::apiOutput($input, $r);
|
self::apiOutput($input, $r);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getBookmarks
|
* getPlayQueue
|
||||||
* Get all user bookmarks.
|
* Geturns the state of the play queue for the authenticated user.
|
||||||
* Takes no parameter.
|
* Takes no parameter.
|
||||||
* Not supported.
|
* Not supported.
|
||||||
*/
|
*/
|
||||||
public static function getbookmarks($input)
|
public static function getplayqueue($input)
|
||||||
{
|
{
|
||||||
self::check_version($input, "1.9.0");
|
self::check_version($input, "1.12.0");
|
||||||
|
|
||||||
$r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_DATA_NOTFOUND);
|
$r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_DATA_NOTFOUND);
|
||||||
self::apiOutput($input, $r);
|
self::apiOutput($input, $r);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* createBookmark
|
* savePlayQueue
|
||||||
* Creates or updates a bookmark.
|
* Save the state of the play queue for the authenticated user.
|
||||||
* Takes the file id and position with optional comment in parameters.
|
* Takes multiple song id in parameter with optional current id playing sond and position.
|
||||||
* Not supported.
|
* Not supported.
|
||||||
*/
|
*/
|
||||||
public static function createbookmark($input)
|
public static function saveplayqueue($input)
|
||||||
{
|
{
|
||||||
self::check_version($input, "1.9.0");
|
self::check_version($input, "1.12.0");
|
||||||
|
|
||||||
$r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_DATA_NOTFOUND);
|
|
||||||
self::apiOutput($input, $r);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* deleteBookmark
|
|
||||||
* Delete an existing bookmark.
|
|
||||||
* Takes the file id in parameter.
|
|
||||||
* Not supported.
|
|
||||||
*/
|
|
||||||
public static function deletebookmark($input)
|
|
||||||
{
|
|
||||||
self::check_version($input, "1.9.0");
|
|
||||||
|
|
||||||
$r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_DATA_NOTFOUND);
|
$r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_DATA_NOTFOUND);
|
||||||
self::apiOutput($input, $r);
|
self::apiOutput($input, $r);
|
||||||
|
|
|
@ -158,6 +158,27 @@ class Subsonic_XML_Data
|
||||||
$id = self::cleanId($id);
|
$id = self::cleanId($id);
|
||||||
return ($id >= Subsonic_XML_Data::AMPACHEID_PODCASTEP);
|
return ($id >= Subsonic_XML_Data::AMPACHEID_PODCASTEP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getAmpacheType($id)
|
||||||
|
{
|
||||||
|
if (self::isArtist($id)) {
|
||||||
|
return "artist";
|
||||||
|
} elseif (self::isAlbum($id)) {
|
||||||
|
return "album";
|
||||||
|
} elseif (self::isSong($id)) {
|
||||||
|
return "song";
|
||||||
|
} elseif (self::isSmartPlaylist($id)) {
|
||||||
|
return "search";
|
||||||
|
} elseif (self::isVideo($id)) {
|
||||||
|
return "video";
|
||||||
|
} elseif (self::isPodcast($id)) {
|
||||||
|
return "podcast";
|
||||||
|
} elseif (self::isPodcastEp($id)) {
|
||||||
|
return "podcast_episode";
|
||||||
|
}
|
||||||
|
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
public static function createFailedResponse($version = "")
|
public static function createFailedResponse($version = "")
|
||||||
{
|
{
|
||||||
|
@ -517,9 +538,9 @@ class Subsonic_XML_Data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function addVideo($xml, $video)
|
public static function addVideo($xml, $video, $elementName = 'video')
|
||||||
{
|
{
|
||||||
$xvideo = $xml->addChild('video');
|
$xvideo = $xml->addChild($elementName);
|
||||||
$xvideo->addAttribute('id', self::getVideoId($video->id));
|
$xvideo->addAttribute('id', self::getVideoId($video->id));
|
||||||
$xvideo->addAttribute('title', $video->f_full_title);
|
$xvideo->addAttribute('title', $video->f_full_title);
|
||||||
$xvideo->addAttribute('isDir', 'false');
|
$xvideo->addAttribute('isDir', 'false');
|
||||||
|
@ -869,10 +890,10 @@ class Subsonic_XML_Data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function addPodcastEpisode($xml, $episode)
|
private static function addPodcastEpisode($xml, $episode, $elementName = 'episode')
|
||||||
{
|
{
|
||||||
$episode->format();
|
$episode->format();
|
||||||
$xepisode = $xml->addChild("episode");
|
$xepisode = $xml->addChild($elementName);
|
||||||
$xepisode->addAttribute("id", self::getPodcastEpId($episode->id));
|
$xepisode->addAttribute("id", self::getPodcastEpId($episode->id));
|
||||||
$xepisode->addAttribute("channelId", self::getPodcastId($episode->podcast));
|
$xepisode->addAttribute("channelId", self::getPodcastId($episode->podcast));
|
||||||
$xepisode->addAttribute("title", $episode->f_title);
|
$xepisode->addAttribute("title", $episode->f_title);
|
||||||
|
@ -905,4 +926,30 @@ class Subsonic_XML_Data
|
||||||
self::addPodcastEpisode($xpodcasts, $episode);
|
self::addPodcastEpisode($xpodcasts, $episode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function addBookmarks($xml, $bookmarks)
|
||||||
|
{
|
||||||
|
$xbookmarks = $xml->addChild("bookmarks");
|
||||||
|
foreach ($bookmarks as $bookmark) {
|
||||||
|
$bookmark->format();
|
||||||
|
self::addBookmark($xbookmarks, $bookmark);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function addBookmark($xml, $bookmark)
|
||||||
|
{
|
||||||
|
$xbookmark = $xml->addChild("bookmark");
|
||||||
|
$xbookmark->addAttribute("position", $bookmark->position);
|
||||||
|
$xbookmark->addAttribute("username", $bookmark->f_user);
|
||||||
|
$xbookmark->addAttribute("comment", $bookmark->comment);
|
||||||
|
$xbookmark->addAttribute("created", date("c", $bookmark->creation_date));
|
||||||
|
$xbookmark->addAttribute("changed", date("c", $bookmark->update_date));
|
||||||
|
if ($bookmark->object_type == "song") {
|
||||||
|
self::addSong($xbookmark, new Song($bookmark->object_id), false, 'entry');
|
||||||
|
} elseif ($bookmark->object_type == "video") {
|
||||||
|
self::addVideo($xbookmark, new Video($bookmark->object_id), 'entry');
|
||||||
|
} elseif ($bookmark->object_type == "podcast_episode") {
|
||||||
|
self::addPodcastEpisode($xbookmark, new Podcast_Episode($bookmark->object_id), 'entry');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -525,6 +525,9 @@ class Update
|
||||||
|
|
||||||
$update_string = "- Add podcasts.<br />";
|
$update_string = "- Add podcasts.<br />";
|
||||||
$version[] = array('version' => '380001', 'description' => $update_string);
|
$version[] = array('version' => '380001', 'description' => $update_string);
|
||||||
|
|
||||||
|
$update_string = "- Add bookmarks.<br />";
|
||||||
|
$version[] = array('version' => '380002', 'description' => $update_string);
|
||||||
|
|
||||||
return $version;
|
return $version;
|
||||||
}
|
}
|
||||||
|
@ -3721,4 +3724,27 @@ class Update
|
||||||
|
|
||||||
return $retval;
|
return $retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* update_380002
|
||||||
|
*
|
||||||
|
* Add bookmarks
|
||||||
|
*/
|
||||||
|
public static function update_380002()
|
||||||
|
{
|
||||||
|
$retval = true;
|
||||||
|
|
||||||
|
$sql = "CREATE TABLE `bookmark` (`id` int( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , " .
|
||||||
|
"`user` int(11) UNSIGNED NOT NULL , " .
|
||||||
|
"`position` int(11) UNSIGNED DEFAULT '0' NOT NULL , " .
|
||||||
|
"`comment` varchar(255) CHARACTER SET utf8 NOT NULL , " .
|
||||||
|
"`object_type` varchar(64) NOT NULL , " .
|
||||||
|
"`object_id` int(11) UNSIGNED NOT NULL , " .
|
||||||
|
"`creation_date` int(11) UNSIGNED DEFAULT '0' NOT NULL , " .
|
||||||
|
"`update_date` int(11) UNSIGNED DEFAULT '0' NOT NULL" .
|
||||||
|
") ENGINE = MYISAM";
|
||||||
|
$retval &= Dba::write($sql);
|
||||||
|
|
||||||
|
return $retval;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue