diff --git a/.env.example b/.env.example index 478972c..4ead6e3 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,7 @@ APP_NAME=Laravel APP_ENV=local +APP_NAME=Laravel +APP_ENV=local APP_KEY= APP_DEBUG=true APP_URL=http://localhost @@ -24,35 +26,6 @@ SESSION_LIFETIME=120 MEMCACHED_HOST=127.0.0.1 -REDIS_HOST=127.0.0.1 -REDIS_PASSWORD=null -REDIS_PORT=6379 - -MAIL_MAILER=smtp -MAIL_HOST=mailpit -MAIL_PORT=1025 -MAIL_USERNAME=null -MAIL_PASSWORD=null -MAIL_ENCRYPTION=null -MAIL_FROM_ADDRESS="hello@example.com" -MAIL_FROM_NAME="${APP_NAME}" - -AWS_ACCESS_KEY_ID= -AWS_SECRET_ACCESS_KEY= -AWS_DEFAULT_REGION=us-east-1 -AWS_BUCKET= -AWS_USE_PATH_STYLE_ENDPOINT=false - -PUSHER_APP_ID= -PUSHER_APP_KEY= -PUSHER_APP_SECRET= -PUSHER_HOST= -PUSHER_PORT=443 -PUSHER_SCHEME=https -PUSHER_APP_CLUSTER=mt1 - -VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}" -VITE_PUSHER_HOST="${PUSHER_HOST}" -VITE_PUSHER_PORT="${PUSHER_PORT}" -VITE_PUSHER_SCHEME="${PUSHER_SCHEME}" -VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" +LASTFM_KEY= +LASTFM_USER= +LASTFM_TOP_TRACKS=10 diff --git a/config/services.php b/config/services.php index 8407709..0acb16e 100644 --- a/config/services.php +++ b/config/services.php @@ -16,6 +16,7 @@ 'lastfm' => [ 'key' => env('LASTFM_KEY'), - 'user' => env('LASTFM_USER') + 'user' => env('LASTFM_USER'), + 'toptracks' => env('LASTFM_TOP_TRACKS') ] ]; diff --git a/resources/views/components/lastfm.blade.php b/resources/views/components/lastfm.blade.php index 78c5f81..92b2c9c 100644 --- a/resources/views/components/lastfm.blade.php +++ b/resources/views/components/lastfm.blade.php @@ -1,67 +1,26 @@ -get('services')['lastfm']; -$curl_current = curl_init(); - -curl_setopt_array($curl_current, [ - CURLOPT_URL => "https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=".$cfg['user']."&nowplaying=true&format=json&api_key=".$cfg['key'], - CURLOPT_RETURNTRANSFER => true, - CURLOPT_ENCODING => "", - CURLOPT_MAXREDIRS => 10, - CURLOPT_TIMEOUT => 30, - CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, - CURLOPT_CUSTOMREQUEST => "GET", -]); - -$current_response = curl_exec($curl_current); -$err = curl_error($curl_current); - -curl_close($curl_current); - -if ($err) { - die("cURL Error #:" . $err); -} -$current_response = json_decode($current_response, true); -$nowplaying = $current_response['recenttracks']['track'][0]; - - -$tracks_to_show = 10; - -$curl = curl_init(); -curl_setopt_array($curl, [ - CURLOPT_URL => "https://ws.audioscrobbler.com/2.0/?method=user.gettoptracks&user=".$cfg['user']."&format=json&period=7day&api_key=".$cfg['key'], - CURLOPT_RETURNTRANSFER => true, - CURLOPT_ENCODING => "", - CURLOPT_MAXREDIRS => 10, - CURLOPT_TIMEOUT => 30, - CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, - CURLOPT_CUSTOMREQUEST => "GET", -]); - -$toptracks = curl_exec($curl); -$err = curl_error($curl); -curl_close($curl); -if ($err) { - die("cURL Error #:" . $err); -} - -$toptracks = json_decode($toptracks, true); -$tracks = $toptracks['toptracks']['track']; +$current_response = json_decode(file_get_contents("https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=".$cfg['user']."&nowplaying=true&format=json&api_key=".$cfg['key'])); +$nowplaying = $current_response->recenttracks->track[0]; +$toptracks = json_decode(file_get_contents("https://ws.audioscrobbler.com/2.0/?method=user.gettoptracks&user=".$cfg['user']."&format=json&period=7day&api_key=".$cfg['key'])); +$tracks = $toptracks->toptracks->track; $count = 0; -?> +@endphp

Last.fm (Profile)

- Last/Current Track: {{ $nowplaying['name'] }} • {{ $nowplaying['artist']['#text'] }} -

Top {{ $tracks_to_show }} Tracks (Last 7 days)

+ Last/Current Track: {{ $nowplaying->name }} • {{ $nowplaying->artist->{"#text"} }} +

Top {{ $cfg['toptracks'] }} Tracks (Last 7 days)

    @foreach ($tracks as $track) - @if ($count >= $tracks_to_show) + @if ($count >= $cfg['toptracks'])
@break @endif
  • - {{ $track['name'] }} • {{ $track['artist']['name'] }} - ({{$track['playcount']}} plays) + {{ $track->name }} • {{ $track->artist->name }} + ({{ $track->playcount }} plays)
  • - +@php $count++ @endphp @endforeach