Commit d0e4e626 authored by Jonas Haraldsson's avatar Jonas Haraldsson

library.removescrobble

parent 43815d12
......@@ -32,6 +32,7 @@ require_once('../api/JSONEncoder.php');
require_once('../api/TrackXML.php');
require_once('../api/AlbumXML.php');
require_once('../api/TagXML.php');
require_once('../api/LibraryXML.php');
require_once('../data/Server.php');
require_once('../radio/radio-utils.php');
......@@ -92,6 +93,7 @@ $method_map = array(
'album.addtags' => method_album_addTags,
'album.gettoptags' => method_album_getTopTags,
'album.gettags' => method_album_getTags,
'library.removescrobble'=> method_library_removeScrobble,
'user.getinfo' => method_user_getInfo,
'user.gettopartists' => method_user_getTopArtists,
'user.gettoptracks' => method_user_getTopTracks,
......@@ -886,6 +888,39 @@ function method_auth_getSession() {
}
}
/**
* library.removescrobble : Remove a scrobble
*
* ###Description
* Remove a scrobble from user's library
*
* #Parameters
* **timestamp** (required)
* **artist** (required)
* **track** (required)
* **sk** (required)
* **format** (optional)
*
* #Additional info
* **This method requires authentication**.
*
* **HTTP request method** : POST
* - - -
*
* @package Webservice
* @subpackage Library
* @api
*/
function method_library_removeScrobble() {
if (!isset($_POST['artist']) || !isset($_POST['track']) || !isset($_POST['timestamp'])) {
report_failure(LFM_INVALID_PARAMS);
}
$userid = get_userid();
$xml = LibraryXML::removeScrobble($userid, $_POST['timestamp'], $_POST['artist'], $_POST['track']);
respond($xml);
}
/**
* radio.tune : Tune in to a radio station
*
......
<?php
/* GNU FM -- a free network service for sharing your music listening habits
Copyright (C) 2013 Free Software Foundation, Inc
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
require_once($install_path . '/data/Library.php');
require_once('xml.php');
/**
* Class with functions that returns XML-formatted data involving a user's library.
*
* These functions are mainly used by web service methods.
*
* @package API
*/
class LibraryXML {
public static function removeScrobble($userid, $timestamp, $artist, $track) {
$result = Library::removeScrobble($userid, $timestamp, $artist, $track);
if (!$result) {
return XML::error('error', '7', 'Invalid resource specified');
}
$xml = new SimpleXMLElement('<lfm status="ok"></lfm>');
return $xml;
}
}
<?php
/* GNU FM -- a free network service for sharing your music listening habits
Copyright (C) 2009 Free Software Foundation, Inc
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
require_once($install_path . '/database.php');
require_once($install_path . '/data/sanitize.php');
/**
* Provides access to functions involving a user's library.
*/
class Library {
/**
* Remove a scrobble.
*
* @param int userid User ID.
* @param int timestamp
* @param string artist Artist name.
* @param string track Track name.
* @return bool True if scrobble was removed, False if not.
*/
function removeScrobble($userid, $timestamp, $artist, $track) {
global $adodb;
$delete_query = 'DELETE FROM Scrobbles WHERE userid=? AND time=? AND artist=? AND track=?';
$delete_params = array($userid, $timestamp, $artist, $track);
// TODO Should we have a db trigger for this?
$update_stats_query = 'UPDATE User_Stats SET scrobble_count=scrobble_count-1 WHERE userid=?';
$update_stats_params = array($userid);
$adodb->StartTrans();
try {
$adodb->Execute($delete_query, $delete_params);
$delete_count = $adodb->Affected_Rows();
if($delete_count) {
$adodb->Execute($update_stats_query, $update_stats_params);
}
} catch (Exception $e) {
$adodb->FailTrans();
$adodb->CompleteTrans();
reportError($e->getMessage(), $e->getTraceAsString());
return False;
}
$adodb->CompleteTrans();
return (bool)$delete_count;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment