forked from ArturSierzant/OMPD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ajax-track-version.php
98 lines (78 loc) · 4.03 KB
/
ajax-track-version.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
<?php
// +------------------------------------------------------------------------+
// | O!MPD, Copyright © 2015-2021 Artur Sierzant |
// | http://www.ompd.pl |
// | |
// | |
// | 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 3 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, see <http://www.gnu.org/licenses/>. |
// +------------------------------------------------------------------------+
require_once('include/initialize.inc.php');
global $cfg, $db;
$track_id = get('track_id');
$track_title = get('track_title');
$data = array();
if (isTidal($track_id)){
$query = mysqli_query($db,'SELECT title FROM tidal_track WHERE track_id = "' . mysqli_real_escape_string($db,getTidalId($track_id)) . '"');
}
else {
$query = mysqli_query($db,'SELECT title FROM track WHERE track_id = "' . mysqli_real_escape_string($db,$track_id) . '"');
}
$track = mysqli_fetch_assoc($query);
$title = $track['title'];
if (!$track_id && $track_title) {
$title = $track_title;
}
$title = findCoreTrackTitle($title);
$title = mysqli_real_escape_like($title);
//$title = strtolower($title);
$separator = $cfg['separator'];
$count = count($separator);
$query_string = '';
$i=0;
for ($i=0; $i<$count; $i++) {
$query_string = $query_string . ' OR LOWER(track.title) LIKE "' . $title . $separator[$i] . '%"';
}
$filter_query = 'WHERE (LOWER(track.title) = "' . $title . '" ' . $query_string . ') AND track.album_id = album.album_id';
$order_query = 'ORDER BY title, artist, album';
//$query = mysqli_query($db, 'SELECT track.artist, track.title, track.number, track.featuring, track.album_id, track.track_id, track.miliseconds, track.relative_file, album.image_id, album.album FROM track, album ' . $filter_query . ' ' . $order_query);
$q = 'SELECT * FROM
(SELECT track.artist as track_artist, track.title, track.featuring, track.album_id, track.track_id as tid, track.miliseconds, track.number, track.relative_file, album.image_id, album.album, album.artist
FROM track
INNER JOIN album ON track.album_id = album.album_id '
. $filter_query . ' ' . $order_query .') as a
LEFT JOIN
(SELECT track_id, favorite_id FROM favoriteitem WHERE favorite_id = "' . $cfg['favorite_id'] . '") as b ON b.track_id = a.tid
LEFT JOIN
(SELECT track_id, favorite_id as blacklist_id FROM favoriteitem WHERE favorite_id = "' . $cfg['blacklist_id'] . '") as bl ON bl.track_id = a.tid
ORDER BY a.track_artist
';
$query = mysqli_query($db,$q);
$other_track_version = false;
if (strlen($title) > 0) {
$num_rows = mysqli_num_rows($query);
//other versions found || one other version found and track is from Tidal || one other version found and track is from e.g. YouTube
if ($num_rows > 1 || ($num_rows == 1 && isTidal($track_id)) || ($num_rows == 1 && !$track_id)) {
$track['title'] = $track_title;
$other_track_version = true;
}
}
$track_id = array();
while ($track2 = mysqli_fetch_assoc($query)) {
$track_id[] = $track2['tid'];
}
$data['other_track_version'] = (boolean) $other_track_version;
$data['title'] = $track['title'];
$data['track_ids'] = $track_id;
echo json_encode($data);
?>