mirror of
https://github.com/Yetangitu/ampache
synced 2025-10-03 09:49:30 +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
|
@ -196,7 +196,7 @@ class Browse extends Query
|
|||
debug_event('browse', 'Show objects called for type {'.$type.'}', '5');
|
||||
|
||||
$limit_threshold = $this->get_threshold();
|
||||
|
||||
|
||||
// Switch on the type of browsing we're doing
|
||||
switch ($type) {
|
||||
case 'song':
|
||||
|
@ -505,7 +505,7 @@ class Browse extends Query
|
|||
{
|
||||
return $this->_state['update_session'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $threshold
|
||||
|
@ -514,7 +514,7 @@ class Browse extends Query
|
|||
{
|
||||
$this->_state['threshold'] = $threshold;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
|
|
|
@ -150,12 +150,12 @@ class Stats
|
|||
if ($threshold) {
|
||||
$date = time() - (86400*$threshold);
|
||||
}
|
||||
|
||||
|
||||
$sql = "SELECT COUNT(*) AS `object_cnt` FROM `object_count` WHERE `object_type`= ? AND `object_id` = ? AND `count_type` = ?";
|
||||
if ($date) {
|
||||
$sql .= "AND `date` >= '" . $date . "'";
|
||||
}
|
||||
|
||||
|
||||
$db_results = Dba::read($sql, array($object_type, $object_id, $count_type));
|
||||
|
||||
$results = Dba::fetch_assoc($db_results);
|
||||
|
|
|
@ -903,7 +903,7 @@ class Subsonic_Api
|
|||
$size = $input['size']; // For video streaming. Not supported.
|
||||
$estimateContentLength = $input['estimateContentLength']; // Force content-length guessing if transcode
|
||||
|
||||
$params = '&client=' . $input['c'];
|
||||
$params = '&client=' . rawurlencode($input['c']) . '&noscrobble=1';
|
||||
if ($estimateContentLength == 'true') {
|
||||
$params .= '&content_length=required';
|
||||
}
|
||||
|
@ -940,7 +940,7 @@ class Subsonic_Api
|
|||
|
||||
$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);
|
||||
}
|
||||
|
||||
|
@ -1496,6 +1496,42 @@ class Subsonic_Api
|
|||
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 ****/
|
||||
|
||||
/**
|
||||
|
@ -1525,21 +1561,6 @@ class Subsonic_Api
|
|||
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
|
||||
* Get all podcast channels.
|
||||
|
|
|
@ -805,9 +805,9 @@ class User extends database_object
|
|||
* update_user_stats
|
||||
* 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->format();
|
||||
$user = $this->id;
|
||||
|
@ -815,19 +815,22 @@ class User extends database_object
|
|||
// We shouldn't test on file only
|
||||
if (!strlen($media->file)) { return false; }
|
||||
|
||||
$this->set_preferences();
|
||||
|
||||
// If pthreads available, we call save_songplay in a new thread to quickly return
|
||||
if (class_exists("Thread", false)) {
|
||||
debug_event('user.class.php', 'Calling save_mediaplay plugins in a new thread...', '5');
|
||||
$thread = new scrobbler_async($GLOBALS['user'], $media);
|
||||
if ($thread->start()) {
|
||||
//$thread->join();
|
||||
if (!$noscrobble) {
|
||||
$this->set_preferences();
|
||||
// If pthreads available, we call save_songplay in a new thread to quickly return
|
||||
if (class_exists("Thread", false)) {
|
||||
debug_event('user.class.php', 'Calling save_mediaplay plugins in a new thread...', 5);
|
||||
$thread = new scrobbler_async($GLOBALS['user'], $media);
|
||||
if ($thread->start()) {
|
||||
//$thread->join();
|
||||
} else {
|
||||
debug_event('user.class.php', 'Error when starting the thread.', 1);
|
||||
}
|
||||
} else {
|
||||
debug_event('user.class.php', 'Error when starting the thread.', '1');
|
||||
User::save_mediaplay($GLOBALS['user'], $media);
|
||||
}
|
||||
} else {
|
||||
User::save_mediaplay($GLOBALS['user'], $media);
|
||||
debug_event('user.class.php', 'Scrobbling explicitly skipped', 5);
|
||||
}
|
||||
|
||||
$media->set_played($user, $agent, $location);
|
||||
|
|
|
@ -585,11 +585,11 @@ if (!isset($_REQUEST['segment'])) {
|
|||
} else {
|
||||
if (!$share_id) {
|
||||
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();
|
||||
$agent = Session::agent($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']));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -144,4 +144,4 @@
|
|||
</table>
|
||||
<?php UI::show_box_bottom(); ?>
|
||||
|
||||
<?php UI::show_box_bottom(); ?>
|
||||
<?php UI::show_box_bottom(); ?>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue