now.flash.moe/public/get.php

32 lines
888 B
PHP
Raw Permalink Normal View History

2016-06-12 18:52:15 +00:00
<?php
use LastFmApi\Api\AuthApi;
use LastFmApi\Api\UserApi;
function view($object)
{
header('Content-Type: application/json; charset=utf-8');
return json_encode($object, JSON_NUMERIC_CHECK);
}
if (!file_exists('../vendor/autoload.php')) {
die(view(['error' => 'Please run "composer install" in the main directory first!']));
}
require_once '../vendor/autoload.php';
2017-03-19 14:56:19 +00:00
if (!file_exists('../.apikey')) {
die(view(['error' => 'API key file missing! Create a file called ".apikey" in the root directory and place your last.fm api key in there.']));
2016-06-12 18:52:15 +00:00
}
2017-03-19 14:56:19 +00:00
$api_key = trim(file_get_contents('../.apikey'));
2016-06-12 18:52:15 +00:00
2017-03-19 14:56:19 +00:00
$auth = new AuthApi('setsession', ['apiKey' => $api_key]);
2016-06-12 18:52:15 +00:00
$user = new UserApi($auth);
$now = $user->getRecentTracks(['user' => (isset($_GET['u']) ? $_GET['u'] : ''), 'limit' => '1']);
if ($now === false) {
$now = ['error' => 'User not found.'];
}
echo view($now);