summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorPaul Arthur <paul.arthur@flowerysong.com>2013-02-07 14:24:40 -0500
committerPaul Arthur <paul.arthur@flowerysong.com>2013-02-07 14:24:40 -0500
commit239ea81fdf2fa2bda8a8556e19412264396fe52a (patch)
tree0d753486ec6ded74cb4adb1a7e70dd9ce4ccfda6 /lib
parent31afde9fc07a766229681a13d2cce0825e9fec93 (diff)
downloadampache-239ea81fdf2fa2bda8a8556e19412264396fe52a.tar.gz
ampache-239ea81fdf2fa2bda8a8556e19412264396fe52a.tar.bz2
ampache-239ea81fdf2fa2bda8a8556e19412264396fe52a.zip
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.
Diffstat (limited to 'lib')
-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
6 files changed, 43 insertions, 42 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;