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\IRequest; |
||
17 | use OCP\IL10N; |
||
18 | use OCP\IDbConnection; |
||
19 | use OCP\ITagManager; |
||
20 | use OCP\Files\IRootFolder; |
||
21 | use OCP\ILogger; |
||
22 | use OCP\Files\NotFoundException; |
||
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 | |||
174 | if (isset($SQL)) { |
||
175 | $stmt = $this->db->prepare($SQL); |
||
176 | $stmt->execute(array($this->userId)); |
||
177 | $results = $stmt->fetchAll(); |
||
178 | foreach ($results as $row) { |
||
179 | if ($category === 'Album') { |
||
180 | $row['art'] = $this->DBController->loadArtistsToAlbum($row['id'], $row['art']); |
||
181 | if ($row['cid'] !== null) { |
||
182 | $row['cid'] = $row['id']; |
||
183 | } else { |
||
184 | $row['cid'] = ''; |
||
185 | } |
||
186 | } |
||
187 | if ($category === 'Album') |
||
188 | array_splice($row, 2, 1); |
||
189 | if ($row['name'] === '0' OR $row['name'] === '') $row['name'] = $this->l10n->t('Unknown'); |
||
190 | $row['counter'] = $this->getCategoryCount($category, $row['id']); |
||
191 | $aPlaylists[] = $row; |
||
192 | } |
||
193 | } |
||
194 | return $aPlaylists; |
||
195 | } |
||
196 | |||
197 | /** |
||
198 | * Get the number of items for a category item |
||
199 | * |
||
200 | * @param string $category |
||
201 | * @param integer $categoryId |
||
202 | * @return integer |
||
203 | */ |
||
204 | private function getCategoryCount($category, $categoryId) |
||
205 | { |
||
206 | $SQL = null; |
||
207 | if ($category === 'Artist') { |
||
208 | $SQL = "SELECT COUNT(`AT`.`id`) AS `count` |
||
209 | FROM `*PREFIX*audioplayer_tracks` `AT` |
||
210 | LEFT JOIN `*PREFIX*audioplayer_artists` `AA` ON `AT`.`artist_id` = `AA`.`id` |
||
211 | WHERE `AT`.`artist_id` = ? |
||
212 | AND `AT`.`user_id` = ? |
||
213 | "; |
||
214 | } elseif ($category === 'Genre') { |
||
215 | $SQL = "SELECT COUNT(`AT`.`id`) AS `count` |
||
216 | FROM `*PREFIX*audioplayer_tracks` `AT` |
||
217 | WHERE `AT`.`genre_id` = ? |
||
218 | AND `AT`.`user_id` = ? |
||
219 | "; |
||
220 | } elseif ($category === 'Year') { |
||
221 | $SQL = "SELECT COUNT(`AT`.`id`) AS `count` |
||
222 | FROM `*PREFIX*audioplayer_tracks` `AT` |
||
223 | WHERE `AT`.`year` = ? |
||
224 | AND `AT`.`user_id` = ? |
||
225 | "; |
||
226 | } elseif ($category === 'Title') { |
||
227 | $SQL = "SELECT COUNT(`AT`.`id`) AS `count` |
||
228 | FROM `*PREFIX*audioplayer_tracks` `AT` |
||
229 | WHERE `AT`.`id` > ? |
||
230 | AND `AT`.`user_id` = ? |
||
231 | "; |
||
232 | } elseif ($category === 'Playlist') { |
||
233 | $SQL = "SELECT COUNT(`AP`.`track_id`) AS `count` |
||
234 | FROM `*PREFIX*audioplayer_playlist_tracks` `AP` |
||
235 | WHERE `AP`.`playlist_id` = ? |
||
236 | "; |
||
237 | } elseif ($category === 'Folder') { |
||
238 | $SQL = "SELECT COUNT(`AT`.`id`) AS `count` |
||
239 | FROM `*PREFIX*audioplayer_tracks` `AT` |
||
240 | WHERE `AT`.`folder_id` = ? |
||
241 | AND `AT`.`user_id` = ? |
||
242 | "; |
||
243 | } elseif ($category === 'Album') { |
||
244 | $SQL = "SELECT COUNT(`id`) AS `count` |
||
245 | FROM `*PREFIX*audioplayer_tracks` |
||
246 | WHERE `album_id` = ? |
||
247 | AND `user_id` = ? |
||
248 | "; |
||
249 | } elseif ($category === 'Album Artist') { |
||
250 | $SQL = "SELECT COUNT(`AT`.`id`) AS `count` |
||
251 | FROM `*PREFIX*audioplayer_albums` `AB` |
||
252 | JOIN `*PREFIX*audioplayer_tracks` `AT` |
||
253 | ON `AB`.`id` = `AT`.`album_id` |
||
254 | WHERE `AB`.`artist_id` = ? |
||
255 | AND `AB`.`user_id` = ? |
||
256 | "; |
||
257 | } |
||
258 | |||
259 | $stmt = $this->db->prepare($SQL); |
||
260 | if ($category === 'Playlist') { |
||
261 | $stmt->execute(array($categoryId)); |
||
262 | } else { |
||
263 | $stmt->execute(array($categoryId, $this->userId)); |
||
264 | } |
||
265 | $results = $stmt->fetch(); |
||
266 | return $results['count']; |
||
267 | } |
||
268 | |||
269 | /** |
||
270 | * AJAX function to get playlist titles for a selected category |
||
271 | * @NoAdminRequired |
||
272 | * |
||
273 | * @param string $category |
||
274 | * @param string $categoryId |
||
275 | * @return JSONResponse |
||
276 | */ |
||
277 | public function getCategoryItems($category, $categoryId) |
||
278 | { |
||
279 | $albums = 0; |
||
280 | if ($categoryId[0] === "S") $category = "Stream"; |
||
281 | if ($categoryId[0] === "P") $category = "Playlist"; |
||
282 | $items = $this->getCatagoryItemsDetails($category, $categoryId); |
||
283 | $headers = $this->getCategoryHeaders($category); |
||
284 | if ($category === 'Artist') $albums = $this->getAlbumCountForCategory($category, $categoryId); |
||
285 | |||
286 | $result = !empty($items) ? [ |
||
287 | 'status' => 'success', |
||
288 | 'data' => $items, |
||
289 | 'header' => $headers, |
||
290 | 'albums' => $albums, |
||
291 | ] : [ |
||
292 | 'status' => 'nodata', |
||
293 | ]; |
||
294 | $response = new JSONResponse(); |
||
295 | $response->setData($result); |
||
296 | return $response; |
||
297 | } |
||
298 | |||
299 | /** |
||
300 | * Get playlist titles for a selected category |
||
301 | * |
||
302 | * @param string $category |
||
303 | * @param string $categoryId |
||
304 | * @return array |
||
305 | * @throws InvalidPathException |
||
306 | * @throws NotFoundException |
||
307 | */ |
||
308 | private function getCatagoryItemsDetails($category, $categoryId) |
||
309 | { |
||
310 | $SQL = null; |
||
311 | $favorite = false; |
||
312 | $aTracks = array(); |
||
313 | $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`"; |
||
314 | $SQL_from = " FROM `*PREFIX*audioplayer_tracks` `AT` |
||
315 | LEFT JOIN `*PREFIX*audioplayer_artists` `AA` ON `AT`.`artist_id` = `AA`.`id` |
||
316 | LEFT JOIN `*PREFIX*audioplayer_albums` `AB` ON `AT`.`album_id` = `AB`.`id`"; |
||
317 | $SQL_order = " ORDER BY LOWER(`AB`.`name`) ASC, `AT`.`disc` ASC, `AT`.`number` ASC"; |
||
318 | |||
319 | if ($category === 'Artist') { |
||
320 | $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`"; |
||
321 | $SQL = $SQL_select . $SQL_from . |
||
322 | "WHERE `AT`.`artist_id` = ? AND `AT`.`user_id` = ?" . |
||
323 | $SQL_order; |
||
324 | } elseif ($category === 'Genre') { |
||
325 | $SQL = $SQL_select . $SQL_from . |
||
326 | "WHERE `AT`.`genre_id` = ? AND `AT`.`user_id` = ?" . |
||
327 | $SQL_order; |
||
328 | } elseif ($category === 'Year') { |
||
329 | $SQL = $SQL_select . $SQL_from . |
||
330 | "WHERE `AT`.`year` = ? AND `AT`.`user_id` = ?" . |
||
331 | $SQL_order; |
||
332 | } elseif ($category === 'Title') { |
||
333 | $SQL = $SQL_select . $SQL_from . |
||
334 | "WHERE `AT`.`id` > ? AND `AT`.`user_id` = ?" . |
||
335 | $SQL_order; |
||
336 | } elseif ($category === 'Playlist' AND $categoryId === "X1") { // Favorites |
||
337 | $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`" . |
||
338 | $SQL_from . |
||
339 | "WHERE `AT`.`id` <> ? AND `AT`.`user_id` = ?" . |
||
340 | " ORDER BY LOWER(`AT`.`title`) ASC"; |
||
341 | $categoryId = 0; //overwrite to integer for PostgreSQL |
||
342 | $favorite = true; |
||
343 | } elseif ($category === 'Playlist' AND $categoryId === "X2") { // Recently Added |
||
344 | $SQL = $SQL_select . $SQL_from . |
||
345 | "WHERE `AT`.`id` <> ? AND `AT`.`user_id` = ? |
||
346 | ORDER BY `AT`.`file_id` DESC |
||
347 | Limit 100"; |
||
348 | $categoryId = 0; |
||
349 | } elseif ($category === 'Playlist' AND $categoryId === "X3") { // Recently Played |
||
350 | $SQL = $SQL_select . $SQL_from . |
||
351 | "LEFT JOIN `*PREFIX*audioplayer_stats` `AS` ON `AT`.`id` = `AS`.`track_id` |
||
352 | WHERE `AS`.`id` <> ? AND `AT`.`user_id` = ? |
||
353 | ORDER BY `AS`.`playtime` DESC |
||
354 | Limit 50"; |
||
355 | $categoryId = 0; |
||
356 | } elseif ($category === 'Playlist' AND $categoryId === "X4") { // Most Played |
||
357 | $SQL = $SQL_select . $SQL_from . |
||
358 | "LEFT JOIN `*PREFIX*audioplayer_stats` `AS` ON `AT`.`id` = `AS`.`track_id` |
||
359 | WHERE `AS`.`id` <> ? AND `AT`.`user_id` = ? |
||
360 | ORDER BY `AS`.`playcount` DESC |
||
361 | Limit 25"; |
||
362 | $categoryId = 0; |
||
363 | } elseif ($category === 'Playlist') { |
||
364 | $SQL = $SQL_select . " , `AP`.`sortorder`" . |
||
365 | "FROM `*PREFIX*audioplayer_playlist_tracks` `AP` |
||
366 | LEFT JOIN `*PREFIX*audioplayer_tracks` `AT` ON `AP`.`track_id` = `AT`.`id` |
||
367 | LEFT JOIN `*PREFIX*audioplayer_artists` `AA` ON `AT`.`artist_id` = `AA`.`id` |
||
368 | LEFT JOIN `*PREFIX*audioplayer_albums` `AB` ON `AT`.`album_id` = `AB`.`id` |
||
369 | WHERE `AP`.`playlist_id` = ? |
||
370 | AND `AT`.`user_id` = ? |
||
371 | ORDER BY `AP`.`sortorder` ASC"; |
||
372 | } elseif ($category === 'Stream') { |
||
373 | $aTracks = $this->StreamParser(intval(substr($categoryId, 1))); |
||
374 | return $aTracks; |
||
375 | |||
376 | } elseif ($category === 'Folder') { |
||
377 | $SQL = $SQL_select . $SQL_from . |
||
378 | "WHERE `AT`.`folder_id` = ? AND `AT`.`user_id` = ?" . |
||
379 | $SQL_order; |
||
380 | } elseif ($category === 'Album') { |
||
381 | $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`"; |
||
382 | $SQL = $SQL_select . $SQL_from . |
||
383 | "WHERE `AB`.`id` = ? AND `AB`.`user_id` = ?" . |
||
384 | " ORDER BY `AT`.`disc` ASC, `AT`.`number` ASC"; |
||
385 | } elseif ($category === 'Album Artist') { |
||
386 | $SQL = $SQL_select . $SQL_from . |
||
387 | "WHERE `AB`.`artist_id` = ? AND `AT`.`user_id` = ?" . |
||
388 | $SQL_order; |
||
389 | } |
||
390 | |||
391 | $this->tagger = $this->tagManager->load('files'); |
||
392 | $favorites = $this->tagger->getFavorites(); |
||
393 | |||
394 | $stmt = $this->db->prepare($SQL); |
||
395 | $stmt->execute(array($categoryId, $this->userId)); |
||
396 | $results = $stmt->fetchAll(); |
||
397 | foreach ($results as $row) { |
||
398 | if ($row['cover'] === null) { |
||
399 | $row['cid'] = ''; |
||
400 | } |
||
401 | if ($category === 'Album') { |
||
402 | $row['cl3'] = $row['dsc'] . '-' . $row['num']; |
||
403 | } |
||
404 | array_splice($row, 8, 3); |
||
405 | $nodes = $this->rootFolder->getUserFolder($this->userId)->getById($row['fid']); |
||
406 | $file = array_shift($nodes); |
||
407 | if ($file === null) { |
||
408 | $this->logger->debug('removed/unshared file found => remove '.$row['fid'], array('app' => 'audioplayer')); |
||
409 | $this->DBController->deleteFromDB($row['fid'], $this->userId); |
||
410 | continue; |
||
411 | } |
||
412 | $path = $file->getPath(); |
||
413 | $segments = explode('/', trim($path, '/'), 3); |
||
414 | $row['lin'] = rawurlencode($segments[2]); |
||
415 | if (is_array($favorites) AND in_array($row['fid'], $favorites)) { |
||
416 | $row['fav'] = "t"; |
||
417 | } |
||
418 | |||
419 | if ($favorite AND is_array($favorites) AND !in_array($row['fid'], $favorites)) { |
||
420 | //special handling for Favorites smart playlist; |
||
421 | //do not display anything that is NOT a fav |
||
422 | } else { |
||
423 | array_splice($row, 5, 1); |
||
424 | $aTracks[] = $row; |
||
425 | } |
||
426 | } |
||
427 | return $aTracks; |
||
428 | } |
||
429 | |||
430 | /** |
||
431 | * Extract steam urls from playlist files |
||
432 | * |
||
433 | * @param integer $fileId |
||
434 | * @return array |
||
435 | * @throws \OCP\Files\InvalidPathException |
||
436 | */ |
||
437 | private function StreamParser($fileId) |
||
438 | { |
||
439 | $tracks = array(); |
||
440 | $x = 0; |
||
441 | $title = null; |
||
442 | $userView = $this->rootFolder->getUserFolder($this->userId); |
||
443 | //$this->logger->debug('removed/unshared file found => remove '.$row['fid'], array('app' => 'audioplayer')); |
||
444 | |||
445 | $streamfile = $userView->getById($fileId); |
||
446 | $file_type = $streamfile[0]->getMimetype(); |
||
447 | $file_content = $streamfile[0]->getContent(); |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
448 | |||
449 | if ($file_type === 'audio/x-scpls') { |
||
450 | $stream_data = parse_ini_string($file_content, true, INI_SCANNER_RAW); |
||
451 | $stream_rows = isset($stream_data['playlist']['NumberOfEntries']) ? $stream_data['playlist']['NumberOfEntries'] : $stream_data['playlist']['numberofentries']; |
||
452 | for ($i = 1; $i <= $stream_rows; $i++) { |
||
453 | $title = $stream_data['playlist']['Title' . $i]; |
||
454 | $file = $stream_data['playlist']['File' . $i]; |
||
455 | preg_match_all('#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#', $file, $matches); |
||
456 | |||
457 | if ($matches[0]) { |
||
458 | $row = array(); |
||
459 | $row['id'] = $fileId . $i; |
||
460 | $row['fid'] = $fileId . $i; |
||
461 | $row['cl1'] = $matches[0][0]; |
||
462 | $row['cl2'] = ''; |
||
463 | $row['cl3'] = ''; |
||
464 | $row['len'] = ''; |
||
465 | $row['mim'] = $file_type; |
||
466 | $row['cid'] = ''; |
||
467 | $row['lin'] = $matches[0][0]; |
||
468 | $row['fav'] = 'f'; |
||
469 | if ($title) $row['cl1'] = $title; |
||
470 | $tracks[] = $row; |
||
471 | } |
||
472 | } |
||
473 | } else { |
||
474 | foreach (preg_split("/((\r?\n)|(\r\n?))/", $file_content) as $line) { |
||
475 | if (empty($line)) continue; |
||
476 | if (substr($line, 0, 8) === '#EXTINF:') { |
||
477 | $extinf = explode(',', substr($line, 8)); |
||
478 | $title = $extinf[1]; |
||
479 | } |
||
480 | preg_match_all('#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#', $line, $matches); |
||
481 | |||
482 | if ($matches[0]) { |
||
483 | $x++; |
||
484 | $row = array(); |
||
485 | $row['id'] = $fileId . $x; |
||
486 | $row['fid'] = $fileId . $x; |
||
487 | $row['cl1'] = $matches[0][0]; |
||
488 | $row['cl2'] = ''; |
||
489 | $row['cl3'] = ''; |
||
490 | $row['len'] = ''; |
||
491 | $row['mim'] = $file_type; |
||
492 | $row['cid'] = ''; |
||
493 | $row['lin'] = $matches[0][0]; |
||
494 | $row['fav'] = 'f'; |
||
495 | if ($title) $row['cl1'] = $title; |
||
496 | $title = null; |
||
497 | $tracks[] = $row; |
||
498 | } elseif (preg_match('/^[^"<>|:]*$/',$line)) { |
||
499 | $path = explode('/', $streamfile[0]->getInternalPath()); |
||
500 | array_shift($path); |
||
501 | array_pop($path); |
||
502 | array_push($path, $line); |
||
503 | $path = implode('/', $path); |
||
504 | $x++; |
||
505 | |||
506 | try { |
||
507 | $fileId = $this->rootFolder->getUserFolder($this->userId)->get($path)->getId(); |
||
508 | $track = $this->DBController->getTrackInfo(null,$fileId); |
||
509 | |||
510 | $row = array(); |
||
511 | $row['id'] = $track['id']; |
||
512 | $row['fid'] = $track['file_id']; |
||
513 | $row['cl1'] = $track['Title']; |
||
514 | $row['cl2'] = $track['Artist']; |
||
515 | $row['cl3'] = $track['Album']; |
||
516 | $row['len'] = $track['Length']; |
||
517 | $row['mim'] = $track['MIME type']; |
||
518 | $row['cid'] = ''; |
||
519 | $row['lin'] = rawurlencode($path); |
||
520 | $row['fav'] = $track['fav']; |
||
521 | if ($title) $row['cl1'] = $title; |
||
522 | $tracks[] = $row; |
||
523 | $title = null; |
||
524 | } catch (NotFoundException $e) { |
||
525 | //File is not known in the filecache and will be ignored; |
||
526 | } |
||
527 | } |
||
528 | } |
||
529 | } |
||
530 | return $tracks; |
||
531 | } |
||
532 | |||
533 | /** |
||
534 | * Get playlist dependend headers |
||
535 | * |
||
536 | * @param string $category |
||
537 | * @return array |
||
538 | */ |
||
539 | private function getCategoryHeaders($category) |
||
540 | { |
||
541 | if ($category === 'Artist') { |
||
542 | return ['col1' => $this->l10n->t('Title'), 'col2' => $this->l10n->t('Album'), 'col3' => $this->l10n->t('Year'), 'col4' => $this->l10n->t('Length')]; |
||
543 | } elseif ($category === 'Album') { |
||
544 | 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')]; |
||
545 | } elseif ($category === 'x_Stream') { //temporary disabled; need to separate streams and playlists |
||
546 | return ['col1' => $this->l10n->t('URL'), 'col2' => $this->l10n->t(''), 'col3' => $this->l10n->t(''), 'col4' => $this->l10n->t('')]; |
||
547 | } else { |
||
548 | return ['col1' => $this->l10n->t('Title'), 'col2' => $this->l10n->t('Artist'), 'col3' => $this->l10n->t('Album'), 'col4' => $this->l10n->t('Length')]; |
||
549 | } |
||
550 | } |
||
551 | |||
552 | /** |
||
553 | * Count the number of albums within the artist selection |
||
554 | * |
||
555 | * @param string $category |
||
556 | * @param string $categoryId |
||
557 | * @return integer |
||
558 | */ |
||
559 | private function getAlbumCountForCategory($category, $categoryId) |
||
560 | { |
||
561 | $SQL = null; |
||
562 | if ($category === 'Artist') { |
||
563 | $SQL = "SELECT COUNT(DISTINCT `AT`.`album_id`) AS `count` |
||
564 | FROM `*PREFIX*audioplayer_tracks` `AT` |
||
565 | LEFT JOIN `*PREFIX*audioplayer_artists` `AA` ON `AT`.`artist_id` = `AA`.`id` |
||
566 | WHERE `AT`.`artist_id` = ? |
||
567 | AND `AT`.`user_id` = ? |
||
568 | "; |
||
569 | } |
||
570 | |||
571 | $stmt = $this->db->prepare($SQL); |
||
572 | $stmt->execute(array($categoryId, $this->userId)); |
||
573 | $results = $stmt->fetch(); |
||
574 | return $results['count']; |
||
575 | } |
||
576 | |||
577 | } |
||
578 |