summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/class/api.class.php10
-rw-r--r--lib/class/catalog.class.php9
-rw-r--r--lib/class/song.class.php26
-rw-r--r--lib/class/stream_playlist.class.php9
-rw-r--r--lib/class/stream_url.class.php29
-rw-r--r--lib/class/video.class.php2
-rw-r--r--play/index.php13
7 files changed, 55 insertions, 43 deletions
diff --git a/lib/class/api.class.php b/lib/class/api.class.php
index e48786fd..b913c06d 100644
--- a/lib/class/api.class.php
+++ b/lib/class/api.class.php
@@ -496,17 +496,15 @@ class Api {
/**
* url_to_song
+ *
* This takes a url and returns the song object in question
*/
public static function url_to_song($input) {
-
// 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();
- echo XML_Data::songs(array($song_id));
-
- } // url_to_song
+ echo XML_Data::songs(array($data['id']));
+ }
/**
* playlists
diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php
index 3b164317..21ef2d08 100644
--- a/lib/class/catalog.class.php
+++ b/lib/class/catalog.class.php
@@ -1961,11 +1961,10 @@ class Catalog extends database_object {
} // if it's a file
// 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')) {
- $song_id = intval(Song::parse_song_url($value));
-
- $sql = "SELECT COUNT(*) FROM `song` WHERE `id`='$song_id'";
- $db_results = Dba::read($sql);
+ elseif (substr($value, 0, strlen(Config::get('web_path'))) == Config::get('web_path')) {
+ $data = Stream_URL::parse($value);
+ $sql = 'SELECT COUNT(*) FROM `song` WHERE `id` = ?';
+ $db_results = Dba::read($sql, array($data['id']));
if (Dba::num_rows($db_results)) {
$songs[] = $song_id;
diff --git a/lib/class/song.class.php b/lib/class/song.class.php
index 3d865b25..fa4e1f0c 100644
--- a/lib/class/song.class.php
+++ b/lib/class/song.class.php
@@ -923,37 +923,13 @@ class Song extends database_object implements media {
$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;
} // 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
* This function returns the last X songs that have been played
* it uses the popular threshold to figure out how many to pull
diff --git a/lib/class/stream_playlist.class.php b/lib/class/stream_playlist.class.php
index a49f47d0..ae16dfb0 100644
--- a/lib/class/stream_playlist.class.php
+++ b/lib/class/stream_playlist.class.php
@@ -374,17 +374,16 @@ class Stream_Playlist {
} // create_localplay
/**
- * create_democratic
+ * create_democratic
+ *
* This 'votes' on the songs it inserts them into
* a tmp_playlist with user of -1 (System)
*/
public function create_democratic() {
-
$democratic = Democratic::get_current_playlist();
$democratic->set_parent();
- $democratic->add_vote($this->media);
-
- } // create_democratic
+ $democratic->add_vote($this->urls);
+ }
/**
* create_download
diff --git a/lib/class/stream_url.class.php b/lib/class/stream_url.class.php
index d651ca59..22a5777c 100644
--- a/lib/class/stream_url.class.php
+++ b/lib/class/stream_url.class.php
@@ -27,4 +27,33 @@ class Stream_URL extends memory_object {
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;
+ }
}
diff --git a/lib/class/video.class.php b/lib/class/video.class.php
index 8299cf8d..6ed14702 100644
--- a/lib/class/video.class.php
+++ b/lib/class/video.class.php
@@ -99,7 +99,7 @@ class Video extends database_object implements media {
$uid = intval($GLOBALS['user']->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;
diff --git a/play/index.php b/play/index.php
index 238e963f..db965f33 100644
--- a/play/index.php
+++ b/play/index.php
@@ -37,12 +37,23 @@ $oid = $_REQUEST['oid']
// FIXME: Any place that doesn't use oid should be fixed
? scrub_in($_REQUEST['oid'])
: scrub_in($_REQUEST['song']);
+$otype = scrub_in($_REQUEST['otype']);
$sid = scrub_in($_REQUEST['ssid']);
$xml_rpc = scrub_in($_REQUEST['xml_rpc']);
$video = make_bool($_REQUEST['video']);
$type = scrub_in($_REQUEST['type']);
$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') {
$playlist_type = scrub_in($_REQUEST['playlist_type']);
$oid = $sid;
@@ -174,7 +185,7 @@ if ($random) {
}
} // if random
-if (!$video) {
+if ($type == 'song') {
/* Base Checks passed create the song object */
$media = new Song($oid);
$media->format();