mirror of
https://github.com/Yetangitu/ampache
synced 2025-10-06 03:49:56 +02:00
Remove scrobbling from stream and add Scrobble method support in SubSonic API
This commit is contained in:
parent
e988741988
commit
4fd3a636be
6 changed files with 61 additions and 37 deletions
|
@ -903,7 +903,7 @@ class Subsonic_Api
|
||||||
$size = $input['size']; // For video streaming. Not supported.
|
$size = $input['size']; // For video streaming. Not supported.
|
||||||
$estimateContentLength = $input['estimateContentLength']; // Force content-length guessing if transcode
|
$estimateContentLength = $input['estimateContentLength']; // Force content-length guessing if transcode
|
||||||
|
|
||||||
$params = '&client=' . $input['c'];
|
$params = '&client=' . rawurlencode($input['c']) . '&noscrobble=1';
|
||||||
if ($estimateContentLength == 'true') {
|
if ($estimateContentLength == 'true') {
|
||||||
$params .= '&content_length=required';
|
$params .= '&content_length=required';
|
||||||
}
|
}
|
||||||
|
@ -940,7 +940,7 @@ class Subsonic_Api
|
||||||
|
|
||||||
$fileid = self::check_parameter($input, 'id', true);
|
$fileid = self::check_parameter($input, 'id', true);
|
||||||
|
|
||||||
$url = Song::play_url(Subsonic_XML_Data::getAmpacheId($fileid), '&action=download' . '&client=' . $input['c'], function_exists('curl_version'));
|
$url = Song::play_url(Subsonic_XML_Data::getAmpacheId($fileid), '&action=download' . '&client=' . rawurlencode($input['c']) . '&noscrobble=1', function_exists('curl_version'));
|
||||||
self::follow_stream($url);
|
self::follow_stream($url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1496,6 +1496,42 @@ class Subsonic_Api
|
||||||
self::apiOutput($input, $r);
|
self::apiOutput($input, $r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* scrobble
|
||||||
|
* Scrobbles a given music file on last.fm.
|
||||||
|
* Takes the file id with optional time and submission parameters.
|
||||||
|
*/
|
||||||
|
public static function scrobble($input)
|
||||||
|
{
|
||||||
|
self::check_version($input, "1.5.0");
|
||||||
|
|
||||||
|
$id = self::check_parameter($input, 'id');
|
||||||
|
//$time = $input['time'];
|
||||||
|
//$submission = $input['submission'];
|
||||||
|
|
||||||
|
if (!is_array($id)) {
|
||||||
|
$rid = array();
|
||||||
|
$rid[] = $id;
|
||||||
|
$id = $rid;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($id as $i) {
|
||||||
|
$aid = Subsonic_XML_Data::getAmpacheId($i);
|
||||||
|
if (Subsonic_XML_Data::isVideo($i)) {
|
||||||
|
$type = 'video';
|
||||||
|
} else {
|
||||||
|
$type = 'song';
|
||||||
|
}
|
||||||
|
|
||||||
|
$media = new $type($aid);
|
||||||
|
$media->format();
|
||||||
|
$GLOBALS['user']->save_mediaplay($GLOBALS['user'], $media);
|
||||||
|
}
|
||||||
|
|
||||||
|
$r = Subsonic_XML_Data::createSuccessResponse();
|
||||||
|
self::apiOutput($input, $r);
|
||||||
|
}
|
||||||
|
|
||||||
/**** CURRENT UNSUPPORTED FUNCTIONS ****/
|
/**** CURRENT UNSUPPORTED FUNCTIONS ****/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1525,21 +1561,6 @@ class Subsonic_Api
|
||||||
self::apiOutput($input, $r);
|
self::apiOutput($input, $r);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* scrobble
|
|
||||||
* Scrobbles a given music file on last.fm.
|
|
||||||
* Takes the file id with optional time and submission parameters.
|
|
||||||
* Not supported. Already done by Ampache if plugin enabled.
|
|
||||||
*/
|
|
||||||
public static function scrobble($input)
|
|
||||||
{
|
|
||||||
self::check_version($input, "1.5.0");
|
|
||||||
|
|
||||||
// Ignore error to not break clients
|
|
||||||
$r = Subsonic_XML_Data::createSuccessResponse();
|
|
||||||
self::apiOutput($input, $r);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getPodcasts
|
* getPodcasts
|
||||||
* Get all podcast channels.
|
* Get all podcast channels.
|
||||||
|
|
|
@ -805,9 +805,9 @@ class User extends database_object
|
||||||
* update_user_stats
|
* update_user_stats
|
||||||
* updates the playcount mojo for this specific user
|
* updates the playcount mojo for this specific user
|
||||||
*/
|
*/
|
||||||
public function update_stats($media_type, $media_id, $agent = '', $location = array())
|
public function update_stats($media_type, $media_id, $agent = '', $location = array(), $noscrobble = false)
|
||||||
{
|
{
|
||||||
debug_event('user.class.php', 'Updating stats for {'.$media_type.'/'.$media_id.'} {'.$agent.'}...', '5');
|
debug_event('user.class.php', 'Updating stats for {'.$media_type.'/'.$media_id.'} {'.$agent.'}...', 5);
|
||||||
$media = new $media_type($media_id);
|
$media = new $media_type($media_id);
|
||||||
$media->format();
|
$media->format();
|
||||||
$user = $this->id;
|
$user = $this->id;
|
||||||
|
@ -815,20 +815,23 @@ class User extends database_object
|
||||||
// We shouldn't test on file only
|
// We shouldn't test on file only
|
||||||
if (!strlen($media->file)) { return false; }
|
if (!strlen($media->file)) { return false; }
|
||||||
|
|
||||||
|
if (!$noscrobble) {
|
||||||
$this->set_preferences();
|
$this->set_preferences();
|
||||||
|
|
||||||
// If pthreads available, we call save_songplay in a new thread to quickly return
|
// If pthreads available, we call save_songplay in a new thread to quickly return
|
||||||
if (class_exists("Thread", false)) {
|
if (class_exists("Thread", false)) {
|
||||||
debug_event('user.class.php', 'Calling save_mediaplay plugins in a new thread...', '5');
|
debug_event('user.class.php', 'Calling save_mediaplay plugins in a new thread...', 5);
|
||||||
$thread = new scrobbler_async($GLOBALS['user'], $media);
|
$thread = new scrobbler_async($GLOBALS['user'], $media);
|
||||||
if ($thread->start()) {
|
if ($thread->start()) {
|
||||||
//$thread->join();
|
//$thread->join();
|
||||||
} else {
|
} else {
|
||||||
debug_event('user.class.php', 'Error when starting the thread.', '1');
|
debug_event('user.class.php', 'Error when starting the thread.', 1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
User::save_mediaplay($GLOBALS['user'], $media);
|
User::save_mediaplay($GLOBALS['user'], $media);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
debug_event('user.class.php', 'Scrobbling explicitly skipped', 5);
|
||||||
|
}
|
||||||
|
|
||||||
$media->set_played($user, $agent, $location);
|
$media->set_played($user, $agent, $location);
|
||||||
|
|
||||||
|
|
|
@ -585,11 +585,11 @@ if (!isset($_REQUEST['segment'])) {
|
||||||
} else {
|
} else {
|
||||||
if (!$share_id) {
|
if (!$share_id) {
|
||||||
if ($_SERVER['REQUEST_METHOD'] != 'HEAD') {
|
if ($_SERVER['REQUEST_METHOD'] != 'HEAD') {
|
||||||
debug_event('play', 'Registering stream stats for {'.$media->get_stream_name() .'}...', '5');
|
debug_event('play', 'Registering stream stats for {'.$media->get_stream_name() .'}...', 5);
|
||||||
$sessionkey = $sid ?: Stream::get_session();
|
$sessionkey = $sid ?: Stream::get_session();
|
||||||
$agent = Session::agent($sessionkey);
|
$agent = Session::agent($sessionkey);
|
||||||
$location = Session::get_geolocation($sessionkey);
|
$location = Session::get_geolocation($sessionkey);
|
||||||
$GLOBALS['user']->update_stats($type, $media->id, $agent, $location);
|
$GLOBALS['user']->update_stats($type, $media->id, $agent, $location, isset($_REQUEST['noscrobble']));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue