X-Git-Url: https://git.jacobcasper.com/?p=Marketplaylister.git;a=blobdiff_plain;f=searchify.php;fp=searchify.php;h=740f79f85c6cb4d08f845fd80fe375894f20fb77;hp=0000000000000000000000000000000000000000;hb=168896268ee9a19bce7125b029a37c34437aeb52;hpb=bed05b1a3c4b40cb71564fbebb2cb41242163dbd diff --git a/searchify.php b/searchify.php new file mode 100644 index 0000000..740f79f --- /dev/null +++ b/searchify.php @@ -0,0 +1,49 @@ +prepare("SELECT * FROM SONGS WHERE uri IS NULL"); + $upstmt = $pdo->prepare("UPDATE songs SET (uri) = :uri WHERE id = :id"); + $upstmt->bindParam(':uri', $uri); + $upstmt->bindParam(':id', $id); + + if ($stmt->execute()) { + + print_r($stmt->fetchAll()); + exit(0); + while ($row = $stmt->fetch()) { + + $track_opts = [ + 'http' => [ + 'method' => 'GET', + 'header' => 'Authorization: Bearer ' . SPOT_TOKEN . "\r\n" + ] + ]; + + $track_context = stream_context_create($track_opts); + + $track_search_url = BASE_URL . 'search?q=track:' . urlencode($row['track']) + . '+artist:' . urlencode($row['artist']) . '&type=track'; + + $trackReq = file_get_contents($track_search_url, false, $track_context); + if ($trackReq) { + $trackJSON = json_decode($trackReq, true); + $trackJSON = $trackJSON['tracks']; + if ($trackJSON['total'] === 0) { + continue; + } + + $uri = $trackJSON['items'][0]['uri']; + $id = $row['id']; + $upstmt->execute(); + + #rate limit + sleep(1); + + } + } + } \ No newline at end of file