From 8e627b16712e90134919c7366dffa4993a13165a Mon Sep 17 00:00:00 2001 From: Frankie B Date: Tue, 13 Jun 2023 23:07:20 +0100 Subject: Add global layout and homepage --- resources/views/components/lastfm.blade.php | 67 +++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 resources/views/components/lastfm.blade.php (limited to 'resources/views/components/lastfm.blade.php') diff --git a/resources/views/components/lastfm.blade.php b/resources/views/components/lastfm.blade.php new file mode 100644 index 0000000..78c5f81 --- /dev/null +++ b/resources/views/components/lastfm.blade.php @@ -0,0 +1,67 @@ +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']; +$count = 0; +?> + +

Last.fm (Profile)

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

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

+
    +@foreach ($tracks as $track) + @if ($count >= $tracks_to_show) +
+ @break + @endif +
  • + {{ $track['name'] }} • {{ $track['artist']['name'] }} + ({{$track['playcount']}} plays) +
  • + +@endforeach -- cgit v1.2.3-54-g00ecf