Categorygithub.com/derezzolution/go-plex-client
modulepackage
0.0.0-20240310223259-4db197a28115
Repository: https://github.com/derezzolution/go-plex-client.git
Documentation: pkg.go.dev

# README

Plex.tv and Plex Media Server client written in Go

godoc

go get -u github.com/derezzolution/go-plex-client

Cli

You can tinker with this library using the command-line over here

Usage

plexConnection, err := plex.New("http://192.168.1.2:32400", "myPlexToken")

// Test your connection to your Plex server
result, err := plexConnection.Test()

// Search for media in your plex server
results, err := plexConnection.Search("The Walking Dead")

// Webhook handler to easily handle events on your server
	wh := plex.NewWebhook()

	wh.OnPlay(func(w plex.Webhook) {
		fmt.Printf("%s is playing\n", w.Metadata.Title)
	})

	wh.OnPause(func(w plex.Webhook) {
		fmt.Printf("%s is paused\n", w.Metadata.Title)
	})

	wh.OnResume(func(w plex.Webhook) {
		fmt.Printf("%s has resumed\n", w.Metadata.Title)
	})

	wh.OnStop(func(w plex.Webhook) {
		fmt.Printf("%s has stopped\n", w.Metadata.Title)
	})

	http.HandleFunc("/", wh.Handler)

	http.ListenAndServe("192.168.1.14:8080", nil)

// connect to your server via websockets to listen for events

ctrlC := make(chan os.Signal, 1)
onError := func(err error) {
	fmt.Println(err)
}

events := plex.NewNotificationEvents()
events.OnPlaying(func(n NotificationContainer) {
	mediaID := n.PlaySessionStateNotification[0].RatingKey
	sessionID := n.PlaySessionStateNotification[0].SessionKey
	var title

	sessions, err := plexConnection.GetSessions()

	if err != nil {
		fmt.Printf("failed to fetch sessions on plex server: %v\n", err)
		return
	}

	for _, session := range sessions.MediaContainer.Video {
		if sessionID != session.SessionKey {
			continue
		}

		userID = session.User.ID
		username = session.User.Title

		break
	}

	metadata, err := plexConnection.GetMetadata(mediaID)

	if err != nil {
		fmt.Printf("failed to get metadata for key %s: %v\n", mediaID, err)
	} else {
		title = metadata.MediaContainer.Metadata[0].Title
	}

	fmt.Printf("user (id: %s) has started playing %s (id: %s) %s\n", username, userID, title, mediaID)
})

plexConnection.SubscribeToNotifications(events, ctrlC, onError)

// ... and more! Please checkout plex.go for more methods

# Packages

No description provided by the author

# Functions

CheckPIN will return information related to the pin such as the auth token if your code has been approved.
GetMediaType is a helper function that returns the media type.
GetMediaTypeID returns plex's media type id.
LibraryParamsFromMediaType is a helper for CreateLibraryParams.
New creates a new plex instance that is required to to make requests to your Plex Media Server.
NewNotificationEvents initializes the event callbacks.
NewWebhook inits and returns a webhook event.
RequestPIN will retrieve a code (valid for 15 minutes) from plex.tv to link an app to your plex account.
SignIn creates a plex instance using a user name and password instead of an auth token.

# Constants

ErrorInvalidToken a constant to help check invalid token errors.
ErrorInvalidToken a constant to help check invalid token errors.
ErrorInvalidToken a constant to help check invalid token errors.
ErrorInvalidToken a constant to help check invalid token errors.
ErrorInvalidToken a constant to help check invalid token errors.
ErrorInvalidToken a constant to help check invalid token errors.
ErrorInvalidToken a constant to help check invalid token errors.
ErrorInvalidToken a constant to help check invalid token errors.
ErrorInvalidToken a constant to help check invalid token errors.
ErrorInvalidToken a constant to help check invalid token errors.
ErrorInvalidToken a constant to help check invalid token errors.
ErrorInvalidToken a constant to help check invalid token errors.
ErrorInvalidToken a constant to help check invalid token errors.

# Structs

ActivityNotification ...
AltGUID represents a Globally Unique Identifier for a metadata provider that is not actively being used.
AltRating represents ratings for metadata providers.
BackgroundProcessingQueueEventNotification ...
BaseAPIResponse info about the Plex Media Server.
Connection lists options to connect to a device.
CreateLibraryParams params required to create a library.
CurrentSessions metadata of users consuming media.
DevicesResponse metadata of a device that has connected to your server.
Directory shows plex directory metadata.
ErrorResponse contains a code and an error message.
Friends are the plex accounts that have access to your server.
No description provided by the author
InviteFriendParams are the params to invite a friend.
LibraryLabels are the existing labels set on your server.
LibrarySections metadata of your library contents.
Location is the path of a plex server directory.
Media media info.
MediaContainer contains media info.
MediaMetadata ...
Metadata ...
MetadataChildren returns metadata about a piece of media (tv show, movie, music, etc).
NotificationContainer read pms notifications.
NotificationEvents hold callbacks that correspond to notifications.
Part ...
PinResponse holds information to successfully check a pin when linking an account.
Player ...
PlaySessionStateNotification ...
Plex contains fields that are required to make an api call to your plex server.
PMSDevices is the result of the https://plex.tv/pms/resources endpoint.
Provider ...
ReachabilityNotification ...
Role ...
SearchMediaContainer ...
SearchResults ...
SearchResultsEpisode contains metadata about an episode.
SectionIDResponse the section id (or library id) of your server useful when inviting a user to the server.
ServerInfo is the result of the https://plex.tv/api/servers endpoint.
ServerSections contains information of your library sections.
No description provided by the author
Session ...
Setting ...
StatusNotification ...
Stream ...
TaggedData ...
TimelineEntry ...
TranscodeSession ...
TranscodeSessionsResponse is the result for transcode session endpoint /transcode/sessions.
UpdateFriendParams optional parameters to update your friends access to your server.
User plex server user.
UserPlexTV plex.tv user.
Webhook contains a webhooks information.
WebhookEvents holds the actions for each webhook events.
WebsocketNotification websocket payload of notifications from a plex media server.

# Type aliases

SignInResponse response from plex.tv sign in.