1
0
Fork 0
mirror of https://github.com/Yetangitu/ampache synced 2025-10-06 03:49:56 +02:00

Add optional client name when playing

This commit is contained in:
Afterster 2013-12-07 09:41:20 +01:00
parent 51cff99ef6
commit f50d8a93a5
6 changed files with 47 additions and 37 deletions

View file

@ -287,7 +287,7 @@ class Plex_Api
$id = Plex_XML_Data::getAmpacheId($key); $id = Plex_XML_Data::getAmpacheId($key);
$song = new Song($id); $song = new Song($id);
if ($song->id) { if ($song->id) {
$url = Song::play_url($id); $url = Song::play_url($id) . '&client=Plex';
header("Location: " . $url); header("Location: " . $url);
} else { } else {
self::createError(404); self::createError(404);

View file

@ -75,45 +75,47 @@ class Recommendation
$xml = self::get_lastfm_results('track.getsimilar', $query); $xml = self::get_lastfm_results('track.getsimilar', $query);
foreach ($xml->similartracks->children() as $child) { if ($xml->similartracks) {
$name = $child->name; foreach ($xml->similartracks->children() as $child) {
$local_id = null; $name = $child->name;
$local_id = null;
$artist_name = $child->artist->name; $artist_name = $child->artist->name;
$s_artist_name = Catalog::trim_prefix($artist_name); $s_artist_name = Catalog::trim_prefix($artist_name);
$s_artist_name = Dba::escape($s_artist_name['string']); $s_artist_name = Dba::escape($s_artist_name['string']);
$sql = "SELECT `song`.`id` FROM `song` " . $sql = "SELECT `song`.`id` FROM `song` " .
"LEFT JOIN `artist` ON " . "LEFT JOIN `artist` ON " .
"`song`.`artist`=`artist`.`id` WHERE " . "`song`.`artist`=`artist`.`id` WHERE " .
"`song`.`title`='" . Dba::escape($name) . "`song`.`title`='" . Dba::escape($name) .
"' AND `artist`.`name`='$s_artist_name'"; "' AND `artist`.`name`='$s_artist_name'";
$db_result = Dba::read($sql); $db_result = Dba::read($sql);
if ($result = Dba::fetch_assoc($db_result)) { if ($result = Dba::fetch_assoc($db_result)) {
$local_id = $result['id']; $local_id = $result['id'];
} }
if (is_null($local_id)) { if (is_null($local_id)) {
debug_event('Recommendation', "$name did not match any local song", 5); debug_event('Recommendation', "$name did not match any local song", 5);
if (! $local_only) { if (! $local_only) {
$results[] = array(
'id' => null,
'title' => $name,
'artist' => $artist_name
);
}
} else {
debug_event('Recommendation', "$name matched local song $local_id", 5);
$results[] = array( $results[] = array(
'id' => null, 'id' => $local_id,
'title' => $name, 'title' => $name
'artist' => $artist_name
); );
} }
} else {
debug_event('Recommendation', "$name matched local song $local_id", 5);
$results[] = array(
'id' => $local_id,
'title' => $name
);
}
if ($limit && count($results) >= $limit) { if ($limit && count($results) >= $limit) {
break; break;
}
} }
} }

View file

@ -197,7 +197,7 @@ class Session
$ip = $_SERVER['REMOTE_ADDR'] ? inet_pton($_SERVER['REMOTE_ADDR']) : '0'; $ip = $_SERVER['REMOTE_ADDR'] ? inet_pton($_SERVER['REMOTE_ADDR']) : '0';
$type = $data['type']; $type = $data['type'];
$value = $data['value']; $value = $data['value'];
$agent = substr($_SERVER['HTTP_USER_AGENT'], 0, 254); $agent = (!empty($data['agent'])) ? $data['agent'] : substr($_SERVER['HTTP_USER_AGENT'], 0, 254);
if ($type == 'stream') { if ($type == 'stream') {
$expire = time() + Config::get('stream_length'); $expire = time() + Config::get('stream_length');

View file

@ -284,7 +284,12 @@ class Stream
public static function _auto_init() public static function _auto_init()
{ {
// Generate the session ID. This is slightly wasteful. // Generate the session ID. This is slightly wasteful.
self::$session = Session::create(array('type' => 'stream')); $data = array();
$data['type'] = 'stream';
if (isset($_REQUEST['client'])) {
$data['agent'] = $_REQUEST['client'];
}
self::$session = Session::create($data);
} }
/** /**

View file

@ -777,7 +777,7 @@ class Subsonic_Api
$maxBitRate = $input['maxBitRate']; // For video streaming. Not supported. $maxBitRate = $input['maxBitRate']; // For video streaming. Not supported.
$estimateContentLength = $input['estimateContentLength']; // Not supported. $estimateContentLength = $input['estimateContentLength']; // Not supported.
$url = Song::play_url(Subsonic_XML_Data::getAmpacheId($fileid)); $url = Song::play_url(Subsonic_XML_Data::getAmpacheId($fileid)) . '&client=' . $input['c'];
self::follow_stream($url); self::follow_stream($url);
} }
@ -792,7 +792,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'; $url = Song::play_url(Subsonic_XML_Data::getAmpacheId($fileid)) . '&action=download' . '&client=' . $input['c'];
self::follow_stream($url); self::follow_stream($url);
} }

View file

@ -55,6 +55,10 @@ if (empty($password)) {
$version = $_GET['v']; $version = $_GET['v'];
$clientapp = $_GET['c']; $clientapp = $_GET['c'];
if (empty($_SERVER['HTTP_USER_AGENT'])) {
$_SERVER['HTTP_USER_AGENT'] = $clientapp;
}
if (empty($user) || empty($password) || empty($version) || empty($action) || empty($clientapp)) { if (empty($user) || empty($password) || empty($version) || empty($action) || empty($clientapp)) {
ob_end_clean(); ob_end_clean();
Subsonic_Api::apiOutput2($f, Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_MISSINGPARAM)); Subsonic_Api::apiOutput2($f, Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_MISSINGPARAM));
@ -82,12 +86,11 @@ if (!$auth['success']) {
if (!Access::check_network('init-api', $user, 5)) { if (!Access::check_network('init-api', $user, 5)) {
debug_event('Access Denied','Unauthorized access attempt to Subsonic API [' . $_SERVER['REMOTE_ADDR'] . ']', '3'); debug_event('Access Denied','Unauthorized access attempt to Subsonic API [' . $_SERVER['REMOTE_ADDR'] . ']', '3');
ob_end_clean(); ob_end_clean();
Subsonic_Api::apiOutput2($f, Subsonic_XML_Data::createError(SSERROR_UNAUTHORIZED, 'Unauthorized access attempt to Subsonic API - ACL Error')); Subsonic_Api::apiOutput2($f, Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_UNAUTHORIZED, 'Unauthorized access attempt to Subsonic API - ACL Error'));
exit(); exit();
} }
$GLOBALS['user'] = User::get_from_username($user); $GLOBALS['user'] = User::get_from_username($user);
// Check server version // Check server version
if (version_compare(Subsonic_XML_Data::API_VERSION, $version) < 0) { if (version_compare(Subsonic_XML_Data::API_VERSION, $version) < 0) {
ob_end_clean(); ob_end_clean();