-
Notifications
You must be signed in to change notification settings - Fork 4
/
getLyricsMusix.php
44 lines (39 loc) · 1.22 KB
/
getLyricsMusix.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
<?php
$type = $_GET['type'];
include_once('./Musixmatch.php');
$musix = new MusixLyricsApi\Musix();
$musix->checkTokenExpire();
if($type === 'default') {
$query = urlencode($_GET['q']);
$track_id = $musix->searchTrack($query);
if($track_id != null) {
$response = $musix -> getLyrics($track_id);
if(isset($response)) {
echo $response;
} else {
echo json_encode(["error":"Lyrics seems like doesn\'t exist.", "isError":true]);
}
} else {
echo json_encode(["error":"Track id seems like doesn\'t exist.", "isError":true]);
}
} else {
$title = urlencode($_GET['t']);
$artist = urlencode($_GET['a']);
$duration = $_GET['d'];
if($duration != null) {
$lyrics = $musix->getLyricsAlternative(/*title=*/ $title, /*artist name=*/ $artist, /*songs duration=*/ convertDuration($duration));
} else {
$lyrics = $musix->getLyricsAlternative(/*title=*/ $title, /*artist name=*/ $artist);
}
if($lyrics != null) {
echo $lyrics;
} else {
echo json_encode(["error":"Track id seems like doesn\'t exist.", "isError":true]);
}
}
function convertDuration($time) {
list($minutes, $seconds) = explode(":", $time);
$totalSeconds = ($minutes * 60) + $seconds;
return $totalSeconds;
}
?>