1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Audio Player |
4
|
|
|
* |
5
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
6
|
|
|
* later. See the LICENSE.md file. |
7
|
|
|
* |
8
|
|
|
* @author Marcel Scherello <[email protected]> |
9
|
|
|
* @copyright 2016-2019 Marcel Scherello |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace OCA\audioplayer\Controller; |
13
|
|
|
|
14
|
|
|
use OCP\AppFramework\Controller; |
15
|
|
|
use OCP\AppFramework\Http\JSONResponse; |
16
|
|
|
use OCP\Files\InvalidPathException; |
17
|
|
|
use OCP\IRequest; |
18
|
|
|
use OCP\IL10N; |
19
|
|
|
use OCP\IDbConnection; |
20
|
|
|
use OCP\ITagManager; |
21
|
|
|
use OCP\Files\IRootFolder; |
22
|
|
|
use OCP\ILogger; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Controller class for main page. |
26
|
|
|
*/ |
27
|
|
|
class CategoryController extends Controller |
28
|
|
|
{ |
29
|
|
|
|
30
|
|
|
private $userId; |
31
|
|
|
private $l10n; |
32
|
|
|
private $db; |
33
|
|
|
private $tagger; |
34
|
|
|
private $tagManager; |
35
|
|
|
private $rootFolder; |
36
|
|
|
private $logger; |
37
|
|
|
private $DBController; |
38
|
|
|
|
39
|
|
|
public function __construct( |
40
|
|
|
$appName, |
41
|
|
|
IRequest $request, |
42
|
|
|
$userId, |
43
|
|
|
IL10N $l10n, |
44
|
|
|
IDBConnection $db, |
45
|
|
|
ITagManager $tagManager, |
46
|
|
|
IRootFolder $rootFolder, |
47
|
|
|
ILogger $logger, |
48
|
|
|
DbController $DBController |
49
|
|
|
) |
50
|
|
|
{ |
51
|
|
|
parent::__construct($appName, $request); |
52
|
|
|
$this->userId = $userId; |
53
|
|
|
$this->l10n = $l10n; |
54
|
|
|
$this->db = $db; |
55
|
|
|
$this->tagManager = $tagManager; |
56
|
|
|
$this->tagger = null; |
57
|
|
|
$this->rootFolder = $rootFolder; |
58
|
|
|
$this->logger = $logger; |
59
|
|
|
$this->DBController = $DBController; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @NoAdminRequired |
64
|
|
|
* @param $category |
65
|
|
|
* @return JSONResponse |
66
|
|
|
*/ |
67
|
|
|
public function getCategory($category) |
68
|
|
|
{ |
69
|
|
|
$playlists = $this->getCategoryDetails($category); |
70
|
|
|
|
71
|
|
|
$result = empty($playlists) ? [ |
72
|
|
|
'status' => 'nodata' |
73
|
|
|
] : [ |
74
|
|
|
'status' => 'success', |
75
|
|
|
'data' => $playlists |
76
|
|
|
]; |
77
|
|
|
$response = new JSONResponse(); |
78
|
|
|
$response->setData($result); |
79
|
|
|
return $response; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Get the categories items for a user |
84
|
|
|
* |
85
|
|
|
* @param string $category |
86
|
|
|
* @return array |
87
|
|
|
*/ |
88
|
|
|
private function getCategoryDetails($category) |
89
|
|
|
{ |
90
|
|
|
$SQL = null; |
91
|
|
|
$aPlaylists = array(); |
92
|
|
|
if ($category === 'Artist') { |
93
|
|
|
$SQL = "SELECT DISTINCT(`AT`.`artist_id`) AS `id`, `AA`.`name`, LOWER(`AA`.`name`) AS `lower` |
94
|
|
|
FROM `*PREFIX*audioplayer_tracks` `AT` |
95
|
|
|
JOIN `*PREFIX*audioplayer_artists` `AA` |
96
|
|
|
ON `AA`.`id` = `AT`.`artist_id` |
97
|
|
|
WHERE `AT`.`user_id` = ? |
98
|
|
|
ORDER BY LOWER(`AA`.`name`) ASC |
99
|
|
|
"; |
100
|
|
|
} elseif ($category === 'Genre') { |
101
|
|
|
$SQL = "SELECT `id`, `name`, LOWER(`name`) AS `lower` |
102
|
|
|
FROM `*PREFIX*audioplayer_genre` |
103
|
|
|
WHERE `user_id` = ? |
104
|
|
|
ORDER BY LOWER(`name`) ASC |
105
|
|
|
"; |
106
|
|
|
} elseif ($category === 'Year') { |
107
|
|
|
$SQL = "SELECT DISTINCT(`year`) AS `id` ,`year` AS `name` |
108
|
|
|
FROM `*PREFIX*audioplayer_tracks` |
109
|
|
|
WHERE `user_id` = ? |
110
|
|
|
ORDER BY `id` ASC |
111
|
|
|
"; |
112
|
|
|
} elseif ($category === 'Title') { |
113
|
|
|
$SQL = "SELECT distinct('0') as `id` ,'" . $this->l10n->t('All Titles') . "' as `name` |
114
|
|
|
FROM `*PREFIX*audioplayer_tracks` |
115
|
|
|
WHERE `user_id` = ? |
116
|
|
|
"; |
117
|
|
|
} elseif ($category === 'Playlist') { |
118
|
|
|
$aPlaylists[] = array("id" => "X1", "name" => $this->l10n->t('Favorites')); |
119
|
|
|
$aPlaylists[] = array("id" => "X2", "name" => $this->l10n->t('Recently Added')); |
120
|
|
|
$aPlaylists[] = array("id" => "X3", "name" => $this->l10n->t('Recently Played')); |
121
|
|
|
$aPlaylists[] = array("id" => "X4", "name" => $this->l10n->t('Most Played')); |
122
|
|
|
$aPlaylists[] = array("id" => "", "name" => ""); |
123
|
|
|
|
124
|
|
|
// Stream files are shown directly |
125
|
|
|
$SQL = "SELECT `file_id` AS `id`, `title` AS `name`, LOWER(`title`) AS `lower` |
126
|
|
|
FROM `*PREFIX*audioplayer_streams` |
127
|
|
|
WHERE `user_id` = ? |
128
|
|
|
ORDER BY LOWER(`title`) ASC |
129
|
|
|
"; |
130
|
|
|
$stmt = $this->db->prepare($SQL); |
131
|
|
|
$stmt->execute(array($this->userId)); |
132
|
|
|
$results = $stmt->fetchAll(); |
133
|
|
|
foreach ($results as $row) { |
134
|
|
|
array_splice($row, 2, 1); |
135
|
|
|
$row['id'] = 'S' . $row['id']; |
136
|
|
|
$aPlaylists[] = $row; |
137
|
|
|
} |
138
|
|
|
$aPlaylists[] = array("id" => "", "name" => ""); |
139
|
|
|
|
140
|
|
|
// regular playlists are selected |
141
|
|
|
$SQL = "SELECT `id`,`name`, LOWER(`name`) AS `lower` |
142
|
|
|
FROM `*PREFIX*audioplayer_playlists` |
143
|
|
|
WHERE `user_id` = ? |
144
|
|
|
ORDER BY LOWER(`name`) ASC |
145
|
|
|
"; |
146
|
|
|
|
147
|
|
|
} elseif ($category === 'Folder') { |
148
|
|
|
$SQL = "SELECT DISTINCT(`FC`.`fileid`) AS `id`, `FC`.`name`, LOWER(`FC`.`name`) AS `lower` |
149
|
|
|
FROM `*PREFIX*audioplayer_tracks` `AT` |
150
|
|
|
JOIN `*PREFIX*filecache` `FC` |
151
|
|
|
ON `FC`.`fileid` = `AT`.`folder_id` |
152
|
|
|
WHERE `AT`.`user_id` = ? |
153
|
|
|
ORDER BY LOWER(`FC`.`name`) ASC |
154
|
|
|
"; |
155
|
|
|
} elseif ($category === 'Album') { |
156
|
|
|
$SQL = "SELECT `AB`.`id` , `AB`.`name`, LOWER(`AB`.`name`) AS `lower` , `AA`.`id` AS `art`, `AB`.`cover` AS `cid` |
157
|
|
|
FROM `*PREFIX*audioplayer_albums` `AB` |
158
|
|
|
LEFT JOIN `*PREFIX*audioplayer_artists` `AA` |
159
|
|
|
ON `AB`.`artist_id` = `AA`.`id` |
160
|
|
|
WHERE `AB`.`user_id` = ? |
161
|
|
|
ORDER BY LOWER(`AB`.`name`) ASC |
162
|
|
|
"; |
163
|
|
|
} elseif ($category === 'Album Artist') { |
164
|
|
|
$SQL = "SELECT DISTINCT(`AB`.`artist_id`) AS `id`, `AA`.`name`, LOWER(`AA`.`name`) AS `lower` |
165
|
|
|
FROM `*PREFIX*audioplayer_albums` `AB` |
166
|
|
|
JOIN `*PREFIX*audioplayer_artists` `AA` |
167
|
|
|
ON `AB`.`artist_id` = `AA`.`id` |
168
|
|
|
WHERE `AB`.`user_id` = ? |
169
|
|
|
ORDER BY LOWER(`AA`.`name`) ASC |
170
|
|
|
"; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
if (isset($SQL)) { |
174
|
|
|
$stmt = $this->db->prepare($SQL); |
175
|
|
|
$stmt->execute(array($this->userId)); |
176
|
|
|
$results = $stmt->fetchAll(); |
177
|
|
|
foreach ($results as $row) { |
178
|
|
|
if ($category === 'Album') { |
179
|
|
|
$row['art'] = $this->DBController->loadArtistsToAlbum($row['id'], $row['art']); |
180
|
|
|
if ($row['cid'] !== null) { |
181
|
|
|
$row['cid'] = $row['id']; |
182
|
|
|
} else { |
183
|
|
|
$row['cid'] = ''; |
184
|
|
|
} |
185
|
|
|
} |
186
|
|
|
array_splice($row, 2, 1); |
187
|
|
|
if ($row['name'] === '0' OR $row['name'] === '') $row['name'] = $this->l10n->t('Unknown'); |
188
|
|
|
$row['cnt'] = $this->getCategoryCount($category, $row['id']); |
189
|
|
|
$aPlaylists[] = $row; |
190
|
|
|
} |
191
|
|
|
} |
192
|
|
|
return $aPlaylists; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* @NoAdminRequired |
197
|
|
|
* @param $category |
198
|
|
|
* @param $categoryId |
199
|
|
|
* @return JSONResponse |
200
|
|
|
*/ |
201
|
|
|
public function getCategoryCover($category, $categoryId) |
202
|
|
|
{ |
203
|
|
|
$playlists = $this->getCatagoryCoverDetails($category, $categoryId); |
204
|
|
|
|
205
|
|
|
$result = empty($playlists) ? [ |
206
|
|
|
'status' => 'nodata' |
207
|
|
|
] : [ |
208
|
|
|
'status' => 'success', |
209
|
|
|
'data' => $playlists |
210
|
|
|
]; |
211
|
|
|
$response = new JSONResponse(); |
212
|
|
|
$response->setData($result); |
213
|
|
|
return $response; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* Get details for the cover view |
218
|
|
|
* |
219
|
|
|
* @param string $category |
220
|
|
|
* @param string $categoryId |
221
|
|
|
* @return array |
222
|
|
|
*/ |
223
|
|
|
private function getCatagoryCoverDetails($category, $categoryId) |
224
|
|
|
{ |
225
|
|
|
$whereMatching = array('Artist' => '`AT`.`artist_id`', 'Genre' => '`AT`.`genre_id`', 'Album' => '`AB`.`id`', 'Album Artist' => '`AB`.`artist_id`', 'Year' => '`AT`.`year`', 'Folder' => '`AT`.`folder_id`'); |
226
|
|
|
|
227
|
|
|
$aPlaylists = array(); |
228
|
|
|
$SQL = "SELECT `AB`.`id` , `AB`.`name`, LOWER(`AB`.`name`) AS `lower` , `AA`.`id` AS `art`, `AB`.`cover` AS `cid`"; |
229
|
|
|
$SQL .= " FROM `*PREFIX*audioplayer_tracks` `AT`"; |
230
|
|
|
$SQL .= " LEFT JOIN `*PREFIX*audioplayer_artists` `AA` ON `AT`.`artist_id` = `AA`.`id`"; |
231
|
|
|
$SQL .= " LEFT JOIN `*PREFIX*audioplayer_albums` `AB` ON `AT`.`album_id` = `AB`.`id`"; |
232
|
|
|
$SQL .= ' WHERE `AT`.`user_id` = ? '; |
233
|
|
|
if ($categoryId) $SQL .= 'AND ' . $whereMatching[$category] . '= ?'; |
234
|
|
|
$SQL .= " GROUP BY `AB`.`id` ORDER BY LOWER(`AB`.`name`) ASC"; |
235
|
|
|
|
236
|
|
|
if (isset($SQL)) { |
237
|
|
|
$stmt = $this->db->prepare($SQL); |
238
|
|
|
if ($categoryId) { |
239
|
|
|
$stmt->execute(array($this->userId, $categoryId)); |
240
|
|
|
} else { |
241
|
|
|
$stmt->execute(array($this->userId)); |
242
|
|
|
} |
243
|
|
|
$results = $stmt->fetchAll(); |
244
|
|
|
foreach ($results as $row) { |
245
|
|
|
$row['art'] = $this->DBController->loadArtistsToAlbum($row['id'], $row['art']); |
246
|
|
|
if ($row['cid'] !== null) { |
247
|
|
|
$row['cid'] = $row['id']; |
248
|
|
|
} else { |
249
|
|
|
$row['cid'] = ''; |
250
|
|
|
} |
251
|
|
|
array_splice($row, 2, 1); |
252
|
|
|
if ($row['name'] === '0' OR $row['name'] === '') $row['name'] = $this->l10n->t('Unknown'); |
253
|
|
|
$aPlaylists[] = $row; |
254
|
|
|
} |
255
|
|
|
} |
256
|
|
|
return $aPlaylists; |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
/** |
260
|
|
|
* Get the number of items for a category item |
261
|
|
|
* |
262
|
|
|
* @param string $category |
263
|
|
|
* @param integer $categoryId |
264
|
|
|
* @return integer |
265
|
|
|
*/ |
266
|
|
|
private function getCategoryCount($category, $categoryId) |
267
|
|
|
{ |
268
|
|
|
$SQL = array(); |
269
|
|
|
$SQL['Artist'] = "SELECT COUNT(`AT`.`id`) AS `count` FROM `*PREFIX*audioplayer_tracks` `AT` LEFT JOIN `*PREFIX*audioplayer_artists` `AA` ON `AT`.`artist_id` = `AA`.`id` WHERE `AT`.`artist_id` = ? AND `AT`.`user_id` = ?"; |
270
|
|
|
$SQL['Genre'] = "SELECT COUNT(`AT`.`id`) AS `count` FROM `*PREFIX*audioplayer_tracks` `AT` WHERE `AT`.`genre_id` = ? AND `AT`.`user_id` = ?"; |
271
|
|
|
$SQL['Year'] = "SELECT COUNT(`AT`.`id`) AS `count` FROM `*PREFIX*audioplayer_tracks` `AT` WHERE `AT`.`year` = ? AND `AT`.`user_id` = ?"; |
272
|
|
|
$SQL['Title'] = "SELECT COUNT(`AT`.`id`) AS `count` FROM `*PREFIX*audioplayer_tracks` `AT` WHERE `AT`.`id` > ? AND `AT`.`user_id` = ?"; |
273
|
|
|
$SQL['Playlist'] = "SELECT COUNT(`AT`.`id`) AS `count` FROM `*PREFIX*audioplayer_playlist_tracks` `AT` WHERE `AP`.`playlist_id` = ?"; |
274
|
|
|
$SQL['Folder'] = "SELECT COUNT(`AT`.`id`) AS `count` FROM `*PREFIX*audioplayer_tracks` `AT` WHERE `AT`.`folder_id` = ? AND `AT`.`user_id` = ?"; |
275
|
|
|
$SQL['Album'] = "SELECT COUNT(`AT`.`id`) AS `count` FROM `*PREFIX*audioplayer_tracks` `AT` WHERE `AT`.`album_id` = ? AND `AT`.`user_id` = ?"; |
276
|
|
|
$SQL['Album Artist'] = "SELECT COUNT(`AT`.`id`) AS `count`FROM `*PREFIX*audioplayer_albums` `AB` JOIN `*PREFIX*audioplayer_tracks` `AT` ON `AB`.`id` = `AT`.`album_id` WHERE `AB`.`artist_id` = ? AND `AB`.`user_id` = ?"; |
277
|
|
|
|
278
|
|
|
$stmt = $this->db->prepare($SQL[$category]); |
279
|
|
|
if ($category === 'Playlist') { |
280
|
|
|
$stmt->execute(array($categoryId)); |
281
|
|
|
} else { |
282
|
|
|
$stmt->execute(array($categoryId, $this->userId)); |
283
|
|
|
} |
284
|
|
|
$results = $stmt->fetch(); |
285
|
|
|
return $results['count']; |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
/** |
289
|
|
|
* AJAX function to get playlist titles for a selected category |
290
|
|
|
* @NoAdminRequired |
291
|
|
|
* |
292
|
|
|
* @param string $category |
293
|
|
|
* @param string $categoryId |
294
|
|
|
* @return JSONResponse |
295
|
|
|
* @throws InvalidPathException |
296
|
|
|
*/ |
297
|
|
|
public function getCategoryItems($category, $categoryId) |
298
|
|
|
{ |
299
|
|
|
if ($categoryId[0] === "S") $category = "Stream"; |
300
|
|
|
if ($categoryId[0] === "P") $category = "Playlist"; |
301
|
|
|
$items = $this->getCatagoryItemsDetails($category, $categoryId); |
302
|
|
|
$headers = $this->getCategoryHeaders($category); |
303
|
|
|
|
304
|
|
|
$result = !empty($items) ? [ |
305
|
|
|
'status' => 'success', |
306
|
|
|
'data' => $items, |
307
|
|
|
'header' => $headers, |
308
|
|
|
] : [ |
309
|
|
|
'status' => 'nodata', |
310
|
|
|
]; |
311
|
|
|
$response = new JSONResponse(); |
312
|
|
|
$response->setData($result); |
313
|
|
|
return $response; |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
/** |
317
|
|
|
* Get playlist titles for a selected category |
318
|
|
|
* |
319
|
|
|
* @param string $category |
320
|
|
|
* @param string $categoryId |
321
|
|
|
* @return array |
322
|
|
|
* @throws InvalidPathException |
323
|
|
|
* @throws NotFoundException |
324
|
|
|
*/ |
325
|
|
|
private function getCatagoryItemsDetails($category, $categoryId) |
326
|
|
|
{ |
327
|
|
|
$SQL = null; |
328
|
|
|
$favorite = false; |
329
|
|
|
$aTracks = array(); |
330
|
|
|
$SQL_select = "SELECT `AT`.`id`, `AT`.`title` AS `cl1`, `AA`.`name` AS `cl2`, `AB`.`name` AS `cl3`, `AT`.`length` AS `len`, `AT`.`file_id` AS `fid`, `AT`.`mimetype` AS `mim`, `AB`.`id` AS `cid`, `AB`.`cover`, LOWER(`AB`.`name`) AS `lower`"; |
331
|
|
|
$SQL_from = " FROM `*PREFIX*audioplayer_tracks` `AT` |
332
|
|
|
LEFT JOIN `*PREFIX*audioplayer_artists` `AA` ON `AT`.`artist_id` = `AA`.`id` |
333
|
|
|
LEFT JOIN `*PREFIX*audioplayer_albums` `AB` ON `AT`.`album_id` = `AB`.`id`"; |
334
|
|
|
$SQL_order = " ORDER BY LOWER(`AB`.`name`) ASC, `AT`.`disc` ASC, `AT`.`number` ASC"; |
335
|
|
|
|
336
|
|
|
if ($category === 'Artist') { |
337
|
|
|
$SQL_select = "SELECT `AT`.`id`, `AT`.`title` AS `cl1`, `AB`.`name` AS `cl2`, `AT`.`year` AS `cl3`, `AT`.`length` AS `len`, `AT`.`file_id` AS `fid`, `AT`.`mimetype` AS `mim`, `AB`.`id` AS `cid`, `AB`.`cover`, LOWER(`AB`.`name`) AS `lower`"; |
338
|
|
|
$SQL = $SQL_select . $SQL_from . |
339
|
|
|
"WHERE `AT`.`artist_id` = ? AND `AT`.`user_id` = ?" . |
340
|
|
|
$SQL_order; |
341
|
|
|
} elseif ($category === 'Genre') { |
342
|
|
|
$SQL = $SQL_select . $SQL_from . |
343
|
|
|
"WHERE `AT`.`genre_id` = ? AND `AT`.`user_id` = ?" . |
344
|
|
|
$SQL_order; |
345
|
|
|
} elseif ($category === 'Year') { |
346
|
|
|
$SQL = $SQL_select . $SQL_from . |
347
|
|
|
"WHERE `AT`.`year` = ? AND `AT`.`user_id` = ?" . |
348
|
|
|
$SQL_order; |
349
|
|
|
} elseif ($category === 'Title') { |
350
|
|
|
$SQL = $SQL_select . $SQL_from . |
351
|
|
|
"WHERE `AT`.`id` > ? AND `AT`.`user_id` = ?" . |
352
|
|
|
$SQL_order; |
353
|
|
|
} elseif ($category === 'Playlist' AND $categoryId === "X1") { // Favorites |
354
|
|
|
$SQL = "SELECT `AT`.`id` , `AT`.`title` AS `cl1`,`AA`.`name` AS `cl2`, `AB`.`name` AS `cl3`,`AT`.`length` AS `len`, `AT`.`file_id` AS `fid`, `AT`.`mimetype` AS `mim`, `AB`.`id` AS `cid`, `AB`.`cover`, LOWER(`AT`.`title`) AS `lower`" . |
355
|
|
|
$SQL_from . |
356
|
|
|
"WHERE `AT`.`id` <> ? AND `AT`.`user_id` = ?" . |
357
|
|
|
" ORDER BY LOWER(`AT`.`title`) ASC"; |
358
|
|
|
$categoryId = 0; //overwrite to integer for PostgreSQL |
359
|
|
|
$favorite = true; |
360
|
|
|
} elseif ($category === 'Playlist' AND $categoryId === "X2") { // Recently Added |
361
|
|
|
$SQL = $SQL_select . $SQL_from . |
362
|
|
|
"WHERE `AT`.`id` <> ? AND `AT`.`user_id` = ? |
363
|
|
|
ORDER BY `AT`.`file_id` DESC |
364
|
|
|
Limit 100"; |
365
|
|
|
$categoryId = 0; |
366
|
|
|
} elseif ($category === 'Playlist' AND $categoryId === "X3") { // Recently Played |
367
|
|
|
$SQL = $SQL_select . $SQL_from . |
368
|
|
|
"LEFT JOIN `*PREFIX*audioplayer_stats` `AS` ON `AT`.`id` = `AS`.`track_id` |
369
|
|
|
WHERE `AS`.`id` <> ? AND `AT`.`user_id` = ? |
370
|
|
|
ORDER BY `AS`.`playtime` DESC |
371
|
|
|
Limit 50"; |
372
|
|
|
$categoryId = 0; |
373
|
|
|
} elseif ($category === 'Playlist' AND $categoryId === "X4") { // Most Played |
374
|
|
|
$SQL = $SQL_select . $SQL_from . |
375
|
|
|
"LEFT JOIN `*PREFIX*audioplayer_stats` `AS` ON `AT`.`id` = `AS`.`track_id` |
376
|
|
|
WHERE `AS`.`id` <> ? AND `AT`.`user_id` = ? |
377
|
|
|
ORDER BY `AS`.`playcount` DESC |
378
|
|
|
Limit 25"; |
379
|
|
|
$categoryId = 0; |
380
|
|
|
} elseif ($category === 'Playlist') { |
381
|
|
|
$SQL = $SQL_select . " , `AP`.`sortorder`" . |
382
|
|
|
"FROM `*PREFIX*audioplayer_playlist_tracks` `AP` |
383
|
|
|
LEFT JOIN `*PREFIX*audioplayer_tracks` `AT` ON `AP`.`track_id` = `AT`.`id` |
384
|
|
|
LEFT JOIN `*PREFIX*audioplayer_artists` `AA` ON `AT`.`artist_id` = `AA`.`id` |
385
|
|
|
LEFT JOIN `*PREFIX*audioplayer_albums` `AB` ON `AT`.`album_id` = `AB`.`id` |
386
|
|
|
WHERE `AP`.`playlist_id` = ? |
387
|
|
|
AND `AT`.`user_id` = ? |
388
|
|
|
ORDER BY `AP`.`sortorder` ASC"; |
389
|
|
|
} elseif ($category === 'Stream') { |
390
|
|
|
$aTracks = $this->StreamParser(intval(substr($categoryId, 1))); |
391
|
|
|
return $aTracks; |
392
|
|
|
|
393
|
|
|
} elseif ($category === 'Folder') { |
394
|
|
|
$SQL = $SQL_select . $SQL_from . |
395
|
|
|
"WHERE `AT`.`folder_id` = ? AND `AT`.`user_id` = ?" . |
396
|
|
|
$SQL_order; |
397
|
|
|
} elseif ($category === 'Album') { |
398
|
|
|
$SQL_select = "SELECT `AT`.`id`, `AT`.`title` AS `cl1`, `AA`.`name` AS `cl2`, `AT`.`length` AS `len`, `AT`.`disc` AS `dsc`, `AT`.`file_id` AS `fid`, `AT`.`mimetype` AS `mim`, `AB`.`id` AS `cid`, `AB`.`cover`, LOWER(`AT`.`title`) AS `lower`,`AT`.`number` AS `num`"; |
399
|
|
|
$SQL = $SQL_select . $SQL_from . |
400
|
|
|
"WHERE `AB`.`id` = ? AND `AB`.`user_id` = ?" . |
401
|
|
|
" ORDER BY `AT`.`disc` ASC, `AT`.`number` ASC"; |
402
|
|
|
} elseif ($category === 'Album Artist') { |
403
|
|
|
$SQL = $SQL_select . $SQL_from . |
404
|
|
|
"WHERE `AB`.`artist_id` = ? AND `AT`.`user_id` = ?" . |
405
|
|
|
$SQL_order; |
406
|
|
|
} |
407
|
|
|
|
408
|
|
|
$this->tagger = $this->tagManager->load('files'); |
409
|
|
|
$favorites = $this->tagger->getFavorites(); |
410
|
|
|
|
411
|
|
|
$stmt = $this->db->prepare($SQL); |
412
|
|
|
$stmt->execute(array($categoryId, $this->userId)); |
413
|
|
|
$results = $stmt->fetchAll(); |
414
|
|
|
foreach ($results as $row) { |
415
|
|
|
if ($row['cover'] === null) { |
416
|
|
|
$row['cid'] = ''; |
417
|
|
|
} |
418
|
|
|
if ($category === 'Album') { |
419
|
|
|
$row['cl3'] = $row['dsc'] . '-' . $row['num']; |
420
|
|
|
} |
421
|
|
|
array_splice($row, 8, 3); |
422
|
|
|
$nodes = $this->rootFolder->getUserFolder($this->userId)->getById($row['fid']); |
423
|
|
|
$file = array_shift($nodes); |
424
|
|
|
if ($file === null) { |
425
|
|
|
$this->logger->debug('removed/unshared file found => remove '.$row['fid'], array('app' => 'audioplayer')); |
426
|
|
|
$this->DBController->deleteFromDB($row['fid'], $this->userId); |
427
|
|
|
continue; |
428
|
|
|
} |
429
|
|
|
$path = $file->getPath(); |
430
|
|
|
$segments = explode('/', trim($path, '/'), 3); |
431
|
|
|
$row['lin'] = rawurlencode($segments[2]); |
432
|
|
|
if (is_array($favorites) AND in_array($row['fid'], $favorites)) { |
433
|
|
|
$row['fav'] = "t"; |
434
|
|
|
} |
435
|
|
|
|
436
|
|
|
if ($favorite AND is_array($favorites) AND !in_array($row['fid'], $favorites)) { |
437
|
|
|
//special handling for Favorites smart playlist; |
438
|
|
|
//do not display anything that is NOT a fav |
439
|
|
|
} else { |
440
|
|
|
array_splice($row, 5, 1); |
441
|
|
|
$aTracks[] = $row; |
442
|
|
|
} |
443
|
|
|
} |
444
|
|
|
return $aTracks; |
445
|
|
|
} |
446
|
|
|
|
447
|
|
|
/** |
448
|
|
|
* Extract steam urls from playlist files |
449
|
|
|
* |
450
|
|
|
* @param integer $fileId |
451
|
|
|
* @return array |
452
|
|
|
* @throws \OCP\Files\InvalidPathException |
453
|
|
|
*/ |
454
|
|
|
private function StreamParser($fileId) |
455
|
|
|
{ |
456
|
|
|
$tracks = array(); |
457
|
|
|
$x = 0; |
458
|
|
|
$title = null; |
459
|
|
|
$userView = $this->rootFolder->getUserFolder($this->userId); |
460
|
|
|
//$this->logger->debug('removed/unshared file found => remove '.$row['fid'], array('app' => 'audioplayer')); |
461
|
|
|
|
462
|
|
|
$streamfile = $userView->getById($fileId); |
463
|
|
|
$file_type = $streamfile[0]->getMimetype(); |
464
|
|
|
$file_content = $streamfile[0]->getContent(); |
|
|
|
|
465
|
|
|
|
466
|
|
|
if ($file_type === 'audio/x-scpls') { |
467
|
|
|
$stream_data = parse_ini_string($file_content, true, INI_SCANNER_RAW); |
468
|
|
|
$stream_rows = isset($stream_data['playlist']['NumberOfEntries']) ? $stream_data['playlist']['NumberOfEntries'] : $stream_data['playlist']['numberofentries']; |
469
|
|
|
for ($i = 1; $i <= $stream_rows; $i++) { |
470
|
|
|
$title = $stream_data['playlist']['Title' . $i]; |
471
|
|
|
$file = $stream_data['playlist']['File' . $i]; |
472
|
|
|
preg_match_all('#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#', $file, $matches); |
473
|
|
|
|
474
|
|
|
if ($matches[0]) { |
475
|
|
|
$row = array(); |
476
|
|
|
$row['id'] = $fileId . $i; |
477
|
|
|
$row['fid'] = $fileId . $i; |
478
|
|
|
$row['cl1'] = $matches[0][0]; |
479
|
|
|
$row['cl2'] = ''; |
480
|
|
|
$row['cl3'] = ''; |
481
|
|
|
$row['len'] = ''; |
482
|
|
|
$row['mim'] = $file_type; |
483
|
|
|
$row['cid'] = ''; |
484
|
|
|
$row['lin'] = $matches[0][0]; |
485
|
|
|
$row['fav'] = 'f'; |
486
|
|
|
if ($title) $row['cl1'] = $title; |
487
|
|
|
$tracks[] = $row; |
488
|
|
|
} |
489
|
|
|
} |
490
|
|
|
} else { |
491
|
|
|
foreach (preg_split("/((\r?\n)|(\r\n?))/", $file_content) as $line) { |
492
|
|
|
if (empty($line)) continue; |
493
|
|
|
if (substr($line, 0, 8) === '#EXTINF:') { |
494
|
|
|
$extinf = explode(',', substr($line, 8)); |
495
|
|
|
$title = $extinf[1]; |
496
|
|
|
} |
497
|
|
|
preg_match_all('#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#', $line, $matches); |
498
|
|
|
|
499
|
|
|
if ($matches[0]) { |
500
|
|
|
$x++; |
501
|
|
|
$row = array(); |
502
|
|
|
$row['id'] = $fileId . $x; |
503
|
|
|
$row['fid'] = $fileId . $x; |
504
|
|
|
$row['cl1'] = $matches[0][0]; |
505
|
|
|
$row['cl2'] = ''; |
506
|
|
|
$row['cl3'] = ''; |
507
|
|
|
$row['len'] = ''; |
508
|
|
|
$row['mim'] = $file_type; |
509
|
|
|
$row['cid'] = ''; |
510
|
|
|
$row['lin'] = $matches[0][0]; |
511
|
|
|
$row['fav'] = 'f'; |
512
|
|
|
if ($title) $row['cl1'] = $title; |
513
|
|
|
$title = null; |
514
|
|
|
$tracks[] = $row; |
515
|
|
|
} elseif (preg_match('/^[^"<>|:]*$/',$line)) { |
516
|
|
|
$path = explode('/', $streamfile[0]->getInternalPath()); |
517
|
|
|
array_shift($path); |
518
|
|
|
array_pop($path); |
519
|
|
|
array_push($path, $line); |
520
|
|
|
$path = implode('/', $path); |
521
|
|
|
$x++; |
522
|
|
|
|
523
|
|
|
try { |
524
|
|
|
$fileId = $this->rootFolder->getUserFolder($this->userId)->get($path)->getId(); |
525
|
|
|
$track = $this->DBController->getTrackInfo(null,$fileId); |
526
|
|
|
|
527
|
|
|
$row = array(); |
528
|
|
|
$row['id'] = $track['id']; |
529
|
|
|
$row['fid'] = $track['file_id']; |
530
|
|
|
$row['cl1'] = $track['Title']; |
531
|
|
|
$row['cl2'] = $track['Artist']; |
532
|
|
|
$row['cl3'] = $track['Album']; |
533
|
|
|
$row['len'] = $track['Length']; |
534
|
|
|
$row['mim'] = $track['MIME type']; |
535
|
|
|
$row['cid'] = ''; |
536
|
|
|
$row['lin'] = rawurlencode($path); |
537
|
|
|
$row['fav'] = $track['fav']; |
538
|
|
|
if ($title) $row['cl1'] = $title; |
539
|
|
|
$tracks[] = $row; |
540
|
|
|
$title = null; |
541
|
|
|
} catch (NotFoundException $e) { |
|
|
|
|
542
|
|
|
//File is not known in the filecache and will be ignored; |
543
|
|
|
} |
544
|
|
|
} |
545
|
|
|
} |
546
|
|
|
} |
547
|
|
|
return $tracks; |
548
|
|
|
} |
549
|
|
|
|
550
|
|
|
/** |
551
|
|
|
* Get playlist dependend headers |
552
|
|
|
* |
553
|
|
|
* @param string $category |
554
|
|
|
* @return array |
555
|
|
|
*/ |
556
|
|
|
private function getCategoryHeaders($category) |
557
|
|
|
{ |
558
|
|
|
if ($category === 'Artist') { |
559
|
|
|
return ['col1' => $this->l10n->t('Title'), 'col2' => $this->l10n->t('Album'), 'col3' => $this->l10n->t('Year'), 'col4' => $this->l10n->t('Length')]; |
560
|
|
|
} elseif ($category === 'Album') { |
561
|
|
|
return ['col1' => $this->l10n->t('Title'), 'col2' => $this->l10n->t('Artist'), 'col3' => $this->l10n->t('Disc') . '-' . $this->l10n->t('Track'), 'col4' => $this->l10n->t('Length')]; |
562
|
|
|
} elseif ($category === 'x_Stream') { //temporary disabled; need to separate streams and playlists |
563
|
|
|
return ['col1' => $this->l10n->t('URL'), 'col2' => $this->l10n->t(''), 'col3' => $this->l10n->t(''), 'col4' => $this->l10n->t('')]; |
564
|
|
|
} else { |
565
|
|
|
return ['col1' => $this->l10n->t('Title'), 'col2' => $this->l10n->t('Artist'), 'col3' => $this->l10n->t('Album'), 'col4' => $this->l10n->t('Length')]; |
566
|
|
|
} |
567
|
|
|
} |
568
|
|
|
|
569
|
|
|
} |
570
|
|
|
|