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:
parent
51cff99ef6
commit
f50d8a93a5
6 changed files with 47 additions and 37 deletions
|
@ -287,7 +287,7 @@ class Plex_Api
|
|||
$id = Plex_XML_Data::getAmpacheId($key);
|
||||
$song = new Song($id);
|
||||
if ($song->id) {
|
||||
$url = Song::play_url($id);
|
||||
$url = Song::play_url($id) . '&client=Plex';
|
||||
header("Location: " . $url);
|
||||
} else {
|
||||
self::createError(404);
|
||||
|
|
|
@ -75,45 +75,47 @@ class Recommendation
|
|||
|
||||
$xml = self::get_lastfm_results('track.getsimilar', $query);
|
||||
|
||||
foreach ($xml->similartracks->children() as $child) {
|
||||
$name = $child->name;
|
||||
$local_id = null;
|
||||
if ($xml->similartracks) {
|
||||
foreach ($xml->similartracks->children() as $child) {
|
||||
$name = $child->name;
|
||||
$local_id = null;
|
||||
|
||||
$artist_name = $child->artist->name;
|
||||
$s_artist_name = Catalog::trim_prefix($artist_name);
|
||||
$s_artist_name = Dba::escape($s_artist_name['string']);
|
||||
$artist_name = $child->artist->name;
|
||||
$s_artist_name = Catalog::trim_prefix($artist_name);
|
||||
$s_artist_name = Dba::escape($s_artist_name['string']);
|
||||
|
||||
$sql = "SELECT `song`.`id` FROM `song` " .
|
||||
"LEFT JOIN `artist` ON " .
|
||||
"`song`.`artist`=`artist`.`id` WHERE " .
|
||||
"`song`.`title`='" . Dba::escape($name) .
|
||||
"' AND `artist`.`name`='$s_artist_name'";
|
||||
$sql = "SELECT `song`.`id` FROM `song` " .
|
||||
"LEFT JOIN `artist` ON " .
|
||||
"`song`.`artist`=`artist`.`id` WHERE " .
|
||||
"`song`.`title`='" . Dba::escape($name) .
|
||||
"' AND `artist`.`name`='$s_artist_name'";
|
||||
|
||||
$db_result = Dba::read($sql);
|
||||
$db_result = Dba::read($sql);
|
||||
|
||||
if ($result = Dba::fetch_assoc($db_result)) {
|
||||
$local_id = $result['id'];
|
||||
}
|
||||
if ($result = Dba::fetch_assoc($db_result)) {
|
||||
$local_id = $result['id'];
|
||||
}
|
||||
|
||||
if (is_null($local_id)) {
|
||||
debug_event('Recommendation', "$name did not match any local song", 5);
|
||||
if (! $local_only) {
|
||||
if (is_null($local_id)) {
|
||||
debug_event('Recommendation', "$name did not match any local song", 5);
|
||||
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(
|
||||
'id' => null,
|
||||
'title' => $name,
|
||||
'artist' => $artist_name
|
||||
'id' => $local_id,
|
||||
'title' => $name
|
||||
);
|
||||
}
|
||||
} else {
|
||||
debug_event('Recommendation', "$name matched local song $local_id", 5);
|
||||
$results[] = array(
|
||||
'id' => $local_id,
|
||||
'title' => $name
|
||||
);
|
||||
}
|
||||
|
||||
if ($limit && count($results) >= $limit) {
|
||||
break;
|
||||
if ($limit && count($results) >= $limit) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -197,7 +197,7 @@ class Session
|
|||
$ip = $_SERVER['REMOTE_ADDR'] ? inet_pton($_SERVER['REMOTE_ADDR']) : '0';
|
||||
$type = $data['type'];
|
||||
$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') {
|
||||
$expire = time() + Config::get('stream_length');
|
||||
|
|
|
@ -284,7 +284,12 @@ class Stream
|
|||
public static function _auto_init()
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -777,7 +777,7 @@ class Subsonic_Api
|
|||
$maxBitRate = $input['maxBitRate']; // For video streaming. 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);
|
||||
}
|
||||
|
||||
|
@ -792,7 +792,7 @@ class Subsonic_Api
|
|||
|
||||
$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);
|
||||
}
|
||||
|
||||
|
|
|
@ -55,6 +55,10 @@ if (empty($password)) {
|
|||
$version = $_GET['v'];
|
||||
$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)) {
|
||||
ob_end_clean();
|
||||
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)) {
|
||||
debug_event('Access Denied','Unauthorized access attempt to Subsonic API [' . $_SERVER['REMOTE_ADDR'] . ']', '3');
|
||||
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();
|
||||
}
|
||||
|
||||
$GLOBALS['user'] = User::get_from_username($user);
|
||||
|
||||
// Check server version
|
||||
if (version_compare(Subsonic_XML_Data::API_VERSION, $version) < 0) {
|
||||
ob_end_clean();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue