forked from alexballas/MPDream
-
Notifications
You must be signed in to change notification settings - Fork 0
/
playlist.php
214 lines (186 loc) · 5.58 KB
/
playlist.php
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<?php
require("./include/mpd.class.php");
$config = parse_ini_file("./include/config.ini");
function is_odd( $int )
{
return( $int % 2 );
}
$Mpd = new mpd($config["server"], $config["port"], $config["password"] == "" ? null : $config["password"]);
if (!$Mpd->connected) {
die("Could not connect to MPD server.");
}
$currenttrackid = $Mpd->current_track_id;
$m_currenttrackid = $Mpd->current_track_id;
$memcache = new Memcache;
$memcache->connect('localhost', 11211) or die ("Could not connect");
if ($m_currenttrackid < 0) {
$m_currenttrackid = 0;
$memcache->delete('mpdplaylist');
}
$playlist_results1 = $memcache->get('mpdplaylist');
if (is_null($playlist_results1[$currenttrackid]["Title"])) {
$memcache->delete('mpdplaylist');
}
if (!$memcache->get('mpdplaylist')) {
$Mpd->RefreshPlaylist();
$m_uplist = 200;
$m_downlist = $m_uplist * 2;
//temp Hack To load all songs and not just batches of 400s
$m_downlist = count($Mpd->playlist);
if (count($Mpd->playlist) < $m_downlist) {
$m_downlist = count($Mpd->playlist) - 1;
}
if ($m_currenttrackid < 0) {
$pollapanw = 0;
$pollakatw = 0;
}
else {
$pollapanw = $m_currenttrackid;
$pollakatw = $m_currenttrackid;
}
for( $i=0; $i<$m_uplist; $i++ )
{
if ($pollapanw > 0) { $pollapanw -= 1; $newpollapanw[$i] = $pollapanw; }
}
$m_magicnumber = $m_downlist - count($newpollapanw);
for( $i=0; $i<$m_magicnumber; $i++ )
{
$pollakatw += 1;
$newpollakatw[$i] = $pollakatw;
}
if (count($newpollapanw) > 0) {
$newpollapanw = array_reverse($newpollapanw);
foreach($newpollapanw as $varrr) {
if (is_null($Mpd->playlist[$varrr]["Title"])) {
$Mpd->playlist[$varrr]["Title"] = "<i>NO TITLE</i>";
}
if (is_null($Mpd->playlist[$varrr]["Artist"])) {
$Mpd->playlist[$varrr]["Artist"] = "<i>NO ARTIST</i>";
}
$memarray[$varrr]["Title"] = $Mpd->playlist[$varrr]["Title"];
$memarray[$varrr]["Artist"] = $Mpd->playlist[$varrr]["Artist"];
}
}
if (is_null($Mpd->playlist[$m_currenttrackid]["Title"])) {
$Mpd->playlist[$m_currenttrackid]["Title"] = "<i>NO TITLE</i>";
}
if (is_null($Mpd->playlist[$m_currenttrackid]["Artist"])) {
$Mpd->playlist[$m_currenttrackid]["Artist"] = "<i>NO ARTIST</i>";
}
$memarray[$m_currenttrackid]["Title"] = $Mpd->playlist[$m_currenttrackid]["Title"];
$memarray[$m_currenttrackid]["Artist"] = $Mpd->playlist[$m_currenttrackid]["Artist"];
for( $i=0; $i<$m_magicnumber; $i++ )
{
$qq = $newpollakatw[$i];
if (!$Mpd->playlist[$qq]["file"]) { break; }
if ($qq) {
if (is_null($Mpd->playlist[$qq]["Title"])) {
$Mpd->playlist[$qq]["Title"] = "<i>NO TITLE</i>";
}
if (is_null($Mpd->playlist[$qq]["Artist"])) {
$Mpd->playlist[$qq]["Artist"] = "<i>NO ARTIST</i>";
}
}
$memarray[$qq]["Title"] = $Mpd->playlist[$qq]["Title"];
$memarray[$qq]["Artist"] = $Mpd->playlist[$qq]["Artist"];
}
$mpdlistcount = count($Mpd->playlist);
$memcache->set('mpdplaylist',$memarray, false, 40) or die ("Failed to save data at the server");
$memcache->set('mpdplaylistcount',$mpdlistcount, false, 40) or die ("Failed to save data at the server");
}
$playlist_results = $memcache->get('mpdplaylist');
$uplist = 2;
$downlist = 8;
//temp Hack To load all songs and not just batches of 400s
$uplist = count($playlist_results);
$downlist = count($playlist_results);
if (count($playlist_results) < $downlist) {
$downlist = count($playlist_results) - 1;
}
if ($currenttrackid < 0) {
$dekapanw = 0;
$dekakatw = 0;
}
else {
$dekapanw = $currenttrackid;
$dekakatw = $currenttrackid;
}
for( $i=0; $i<$uplist; $i++ )
{
if ($dekapanw > 0) { $dekapanw -= 1; $newdekapanw[$i] = $dekapanw; }
}
$magicnumber = $downlist - count($newdekapanw);
for( $i=0; $i<$magicnumber; $i++ )
{
$dekakatw += 1;
$newdekakatw[$i] = $dekakatw;
}
if (count($newdekapanw) > 0) {
$newdekapanw = array_reverse($newdekapanw);
foreach($newdekapanw as $varr) {
echo "<a onclick='clickplaylist(this.id);' id='$varr'>";
if (is_odd($varr)) {
echo "<div class='songlist songodd'>";
}
else {
echo "<div class='songlist songeven'>";
}
echo $varr . ". " . $playlist_results[$varr]["Title"];
echo "<br />";
echo "<b>from</b> " . $playlist_results[$varr]["Artist"];
echo "<br />";
echo "</div>";
echo "</a>";
}
}
if ($currenttrackid >= 0) {
echo "<a onclick='clickplaylist(this.id);' id='$currenttrackid'>";
if (is_odd($currenttrackid)) {
echo "<div class='songlist thesong'>";
}
else {
echo "<div class='songlist thesong'>";
}
echo $currenttrackid . ". " . $playlist_results[$currenttrackid]["Title"];
echo "<br />";
echo "<b>from</b> " . $playlist_results[$currenttrackid]["Artist"];
echo "<br />";
echo "</div>";
echo "</a>";
}
else {
$currenttrackid = 0;
echo "<a onclick='clickplaylist(this.id);' id='$currenttrackid'>";
if (is_odd($currenttrackid)) {
echo "<div class='songlist'>";
}
else {
echo "<div class='songlist'>";
}
echo $currenttrackid . ". " . $playlist_results[$currenttrackid]["Title"];
echo "<br />";
echo "<b>from</b> " . $playlist_results[$currenttrackid]["Artist"];
echo "<br />";
echo "</div>";
echo "</a>";
}
for( $i=0; $i<$magicnumber; $i++ )
{
if ((is_null($playlist_results[$newdekakatw[$i]]["Title"])) || (is_null($playlist_results[$newdekakatw[$i]]["Artist"]))) {
break;
}
echo "<a onclick='clickplaylist(this.id);' id='$newdekakatw[$i]'>";
if (is_odd($newdekakatw[$i])) {
echo "<div class='songlist songodd'>";
}
else {
echo "<div class='songlist songeven'>";
}
echo $newdekakatw[$i] . ". " . $playlist_results[$newdekakatw[$i]]["Title"];
echo "<br />";
echo "<b>from</b> " . $playlist_results[$newdekakatw[$i]]["Artist"];
echo "<br />";
echo "</div>";
echo "</a>";
}
?>