PHP code example of havenstd06 / laravel-plex

1. Go to this page and download the library: Download havenstd06/laravel-plex 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/ */

    

havenstd06 / laravel-plex example snippets


return [
    'server_url'         => env('PLEX_SERVER_URL', ''), // Plex Server URL (ex: http://[IP address]:32400)
    'token'              => env('PLEX_TOKEN', ''),

    'client_identifier'  => env('PLEX_CLIENT_IDENTIFIER', ''), // (UUID, serial number, or other number unique per device)
    'product'            => env('PLEX_PRODUCT', 'havenstd06/laravel-plex'), // (Plex application name, eg Laika, Plex Media Server, Media Link)
    'version'            => env('PLEX_VERSION', '1.0.0'), // (Plex application version number)

    'validate_ssl'       => env('PLEX_VALIDATE_SSL', true), // Validate SSL when creating api client.
];

use Havenstd06\LaravelPlex\Services\Plex as PlexClient;

$provider = new PlexClient;

$config = [
    'server_url'        => 'https://example.com',
    'token'             => 'your-token',
    
    'client_identifier' => 'your-client-identifier',
    'product'           => 'your-product',
    'version'           => 'your-version',
    
    'validate_ssl'      => true,
];

$provider->setApiCredentials($config);

$data = [
    'auth' => [
        'username/email', // Required
        'password', // Required
    ],
    'headers' => [
        // Headers: https://github.com/Arcanemagus/plex-api/wiki/Plex.tv#request-headers
        // X-Plex-Client-Identifier is already defined in default config file
    ]
];

// The second parameter allows you to choose if you want to
// authenticate with the token registered in the config
// (ONLY IF THE TOKEN EXISTS).
$plexUser = $provider->signIn($data, false);
$token = $plexUser['user']['authToken'];

$provider->getAccounts();

$provider->getPlexAccount();

$provider->getServerPlexAccount();

$provider->getUsers();

$provider->validateUser('username | email');

$provider->getFriends();

use Havenstd06\LaravelPlex\Classes\FriendRestrictionsSettings;

$librarySectionIds = [
    652397653,
    765367227,
    887542234
];

$settings = new FriendRestrictionsSettings(
    allowChannels: '1',
    allowSubtitleAdmin: '1',
    allowSync: '0',
    allowTuners: '0',
    filterMovies: '',
    filterMusic: '',
    filterTelevision: '',
);

$provider->inviteFriend('[email protected]', $librarySectionIds, $settings);

$provider->cancelInvite('[email protected]');

$provider->getPendingInvites();

$provider->removeFriend(12345678); // Friend ID / InvitedID

$provider->getFriendDetail(12345678); // Friend ID / InvitedID

use Havenstd06\LaravelPlex\Classes\FriendRestrictionsSettings;

$settings = new FriendRestrictionsSettings(
    allowChannels: '1',
    allowSubtitleAdmin: '1',
    allowSync: '0',
    allowTuners: '0',
    filterMovies: '',
    filterMusic: '',
    filterTelevision: '',
);

$provider->updateFriendRestrictions(12345678, $settings); // Friend ID / InvitedID

$librarySectionIds = [
    652397653,
    765367227,
    887542234
];

$provider->updateFriendLibraries(12345678, $librarySectionIds); // Friend ID / InvitedID

$provider->getServers();

$provider->getServerDetail($machineIdentifier); // optional argument

$provider->getServerIdentity();

$provider->getPmsServers(true);

$provider->getServerCapabilities();

$provider->getServerPreferences();

$provider->getSystem();

$provider->getSystemAgents();

$provider->searchDatabase('Avengers');

$provider->getNowPlaying();

$provider->getViewsHistory();

$provider->getDevices();

$provider->getDevices();

$provider->getResources();

$provider->searchLibrary('Avengers', 10);

$provider->getOnDeck();

$provider->getLibraries();

$provider->getLibrary(1);

$provider->deleteLibrary(1);

$provider->refreshLibrary(1);

$provider->getPlaylists();

$provider->getPlaylist(2);

$provider->getPlaylistItems(2);

$provider->getPhoto('path', 480, 719);

$provider->getVideo('path', 'http');

$provider->scrobble('item rating key');

$provider->unscrobble('item rating key');

$provider->progress('item rating key', 'offset');

$provider->getTranslations('fr');
bash
php artisan vendor:publish --provider="Havenstd06\LaravelPlex\Providers\PlexServiceProvider"