summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarl 'vollmerk' Vollmer <vollmer@ampache.org>2006-04-06 06:16:02 +0000
committerKarl 'vollmerk' Vollmer <vollmer@ampache.org>2006-04-06 06:16:02 +0000
commit065e228c184aa3043dbb93c701d8c2a8cfb05b1e (patch)
treee827b0a4edb07957a8a0b80edfe5edccb698f6e5
parent3b0791a0e038937b6d1dab49e6599aff5f48a4ab (diff)
downloadampache-065e228c184aa3043dbb93c701d8c2a8cfb05b1e.tar.gz
ampache-065e228c184aa3043dbb93c701d8c2a8cfb05b1e.tar.bz2
ampache-065e228c184aa3043dbb93c701d8c2a8cfb05b1e.zip
added a new function to song and added a untested mpd controller
-rw-r--r--lib/class/localplay.class.php22
-rw-r--r--lib/class/song.class.php29
-rwxr-xr-xmodules/kajax/ajax.js45
-rwxr-xr-xmodules/kajax/driver.php13
-rw-r--r--modules/localplay/mpd.controller.php214
5 files changed, 322 insertions, 1 deletions
diff --git a/lib/class/localplay.class.php b/lib/class/localplay.class.php
index 4c96f559..9e9cabaf 100644
--- a/lib/class/localplay.class.php
+++ b/lib/class/localplay.class.php
@@ -65,6 +65,28 @@ class Localplay {
/**
+ * _load_player
+ * This function attempts to load the player class that localplay
+ * Will interface with in order to make all this magical stuf work
+ * all LocalPlay modules should be located in /modules/<name>/<name>.class.php
+ */
+ function _load_player() {
+
+ $filename = conf('prefix') . '/modules/localplay/' . $this->type . '.controller.php';
+ $include = require_once ($filename);
+
+ if (!$include) {
+ /* Throw Error Here */
+
+ } // include
+ else {
+ $class_name = $this->type;
+ $this->_player = new $class_name();
+ }
+
+ } // _load_player
+
+ /**
* has_function
* This is used to check the function map and see if the current
* player type supports the indicated function.
diff --git a/lib/class/song.class.php b/lib/class/song.class.php
index d0868de2..ddaa96e7 100644
--- a/lib/class/song.class.php
+++ b/lib/class/song.class.php
@@ -697,7 +697,34 @@ class Song {
return stripslashes($matches[1]);
} // get_info_from_filename
-
+
+ /**
+ * get_url
+ * This function takes all the song information and correctly formats
+ * a stream URL taking into account the downsampling mojo and everything
+ * else, this is used or will be used by _EVERYTHING_
+ */
+ function get_url() {
+
+ /* Define Variables we are going to need */
+ $username = $GLOBALS['user']->username;
+ $song_id = $this->id;
+ $session = session_id();
+ $type = $this->type;
+
+ if ($GLOBALS['user']->prefs['play_type'] == 'downsample') {
+ $ds_string = "&ds=" . $GLOBALS['user']->prefs['sample_rate'];
+ }
+
+ /* Account for retarded players */
+ if ($song->type == 'flac') { $type = 'ogg'; }
+
+ $url = conf('web_path') . "/play/index.php?song=$song_id&uid=$username&sid=$session$ds_string&name=$type";
+
+ return $url;
+
+ } // get_url
+
/*!
@function native_stream
@discussion returns true if the $song->type streams ok, false if it must be transcoded to stream
diff --git a/modules/kajax/ajax.js b/modules/kajax/ajax.js
new file mode 100755
index 00000000..9920f4d4
--- /dev/null
+++ b/modules/kajax/ajax.js
@@ -0,0 +1,45 @@
+<script type="text/javascript">
+ //var xmlDoc = null;
+ var http_request = false;
+ var IE = true;
+
+ function makeRequest(url,getTerms) {
+ if (window.ActiveXObject) { // IE
+ try {
+ http_request = new ActiveXObject("Msxml2.XMLHTTP");
+ }
+ catch (e) {
+ try {
+ http_request = new ActiveXObject("Microsoft.XMLHTTP");
+ }
+ catch (e) {}
+ }
+ }
+ else { // Mozilla
+ IE = false;
+ http_request = new XMLHttpRequest();
+ }
+ if (!http_request) {
+ return false;
+ }
+ http_request.onreadystatechange = function() {};
+ http_request.open('GET', url+"?"+getTerms, false);
+ http_request.send(null);
+ }
+
+ function getContents(http_request) {
+ if (http_request.readyState == 4) {
+ if (http_request.status == 200) {
+
+ }
+ }
+ }
+
+ function ajaxPut(url,getTerms,uid) {
+ makeRequest(url,getTerms);
+
+ data = http_request.responseTXT;
+ document.getElementById(uid).innerHTML = data;
+ }
+
+</script>
diff --git a/modules/kajax/driver.php b/modules/kajax/driver.php
new file mode 100755
index 00000000..5cb4edbb
--- /dev/null
+++ b/modules/kajax/driver.php
@@ -0,0 +1,13 @@
+<?
+ Copyright 2006 Kevin Riker
+ All Rights Reserved
+
+$url = "query.php";
+$get = "search=hello";
+
+require_once('ajax.js');
+
+echo "<script type=\"text/javascript\">
+ javascript:makeRequest(\"$url\",\"$get\");
+</script>";
+?>
diff --git a/modules/localplay/mpd.controller.php b/modules/localplay/mpd.controller.php
new file mode 100644
index 00000000..19ceab70
--- /dev/null
+++ b/modules/localplay/mpd.controller.php
@@ -0,0 +1,214 @@
+<?php
+/*
+
+ Copyright 2001 - 2006 Ampache.org
+ All Rights Reserved
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+
+/**
+ * AmpacheMpd Class
+ * the Ampache Mpd Controller, this is the glue between
+ * the MPD class and the Ampahce Localplay class
+ */
+class AmpacheMpd {
+
+ /* Variables */
+
+
+ /* Constructed variables */
+ $_mpd;
+
+ /**
+ * Constructor
+ * This returns the array map for the localplay object
+ * REQUIRED for Localplay
+ */
+ function AmpacheMpd() {
+
+ /* Do a Require Once On the needed Libraries */
+ require_once(conf('prefix') . '/modules/mpd/mpd.class.php');
+
+ $map = array();
+
+ $map['add'] = 'add_songs';
+ $map['delete'] = 'delete_songs';
+ $map['play'] = 'play';
+ $map['stop'] = 'stop';
+ $map['get'] = 'get_songs';
+ $map['connect'] = 'connect';
+
+ return $map;
+
+ } // AmpacheMpd
+
+
+ /**
+ * preference
+ * This function returns an array of the preferences and their
+ * information for Ampache to use All preferences will get a
+ * localplay_mpd_ appended to their name to avoid conflicts
+ * however this controller does not need to take that into acount
+ * REQUIRE for Locaplay
+ */
+ function preferences() {
+
+ $preferences = array();
+
+ $preferences[] = array('name'=>'hostname','default'=>'localhost','type'=>'string');
+ $preferences[] = array('name'=>'port','default'=>'6600','type'=>'integer');
+ $preferences[] = array('name'=>'password','default'=>'','type'=>'string');
+
+ return $preferences;
+
+ } // preferences
+
+
+ /**
+ * add_songs
+ * This must take an array of URL's from Ampache
+ * and then add them to MPD
+ */
+ function add_songs($songs) {
+
+ foreach ($songs as $song_id) {
+ $song = new Song($song_id);
+ $url = $song->get_url();
+ if (is_null($this->_mpd->PlAdd($url)) {
+ debug_event('mpd_add','Error: Unable to add $url to MPD ' . $this->_mpd->errStr,'1');
+ }
+
+ } // end foreach
+
+ return true;
+
+ } // add_songs
+
+
+ /**
+ * delete_songs
+ * This must take an array of ID's (as passed by get function) from Ampache
+ * and delete them from MPD
+ */
+ function delete_songs($songs) {
+
+ /* Default to true */
+ $return = true;
+
+ /* This should be an array of UID's as returned by
+ * the get function so that we can just call the class based
+ * functions to remove them or if there isn't a uid for
+ * the songs, then however ya'll have stored them
+ * in this controller
+ */
+ foreach ($songs as $uid) {
+
+ if (is_null($this->_mpd->PLRemove($uid)) { $return = false; }
+
+ } // foreach of songs
+
+ return $return;
+
+ } // delete_songs
+
+
+ /**
+ * play
+ * This just tells MPD to start playing, it does not
+ * take any arguments
+ */
+ function play() {
+
+ if (is_null($this->_mpd->Play()) { return false; }
+
+ return true;
+
+ } // play
+
+ /**
+ * stop
+ * This just tells MPD to stop playing, it does not take
+ * any arguments
+ */
+ function stop() {
+
+ if (is_null($this->_mpd->Stop()) { return false; }
+
+ return true;
+
+ } // stop
+
+
+ /**
+ * get_songs
+ * This functions returns an array containing information about
+ * The songs that MPD currently has in it's playlist. This must be
+ * done in a standardized fashion
+ */
+ function get_songs() {
+
+ /* Get the Current Playlist */
+ $playlist = $this->_mpd->playlist;
+
+ foreach ($playlist as $key=>$entry) {
+
+ $data = array();
+
+ /* Required Elements */
+ $data['id'] = $entry['Pos'];
+ $data['raw'] = $entry['file'];
+
+ /* Optional Elements */
+ $data['name'] = '';
+
+ $results[] = $data;
+
+ } // foreach playlist items
+
+ } // get_songs
+
+ /**
+ * get_status
+ * This returns bool/int values for features, loop, repeat and any other features
+ * That this localplay method support
+ */
+ function get_status() {
+
+
+
+
+ } // get_status
+
+ /**
+ * connect
+ * This functions creates the connection to MPD and returns
+ * a boolean value for the status, to save time this handle
+ * is stored in this class
+ */
+ function connect() {
+
+ $this->_mpd = new mpd(conf('localplay_mpd_hostnmae'),conf('localplay_mpd_port'));
+
+ if ($this->_mpd->connected) { return true; }
+
+ return false;
+
+ } // connect
+
+} //end of AmpacheMpd
+
+?>