composer require havenstd06/laravel-plex
php artisan vendor:publish --provider="Havenstd06\LaravelPlex\Providers\PlexServiceProvider"
After publishing the assets, add the following to your .env files .
# Plex API
PLEX_SERVER_URL=
PLEX_TOKEN=
PLEX_CLIENT_IDENTIFIER=
PLEX_PRODUCT=havenstd06/laravel-plex
PLEX_VERSION=1.0.0
PLEX_VALIDATE_SSL=true
The configuration file plex.php is located in the config folder. Following are its contents when published:
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;
You can override Plex API configuration by calling setApiCredentials method:
$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);
Sign In to return Plex user data (included token).
$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'];
Get server accounts details.
$provider->getAccounts();
Get account information
$provider->getPlexAccount();
Get Plex.TV account information.
$provider->getServerPlexAccount();
List all home users, including guests (Users & Sharing in UI)
$provider->getUsers();
Validate username or email
$provider->validateUser('username | email');
Get shares friends list.
$provider->getFriends();
Invite a friend.
If you don't pass an array with the library ids ($librarySectionIds
), all the libraries of the server will be taken.
Settings are optional too.
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('me@hvs.cx', $librarySectionIds, $settings);
Cancel invitation.
$provider->cancelInvite('me@hvs.cx');
Get pending invitations list.
$provider->getPendingInvites();
Remove friend.
$provider->removeFriend(12345678); // Friend ID / InvitedID
Get friends details
$provider->getFriendDetail(12345678); // Friend ID / InvitedID
Update friend restrictions
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
Update friend libraries
$librarySectionIds = [
652397653,
765367227,
887542234
];
$provider->updateFriendLibraries(12345678, $librarySectionIds); // Friend ID / InvitedID
Get the local List of servers.
$provider->getServers();
Get servers detail (contain libraries ids)
$provider->getServerDetail($machineIdentifier); // optional argument
Get server identity details
$provider->getServerIdentity();
Gets a list of servers and their sections. Limited to servers that have remote access enabled. The second parameter is for include lite.
$provider->getPmsServers(true);
Get server capabilities details. Transcode bitrate info, server info.
$provider->getServerCapabilities();
Gets the server preferences.
$provider->getServerPreferences();
General plex system information.
$provider->getSystem();
Agents available (and some of their configuration)
$provider->getSystemAgents();
This will search in the database for the string provided.
$provider->searchDatabase('Avengers');
This will retrieve the "Now Playing" Information of the PMS.
$provider->getNowPlaying();
Retrieves a listing of all history views.
$provider->getViewsHistory();
Gets a list of available clients and servers.
$provider->getDevices();
Get servers devices details.
$provider->getDevices();
Gets a list of servers, devices and their sections
$provider->getResources();
This will search in the library for the string provided. The second parameter is the limit.
$provider->searchLibrary('Avengers', 10);
Show ondeck list
$provider->getOnDeck();
Contains all of the sections on the PMS. Confusingly, Plex's UI calls a section a library: e.g. "TV shows" or "Movies". This acts as a directory and you are able to "walk" through it.
$provider->getLibraries();
Get all data in the library for the section passed in.
$provider->getLibrary(1);
Delete a section
$provider->deleteLibrary(1);
Refreshes the library for the section passed in.
$provider->refreshLibrary(1);
Get playlists list.
$provider->getPlaylists();
The key associated with a library.
This key can be found by calling the getPlaylists
method.
$provider->getPlaylist(2);
The key associated with a library.
This key can be found by calling the getPlaylists
method.
$provider->getPlaylistItems(2);
Get photo of specified height and width.
$provider->getPhoto('path', 480, 719);
Ask the server whether it can provide the video with/without transcoding (based on the client profile).
$provider->getVideo('path', 'http');
Marks item with the corresponding "rating key" as watched.
$provider->scrobble('item rating key');
Marks item with the corresponding "rating key" as unwatched.
$provider->unscrobble('item rating key');
Marks media item with the corresponding "rating key" as partially watched, populating its "viewOffset" field.
Time is in milliseconds.
$provider->progress('item rating key', 'offset');
Get Translations for example: fr
$provider->getTranslations('fr');
Pull requests are welcome.
For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.