diff options
author | RaindropsSys <raindrops@equestria.dev> | 2023-10-30 23:08:45 +0100 |
---|---|---|
committer | RaindropsSys <raindrops@equestria.dev> | 2023-10-30 23:08:45 +0100 |
commit | 41c51b8bdb9c8e9fa4a7d56f260d594739d4107e (patch) | |
tree | 4bb3e824d636c7cf8cb39fd0e1aa25c49c339164 /api | |
parent | 4d4308c46d4f7801c657cc79d2243e1a81831334 (diff) | |
download | mist-41c51b8bdb9c8e9fa4a7d56f260d594739d4107e.tar.gz mist-41c51b8bdb9c8e9fa4a7d56f260d594739d4107e.tar.bz2 mist-41c51b8bdb9c8e9fa4a7d56f260d594739d4107e.zip |
Updated 35 files and added 28 files (automated)
Diffstat (limited to 'api')
-rw-r--r-- | api/hasStella.php | 11 | ||||
-rw-r--r-- | api/lyrics.php | 22 |
2 files changed, 29 insertions, 4 deletions
diff --git a/api/hasStella.php b/api/hasStella.php new file mode 100644 index 0000000..7e335b7 --- /dev/null +++ b/api/hasStella.php @@ -0,0 +1,11 @@ +<?php + +header("X-Frame-Options: SAMEORIGIN"); +header("Content-Type: application/json"); +require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.php"; global $songs; + +if (!isset($_GET["id"]) || !isset($songs[$_GET["id"]])) { + die(); +} + +die(file_exists($_SERVER['DOCUMENT_ROOT'] . "/assets/content/" . $_GET["id"] . ".stella") ? "true" : "false");
\ No newline at end of file diff --git a/api/lyrics.php b/api/lyrics.php index 89e7675..11910d9 100644 --- a/api/lyrics.php +++ b/api/lyrics.php @@ -3,7 +3,7 @@ header("X-Frame-Options: SAMEORIGIN"); header("Content-Type: application/json"); require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.php"; global $songs; -$token = json_decode(file_get_contents("/opt/spotify/token.json"), true); +$token = json_decode(file_exists("/opt/spotify/token.json") ? file_get_contents("/opt/spotify/token.json") : file_get_contents($_SERVER["DOCUMENT_ROOT"] . "/includes/app.json"), true); if (!isset($_GET["id"]) || !isset($songs[$_GET["id"]])) { die(); @@ -19,27 +19,41 @@ $id = json_decode(file_get_contents("https://api.spotify.com/v1/search?q=" . raw ])), true)["tracks"]["items"][0]["id"]; $data = json_decode(file_get_contents("http://localhost:8000/public/?trackid=" . $id), true); + if (isset($data) && str_ends_with($data["syncType"], "_SYNCED")) { die(json_encode([ "synced" => true, "payload" => $data["lines"] ], JSON_PRETTY_PRINT)); +} elseif (isset($data) && str_starts_with($data["syncType"], "UNSYNCED")) { + die(json_encode([ + "synced" => false, + "payload" => implode("\n", array_map(function ($i) { + return $i["words"]; + }, $data["lines"])) + ], JSON_PRETTY_PRINT)); } $genius = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/app.json"), true)["genius"]; -$id = json_decode(file_get_contents("https://api.genius.com/search?q=" . rawurlencode($song["title"] . " " . $song["artist"]), false, stream_context_create([ +$id = array_values(array_filter(json_decode(file_get_contents("https://api.genius.com/search?q=" . rawurlencode($song["title"] . " " . $song["artist"]), false, stream_context_create([ "http" => [ "method" => "GET", "header" => "Authorization: Bearer " . $genius . "\r\n" ] -])), true)["response"]["hits"][0]["result"]["id"]; +])), true)["response"]["hits"], function ($i) { + return !str_contains(strtolower($i["result"]["artist_names"]), "genius"); +}))[0]["result"]["id"]; $data = []; exec('bash -c "cd /opt/spotify/spotify-lyrics-api; python genius.py ' . $id . '"', $data); $data = array_slice(array_map(function ($i) { if (str_ends_with($i, "1Embed")) { return substr($i, 0, -6); + } elseif (str_ends_with($i, "2Embed")) { + return substr($i, 0, -6); + } elseif (str_ends_with($i, "Embed")) { + return substr($i, 0, -5); } else { return $i; } @@ -48,7 +62,7 @@ $data = array_slice(array_map(function ($i) { if (count($data) > 0) { die(json_encode([ "synced" => false, - "payload" => implode("\n", $data) + "payload" => str_replace("You might also like", "", str_replace("You might also like\n", "", trim(implode("\n", $data)))) ], JSON_PRETTY_PRINT)); } |