PHP code example of calliostro / discogs-bundle

1. Go to this page and download the library: Download calliostro/discogs-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

calliostro / discogs-bundle example snippets



// src/Controller/MusicController.php

namespace App\Controller;

use Calliostro\Discogs\DiscogsClient;
use Symfony\Component\HttpFoundation\JsonResponse;

class MusicController
{
    public function artistInfo(string $id, DiscogsClient $client): JsonResponse
    {
        $artist = $client->getArtist(artistId: $id);
        $releases = $client->listArtistReleases(artistId: $id, perPage: 5);

        return new JsonResponse([
            'artist' => $artist['name'],
            'profile' => $artist['profile'] ?? null,
            'releases' => $releases['releases'],
        ]);
    }
}

// Requires Personal Access Token
$collection = $client->listCollectionItems(username: 'your-username', folderId: 0);
$wantlist = $client->getUserWantlist(username: 'your-username');

$client->addToCollection(
    username: 'your-username',
    folderId: 1,
    releaseId: 30359313 // Billie Eilish - Happier Than Ever
);

$client->addToWantlist(username: 'your-username', releaseId: 28409710); // Taylor Swift - Midnights

$results = $client->search(
    q: 'Billie Eilish',
    type: 'artist'
);

$releases = $client->listArtistReleases(artistId: 4470662);  // Billie Eilish
$release = $client->getRelease(releaseId: 30359313);         // Happier Than Ever
$master = $client->getMaster(masterId: 2835729);             // Midnights master
$label = $client->getLabel(labelId: 12677);                  // Interscope Records


// src/Service/MusicService.php

namespace App\Service;

use Calliostro\Discogs\DiscogsClient;

class MusicService
{
    public function __construct(
        private readonly DiscogsClient $client
    ) {
    }

    public function getArtistWithReleases(int $artistId): array
    {
        $artist = $this->client->getArtist(artistId: $artistId);
        $releases = $this->client->listArtistReleases(
            artistId: $artistId,
            perPage: 10
        );

        return [
            'artist' => $artist,
            'releases' => $releases['releases'],
        ];
    }

    public function addToMyCollection(int $releaseId): void
    {
        // Requires Personal Access Token
        $this->client->addToCollection(
            username: 'your-username', // Replace with actual username
            folderId: 1, // "Uncategorized" folder
            releaseId: $releaseId
        );
    }
}