From 898b52edcb47bcb3e9d6106e74ca73e74ea01e70 Mon Sep 17 00:00:00 2001 From: sillylaird Date: Thu, 3 Sep 2026 00:33:59 +0000 Subject: import live www.sillylaird.ca webroot --- lastfm-proxy.php | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 lastfm-proxy.php (limited to 'lastfm-proxy.php') diff --git a/lastfm-proxy.php b/lastfm-proxy.php new file mode 100644 index 0000000..7a0a208 --- /dev/null +++ b/lastfm-proxy.php @@ -0,0 +1,35 @@ + 'rate limited']); + exit; +} + +$api_key = lastfm_api_key(); +$user = 'SillyLaird'; +$url = "https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user={$user}&api_key={$api_key}&format=json&limit=5"; + +$ctx = stream_context_create(['http' => [ + 'timeout' => 5, + 'header' => 'User-Agent: www.sillylaird.ca/1.0', +]]); + +$response = @file_get_contents($url, false, $ctx); + +if ($response === false) { + http_response_code(502); + echo json_encode(['error' => 'Failed to fetch from Last.fm']); + exit; +} + +// Cap response size we relay back (defensive — Last.fm responses are tiny). +if (strlen($response) > 256 * 1024) { + $response = substr($response, 0, 256 * 1024); +} + +echo $response; -- cgit v1.2.3