1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
<?php
/*
Copyright (c) 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.
*/
/*!
@function addToPlaylist()
@discussion adds a bunch of songs to the mpd playlist
this takes a mpd object, and an array of songs
*/
function addToPlaylist( $myMpd, $song_ids=array()) {
foreach( $song_ids as $song_id ) {
/* There are two ways to do this, filename or URL */
if (conf('mpd_method') == 'url') {
// We just need to generate a standard stream URL and pass that
$song = new Song($song_id);
$sess_id = session_id();
if ($song->type == ".flac") { $song->type = ".ogg"; }
if ($GLOBALS['user']->prefs['play_type'] == 'downsample') {
$ds = $GLOBALS['user']->prefs['sample_rate'];
}
$song_url = conf('web_path') . "/play/index.php?song=$song_id&uid=" . $_SESSION['userdata']['username'] . "&sid=$sess_id&ds=$ds&name=." . $song->type;
if (is_null( $myMpd->PlAdd($song_url) ) ) {
$log_line = _("Error") . ": " . _("Could not add") . ": " . $song_url . " : " . $myMpd->errStr;
echo "<font class=\"error\">$log_line</font><br />\n";
if (conf('debug')) { log_event($GLOBALS['user']->username,'add',$log_line); }
} // if it's null
} // if we want urls
else {
$song = new Song( $song_id );
$song_filename = $song->get_rel_path();
if( is_null( $myMpd->PLAdd( $song_filename ) ) ) {
$log_line = _("Error") . ": " . _("Could not add") . ": " . $song_filename . " : " . $myMpd->errStr;
echo "<font class=\"error\">$log_line</font><br />\n";
if (conf('debug')) { log_event($_SESSION['userdata']['username'],'add',$log_line); }
} // end if it's null
// We still need to count if they use the file method
else {
$GLOBALS['user']->update_stats( $song_id );
} // end else
} // end else not url method
} // end foreach
} // addToPlaylist
/*!
@function show_mpd_control
@discussion shows the mpd controls
*/
function show_mpd_control() {
$_REQUEST['action'] = 'show_control';
require (conf('prefix').'/amp-mpd.php');
} // show_mpd_control
/**
* show_mpd_pl
* Shows the MPD playlist
* @package Local Play
* @catagory MPD
*/
function show_mpd_pl() {
$myMpd = init_mpd();
require (conf('prefix').'/templates/show_mpdpl.inc');
} // show_mpd_pl
/**
* mpd_redirect
* Redriect mojo
* @package Local Play
* @catagory MPD
* @param $page is the URL after conf('web_path') . '/'
*/
function mpd_redirect( $page = 'mpd.php' ) {
if (conf('localplay_menu')) {
header ("Location: " . conf('web_path') . '/' . $page);
}
else {
header ("Location: " . conf('web_path'));
}
} // mpd_redirect
/**
* Init MPD - This is originally from /amp-mpd.php
* This initializes MPD if it is the playback method.
* It checks to see if a global variable called myMpd is an object
* if it's not then it attempt to create one and return it
* @package Local Play
* @catagory MPD
*/
function init_mpd() {
static $myMpd;
if (!conf('allow_mpd_playback')) { return false; }
if (!is_object($myMpd)) {
$myMpd = new mpd(conf('mpd_host'),conf('mpd_port'));
}
if (!$myMpd->connected AND is_object($myMpd)) {
// Attempt to reconnect
$myMpd->Connect();
}
if (!$myMpd->connected) {
if (conf('debug')) {
log_event ($_SESSION['userdata']['username'],' connection_failed ',"Error: unable to connect to ". conf('mpd_host') . " on port " . conf('mpd_port') . " ".$myMpd->errStr);
}
return false;
}
return $myMpd;
} // function init_mpd()
?>
|