mirror of
https://github.com/Yetangitu/ampache
synced 2025-10-03 09:49:30 +02:00
Some cleanup of play URL handling
Move parsing from Song into Stream_URL and make it parse more things. Add the type parameter to all generated URLs instead of adding video to Video URLs.
This commit is contained in:
parent
31afde9fc0
commit
239ea81fdf
7 changed files with 55 additions and 43 deletions
|
@ -496,17 +496,15 @@ class Api {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* url_to_song
|
* url_to_song
|
||||||
|
*
|
||||||
* This takes a url and returns the song object in question
|
* This takes a url and returns the song object in question
|
||||||
*/
|
*/
|
||||||
public static function url_to_song($input) {
|
public static function url_to_song($input) {
|
||||||
|
|
||||||
// Don't scrub, the function needs her raw and juicy
|
// Don't scrub, the function needs her raw and juicy
|
||||||
$song_id = Song::parse_song_url($input['url']);
|
$data = Stream_URL::parse($input['url']);
|
||||||
|
|
||||||
ob_end_clean();
|
ob_end_clean();
|
||||||
echo XML_Data::songs(array($song_id));
|
echo XML_Data::songs(array($data['id']));
|
||||||
|
}
|
||||||
} // url_to_song
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* playlists
|
* playlists
|
||||||
|
|
|
@ -1961,11 +1961,10 @@ class Catalog extends database_object {
|
||||||
|
|
||||||
} // if it's a file
|
} // if it's a file
|
||||||
// Check to see if it's a url from this ampache instance
|
// Check to see if it's a url from this ampache instance
|
||||||
elseif (substr($value,0,strlen(Config::get('web_path'))) == Config::get('web_path')) {
|
elseif (substr($value, 0, strlen(Config::get('web_path'))) == Config::get('web_path')) {
|
||||||
$song_id = intval(Song::parse_song_url($value));
|
$data = Stream_URL::parse($value);
|
||||||
|
$sql = 'SELECT COUNT(*) FROM `song` WHERE `id` = ?';
|
||||||
$sql = "SELECT COUNT(*) FROM `song` WHERE `id`='$song_id'";
|
$db_results = Dba::read($sql, array($data['id']));
|
||||||
$db_results = Dba::read($sql);
|
|
||||||
|
|
||||||
if (Dba::num_rows($db_results)) {
|
if (Dba::num_rows($db_results)) {
|
||||||
$songs[] = $song_id;
|
$songs[] = $song_id;
|
||||||
|
|
|
@ -923,36 +923,12 @@ class Song extends database_object implements media {
|
||||||
|
|
||||||
$song_name = rawurlencode($song->get_artist_name() . " - " . $song->title . "." . $type);
|
$song_name = rawurlencode($song->get_artist_name() . " - " . $song->title . "." . $type);
|
||||||
|
|
||||||
$url = Stream::get_base_url() . "oid=$song->id&uid=$user_id&name=/$song_name";
|
$url = Stream::get_base_url() . "type=song&oid=$song->id&uid=$user_id&name=/$song_name";
|
||||||
|
|
||||||
return $url;
|
return $url;
|
||||||
|
|
||||||
} // play_url
|
} // play_url
|
||||||
|
|
||||||
/**
|
|
||||||
* parse_song_url
|
|
||||||
* Takes a URL from this ampache install and returns the song that the url represents
|
|
||||||
* used by the API, and used to parse out stream urls for localplay
|
|
||||||
* right now just gets song id might do more later, hence the complexity
|
|
||||||
*/
|
|
||||||
public static function parse_song_url($url) {
|
|
||||||
|
|
||||||
// We only care about the question mark stuff
|
|
||||||
$query = parse_url($url,PHP_URL_QUERY);
|
|
||||||
|
|
||||||
$elements = explode("&",$query);
|
|
||||||
|
|
||||||
foreach ($elements as $items) {
|
|
||||||
list($key,$value) = explode("=",$items);
|
|
||||||
if ($key == 'oid') {
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
} // end foreach
|
|
||||||
|
|
||||||
return false;
|
|
||||||
|
|
||||||
} // parse_song_url
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get_recently_played
|
* get_recently_played
|
||||||
* This function returns the last X songs that have been played
|
* This function returns the last X songs that have been played
|
||||||
|
|
|
@ -374,17 +374,16 @@ class Stream_Playlist {
|
||||||
} // create_localplay
|
} // create_localplay
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create_democratic
|
* create_democratic
|
||||||
|
*
|
||||||
* This 'votes' on the songs it inserts them into
|
* This 'votes' on the songs it inserts them into
|
||||||
* a tmp_playlist with user of -1 (System)
|
* a tmp_playlist with user of -1 (System)
|
||||||
*/
|
*/
|
||||||
public function create_democratic() {
|
public function create_democratic() {
|
||||||
|
|
||||||
$democratic = Democratic::get_current_playlist();
|
$democratic = Democratic::get_current_playlist();
|
||||||
$democratic->set_parent();
|
$democratic->set_parent();
|
||||||
$democratic->add_vote($this->media);
|
$democratic->add_vote($this->urls);
|
||||||
|
}
|
||||||
} // create_democratic
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create_download
|
* create_download
|
||||||
|
|
|
@ -27,4 +27,33 @@ class Stream_URL extends memory_object {
|
||||||
|
|
||||||
public $properties = array('url', 'title', 'author', 'time', 'info_url', 'image_url', 'album', 'type');
|
public $properties = array('url', 'title', 'author', 'time', 'info_url', 'image_url', 'album', 'type');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* parse
|
||||||
|
*
|
||||||
|
* Takes an url and parses out all the chewy goodness.
|
||||||
|
*/
|
||||||
|
public static function parse($url) {
|
||||||
|
$query = parse_url($url, PHP_URL_QUERY);
|
||||||
|
$elements = explode('&', $query);
|
||||||
|
$results = array();
|
||||||
|
|
||||||
|
foreach ($elements as $element) {
|
||||||
|
list($key, $value) = explode('=', $items, 1);
|
||||||
|
switch ($key) {
|
||||||
|
case 'oid':
|
||||||
|
$key = 'id';
|
||||||
|
break;
|
||||||
|
case 'video':
|
||||||
|
if (make_bool($value)) {
|
||||||
|
$results['type'] = 'video';
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
// Nothing
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$results[$key] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $results;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,7 +99,7 @@ class Video extends database_object implements media {
|
||||||
$uid = intval($GLOBALS['user']->id);
|
$uid = intval($GLOBALS['user']->id);
|
||||||
$oid = intval($video->id);
|
$oid = intval($video->id);
|
||||||
|
|
||||||
$url = Stream::get_base_url() . "video=true&uid=$uid&oid=$oid";
|
$url = Stream::get_base_url() . "type=video&uid=$uid&oid=$oid";
|
||||||
|
|
||||||
return $url;
|
return $url;
|
||||||
|
|
||||||
|
|
|
@ -37,12 +37,23 @@ $oid = $_REQUEST['oid']
|
||||||
// FIXME: Any place that doesn't use oid should be fixed
|
// FIXME: Any place that doesn't use oid should be fixed
|
||||||
? scrub_in($_REQUEST['oid'])
|
? scrub_in($_REQUEST['oid'])
|
||||||
: scrub_in($_REQUEST['song']);
|
: scrub_in($_REQUEST['song']);
|
||||||
|
$otype = scrub_in($_REQUEST['otype']);
|
||||||
$sid = scrub_in($_REQUEST['ssid']);
|
$sid = scrub_in($_REQUEST['ssid']);
|
||||||
$xml_rpc = scrub_in($_REQUEST['xml_rpc']);
|
$xml_rpc = scrub_in($_REQUEST['xml_rpc']);
|
||||||
$video = make_bool($_REQUEST['video']);
|
$video = make_bool($_REQUEST['video']);
|
||||||
$type = scrub_in($_REQUEST['type']);
|
$type = scrub_in($_REQUEST['type']);
|
||||||
$transcode_to = scrub_in($_REQUEST['transcode_to']);
|
$transcode_to = scrub_in($_REQUEST['transcode_to']);
|
||||||
|
|
||||||
|
if ($video) {
|
||||||
|
// FIXME: Compatibility hack, should eventually be removed
|
||||||
|
$type = 'video';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$type) {
|
||||||
|
// FIXME: Compatibility hack, should eventually be removed
|
||||||
|
$type = 'song';
|
||||||
|
}
|
||||||
|
|
||||||
if ($type == 'playlist') {
|
if ($type == 'playlist') {
|
||||||
$playlist_type = scrub_in($_REQUEST['playlist_type']);
|
$playlist_type = scrub_in($_REQUEST['playlist_type']);
|
||||||
$oid = $sid;
|
$oid = $sid;
|
||||||
|
@ -174,7 +185,7 @@ if ($random) {
|
||||||
}
|
}
|
||||||
} // if random
|
} // if random
|
||||||
|
|
||||||
if (!$video) {
|
if ($type == 'song') {
|
||||||
/* Base Checks passed create the song object */
|
/* Base Checks passed create the song object */
|
||||||
$media = new Song($oid);
|
$media = new Song($oid);
|
||||||
$media->format();
|
$media->format();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue