Documentation ¶
Overview ¶
Package plex provides the methods the Notifiarr client uses to interface with Plex. This package also provides a web handler for incoming plex webhooks, and another two handlers for requests from Notifiarr.com to list sessions and kill a session. The purpose is to keep track of Plex viewers and send meaningful alerts to their respective Disord server about user behavior. ie. user started watching something, paused it, resumed it, and finished something. This package can be disabled by not providing a Plex Media Server URL or Token.
Index ¶
- Variables
- type Country
- type Director
- type Directory
- type GUID
- type Genre
- type LibrarySection
- type Media
- type MediaPart
- type MediaStream
- type PMSInfo
- type Player
- type Producer
- type Role
- type Server
- func (s *Server) Configured() bool
- func (s *Server) GetInfo() (*PMSInfo, error)
- func (s *Server) GetPlexSectionKey(keyPath string) (*LibrarySection, error)
- func (s *Server) GetSessions() (*Sessions, error)
- func (s *Server) GetSessionsWithContext(ctx context.Context) (*Sessions, error)
- func (s *Server) HandleKillSession(r *http.Request) (int, interface{})
- func (s *Server) HandleSessions(r *http.Request) (int, interface{})
- func (s *Server) KillSession(sessionID, reason string) ([]byte, error)
- func (s *Server) KillSessionWithContext(ctx context.Context, sessionID, reason string) ([]byte, error)
- func (s *Server) Validate()
- type Session
- type Sessions
- type Similar
- type Transcode
- type User
- type Writer
Constants ¶
This section is empty.
Variables ¶
var ErrBadStatus = fmt.Errorf("status code not 200")
ErrBadStatus is returned when plex returns an invalid status code.
var ErrNoURLToken = fmt.Errorf("token or URL for Plex missing")
ErrNoURLToken is returned when there is no token or URL.
Functions ¶
This section is empty.
Types ¶
type Country ¶
type Country struct { Count string `json:"count"` Filter string `json:"filter"` ID string `json:"id"` Tag string `json:"tag"` }
Country is part of a Plex Session.
type Director ¶
type Director struct { Filter string `json:"filter"` ID string `json:"id"` Tag string `json:"tag"` }
Director is part of a Plex Session.
type Directory ¶ added in v0.1.7
type Directory struct { Count int `json:"count"` Key string `json:"key"` Title string `json:"title"` }
Directory is part of the PMSInfo.
type GUID ¶
type GUID struct {
ID string `json:"id"`
}
GUID is a reusable type from the Section library.
type Genre ¶
type Genre struct { Count string `json:"count"` Filter string `json:"filter"` ID string `json:"id"` Tag string `json:"tag"` }
Genre is part of a Plex Session.
type LibrarySection ¶
type LibrarySection struct { Size int `json:"size"` AllowSync bool `json:"allowSync"` Identifier string `json:"identifier"` LibrarySectionID int `json:"librarySectionID"` LibrarySectionTitle string `json:"librarySectionTitle"` LibrarySectionUUID string `json:"librarySectionUUID"` MediaTagPrefix string `json:"mediaTagPrefix"` MediaTagVersion int `json:"mediaTagVersion"` Metadata []struct { RatingKey string `json:"ratingKey"` Key string `json:"key"` ParentRatingKey string `json:"parentRatingKey,omitempty"` GrandparentRatingKey string `json:"grandparentRatingKey,omitempty"` GUID string `json:"guid"` ParentGUID string `json:"parentGuid,omitempty"` GrandparentGUID string `json:"grandparentGuid,omitempty"` Type string `json:"type"` Title string `json:"title"` GrandparentKey string `json:"grandparentKey,omitempty"` ParentKey string `json:"parentKey,omitempty"` LibrarySectionTitle string `json:"librarySectionTitle"` LibrarySectionID int `json:"librarySectionID"` LibrarySectionKey string `json:"librarySectionKey"` GrandparentTitle string `json:"grandparentTitle,omitempty"` ParentTitle string `json:"parentTitle,omitempty"` ContentRating string `json:"contentRating"` Summary string `json:"summary"` Index int `json:"index,omitempty"` ParentIndex int `json:"parentIndex,omitempty"` Rating float64 `json:"rating,omitempty"` Year int `json:"year,omitempty"` Thumb string `json:"thumb"` Art string `json:"art"` ParentThumb string `json:"parentThumb,omitempty"` GrandparentThumb string `json:"grandparentThumb,omitempty"` GrandparentArt string `json:"grandparentArt,omitempty"` GrandparentTheme string `json:"grandparentTheme,omitempty"` Duration int `json:"duration"` OriginallyAvailableAt string `json:"originallyAvailableAt"` AddedAt int `json:"addedAt"` UpdatedAt int `json:"updatedAt"` Media []struct { ID int `json:"id"` Duration int `json:"duration"` Bitrate int `json:"bitrate"` Width int `json:"width"` Height int `json:"height"` AspectRatio float64 `json:"aspectRatio"` AudioChannels int `json:"audioChannels"` AudioCodec string `json:"audioCodec"` VideoCodec string `json:"videoCodec"` VideoResolution string `json:"videoResolution"` Container string `json:"container"` VideoFrameRate string `json:"videoFrameRate"` OptimizedForStreaming int `json:"optimizedForStreaming"` AudioProfile string `json:"audioProfile"` Has64BitOffsets bool `json:"has64bitOffsets"` VideoProfile string `json:"videoProfile"` Part []struct { ID int `json:"id"` Key string `json:"key"` Duration int `json:"duration"` File string `json:"file"` Size int `json:"size"` AudioProfile string `json:"audioProfile"` Container string `json:"container"` Indexes string `json:"indexes"` VideoProfile string `json:"videoProfile"` OptimizedForStreaming bool `json:"optimizedForStreaming"` Has64BitOffsets bool `json:"has64bitOffsets"` Stream []struct { ID int `json:"id"` StreamType int `json:"streamType"` Codec string `json:"codec"` Index int `json:"index"` Bitrate int `json:"bitrate"` BitDepth int `json:"bitDepth,omitempty"` ChromaLocation string `json:"chromaLocation,omitempty"` ChromaSubsampling string `json:"chromaSubsampling,omitempty"` CodedHeight int `json:"codedHeight,omitempty"` CodedWidth int `json:"codedWidth,omitempty"` ColorRange string `json:"colorRange,omitempty"` ColorSpace string `json:"colorSpace,omitempty"` FrameRate float64 `json:"frameRate,omitempty"` Height int `json:"height,omitempty"` Level int `json:"level,omitempty"` Profile string `json:"profile"` RefFrames int `json:"refFrames,omitempty"` StreamIdentifier string `json:"streamIdentifier"` Width int `json:"width,omitempty"` DisplayTitle string `json:"displayTitle"` ExtendedDisplayTitle string `json:"extendedDisplayTitle"` Channels int `json:"channels,omitempty"` Language string `json:"language,omitempty"` LanguageCode string `json:"languageCode,omitempty"` AudioChannelLayout string `json:"audioChannelLayout,omitempty"` SamplingRate int `json:"samplingRate,omitempty"` Selected bool `json:"selected,omitempty"` HasScalingMatrix bool `json:"hasScalingMatrix,omitempty"` Default bool `json:"default"` } `json:"Stream"` } `json:"Part"` } `json:"Media"` TitleSort string `json:"titleSort,omitempty"` ViewOffset int `json:"viewOffset,omitempty"` LastViewedAt int `json:"lastViewedAt,omitempty"` ParentYear int `json:"parentYear,omitempty"` Studio string `json:"studio,omitempty"` AudienceRating float64 `json:"audienceRating,omitempty"` ViewCount int `json:"viewCount,omitempty"` Tagline string `json:"tagline,omitempty"` AudienceRatingImage string `json:"audienceRatingImage,omitempty"` ChapterSource string `json:"chapterSource,omitempty"` PrimaryExtraKey string `json:"primaryExtraKey,omitempty"` RatingImage string `json:"ratingImage,omitempty"` GuID []*GUID `json:"Guid,omitempty"` } `json:"Metadata"` }
LibrarySection is a plex response struct.
type Media ¶
type Media struct { AspectRatio string `json:"aspectRatio"` AudioChannels int `json:"audioChannels"` AudioCodec string `json:"audioCodec"` AudioProfile string `json:"audioProfile"` Bitrate float64 `json:"bitrate"` Container string `json:"container"` Duration float64 `json:"duration"` Height int64 `json:"height"` ID string `json:"id"` Protocol string `json:"protocol"` StreamingOptmzd bool `json:"optimizedForStreaming"` VideoCodec string `json:"videoCodec"` VideoFrameRate string `json:"videoFrameRate"` VideoProfile string `json:"videoProfile"` VideoResolution string `json:"videoResolution"` Width int64 `json:"width"` Selected bool `json:"selected"` Part []*MediaPart `json:"Part"` }
Media is part of a Plex Session.
type MediaPart ¶
type MediaPart struct { AudioProfile string `json:"audioProfile"` Bitrate float64 `json:"bitrate"` Container string `json:"container"` Decision string `json:"decision"` Duration float64 `json:"duration"` File string `json:"file"` Height int64 `json:"height"` ID string `json:"id"` Indexes string `json:"indexes"` Key string `json:"key"` Protocol string `json:"protocol"` Selected bool `json:"selected"` Size int64 `json:"size"` StreamingOptmzd bool `json:"optimizedForStreaming"` VideoProfile string `json:"videoProfile"` Width int64 `json:"width"` Stream []*MediaStream `json:"Stream"` }
MediaPart is part of a Plex Session.
type MediaStream ¶
type MediaStream struct { AudioChannelLayout string `json:"audioChannelLayout,omitempty"` BitDepth int `json:"bitDepth,omitempty"` Bitrate float64 `json:"bitrate"` BitrateMode string `json:"bitrateMode,omitempty"` Channels int `json:"channels,omitempty"` ChromaLocation string `json:"chromaLocation,omitempty"` ChromaSubsampling string `json:"chromaSubsampling,omitempty"` Codec string `json:"codec"` CodedHeight int64 `json:"codedHeight,omitempty"` CodedWidth int64 `json:"codedWidth,omitempty"` ColorPrimaries string `json:"colorPrimaries,omitempty"` ColorTrc string `json:"colorTrc,omitempty"` Decision string `json:"decision"` Default bool `json:"default,omitempty"` DisplayTitle string `json:"displayTitle"` ExtDisplayTitle string `json:"extendedDisplayTitle"` FrameRate float64 `json:"frameRate,omitempty"` HasScalingMatrix bool `json:"hasScalingMatrix,omitempty"` Height int64 `json:"height,omitempty"` ID string `json:"id"` Index int `json:"index"` Language string `json:"language,omitempty"` LanguageCode string `json:"languageCode,omitempty"` Level int `json:"level,omitempty"` Location string `json:"location"` Profile string `json:"profile"` RefFrames int `json:"refFrames,omitempty"` SamplingRate int `json:"samplingRate,omitempty"` ScanType string `json:"scanType,omitempty"` Selected bool `json:"selected,omitempty"` StreamType int `json:"streamType"` Width int64 `json:"width,omitempty"` LanguageTag string `json:"languageTag,omitempty"` }
MediaStream is part of a Plex Session.
type PMSInfo ¶ added in v0.1.7
type PMSInfo struct { Size int64 `json:"size"` AllowCameraUpload bool `json:"allowCameraUpload"` AllowChannelAccess bool `json:"allowChannelAccess"` AllowSharing bool `json:"allowSharing"` AllowSync bool `json:"allowSync"` AllowTuners bool `json:"allowTuners"` BackgroundProcessing bool `json:"backgroundProcessing"` Certificate bool `json:"certificate"` CompanionProxy bool `json:"companionProxy"` CountryCode string `json:"countryCode"` Diagnostics string `json:"diagnostics"` EventStream bool `json:"eventStream"` FriendlyName string `json:"friendlyName"` HubSearch bool `json:"hubSearch"` ItemClusters bool `json:"itemClusters"` LiveTV int64 `json:"livetv"` MachineIdentifier string `json:"machineIdentifier"` MaxUploadBitrate int64 `json:"maxUploadBitrate"` MaxUploadBitrateReason string `json:"maxUploadBitrateReason"` MaxUploadBitrateReasonMessage string `json:"maxUploadBitrateReasonMessage"` MediaProviders bool `json:"mediaProviders"` Multiuser bool `json:"multiuser"` MyPlex bool `json:"myPlex"` MyPlexMappingState string `json:"myPlexMappingState"` MyPlexSigninState string `json:"myPlexSigninState"` MyPlexSubscription bool `json:"myPlexSubscription"` MyPlexUsername string `json:"myPlexUsername"` OfflineTranscode int64 `json:"offlineTranscode"` OwnerFeatures string `json:"ownerFeatures"` PhotoAutoTag bool `json:"photoAutoTag"` Platform string `json:"platform"` PlatformVersion string `json:"platformVersion"` PluginHost bool `json:"pluginHost"` PushNotifications bool `json:"pushNotifications"` ReadOnlyLibraries bool `json:"readOnlyLibraries"` RequestParametersInCookie bool `json:"requestParametersInCookie"` StreamingBrainABRVersion int64 `json:"streamingBrainABRVersion"` StreamingBrainVersion int64 `json:"streamingBrainVersion"` Sync bool `json:"sync"` TranscoderActiveVideoSessions int64 `json:"transcoderActiveVideoSessions"` TranscoderAudio bool `json:"transcoderAudio"` TranscoderLyrics bool `json:"transcoderLyrics"` TranscoderPhoto bool `json:"transcoderPhoto"` TranscoderSubtitles bool `json:"transcoderSubtitles"` TranscoderVideo bool `json:"transcoderVideo"` TranscoderVideoBitrates string `json:"transcoderVideoBitrates"` TranscoderVideoQualities string `json:"transcoderVideoQualities"` TranscoderVideoResolutions string `json:"transcoderVideoResolutions"` UpdatedAt int64 `json:"updatedAt"` Updater bool `json:"updater"` Version string `json:"version"` VoiceSearch bool `json:"voiceSearch"` Directory []*Directory `json:"Directory"` } // `json:"MediaContainer"`
PMSInfo is the `/` path on Plex.
type Player ¶
type Player struct { Address string `json:"address"` Device string `json:"device"` MachineID string `json:"machineIdentifier"` Model string `json:"model"` Platform string `json:"platform"` PlatformVer string `json:"platformVersion"` Product string `json:"product"` Profile string `json:"profile"` PublicAddr string `json:"remotePublicAddress"` State string `json:"state"` StateTime structDur `json:"stateTime"` // this is not a plex item. We calculate this. Title string `json:"title"` UserID int64 `json:"userID"` Vendor string `json:"vendor"` Version string `json:"version"` Relayed bool `json:"relayed"` Local bool `json:"local"` Secure bool `json:"secure"` }
Player is part of a Plex Session.
type Producer ¶
type Producer struct { Count string `json:"count"` Filter string `json:"filter"` ID string `json:"id"` Tag string `json:"tag"` }
Producer is part of a Plex Session.
type Role ¶
type Role struct { Count string `json:"count,omitempty"` Filter string `json:"filter"` ID string `json:"id"` Role string `json:"role"` Tag string `json:"tag"` Thumb string `json:"thumb,omitempty"` }
Role is part of a Plex Session.
type Server ¶
type Server struct { Timeout cnfg.Duration `toml:"timeout" xml:"timeout" json:"timeout"` Interval cnfg.Duration `toml:"interval" xml:"interval" json:"interval"` URL string `toml:"url" xml:"url" json:"url"` Token string `toml:"token" xml:"token" json:"token"` AccountMap string `toml:"account_map" xml:"account_map" json:"accountMap"` Name string `toml:"-" xml:"-" json:"-"` NoActivity bool `toml:"no_activity" xml:"no_activity" json:"noActivity"` Delay cnfg.Duration `toml:"activity_delay" xml:"activity_delay" json:"activityDelay"` Cooldown cnfg.Duration `toml:"cooldown" xml:"cooldown" json:"cooldown"` SeriesPC uint `toml:"series_percent_complete" xml:"series_percent_complete" json:"seriesPc"` MoviesPC uint `toml:"movies_percent_complete" xml:"movies_percent_complete" json:"moviesPc"` // contains filtered or unexported fields }
Server is the Plex configuration from a config file. Without a URL or Token, nothing works and this package is unused.
func (*Server) Configured ¶ added in v0.1.7
Configured returns true ifthe server is configured, false otherwise.
func (*Server) GetPlexSectionKey ¶
func (s *Server) GetPlexSectionKey(keyPath string) (*LibrarySection, error)
GetPlexSectionKey gets a section key from Plex based on a key path.
func (*Server) GetSessions ¶
GetSessions returns the Plex sessions in JSON format, no timeout.
func (*Server) GetSessionsWithContext ¶ added in v0.1.5
GetSessionsWithContext returns the Plex sessions in JSON format.
func (*Server) HandleKillSession ¶ added in v0.1.5
HandleKillSession provides a web handler to the notifiarr client allows notifiarr.com (via Discord request) to end a Plex session. The handler satisfies apps.APIHandler, sorry.
func (*Server) HandleSessions ¶ added in v0.1.5
HandleSessions provides a web handler to the notifiarr client that returns the current Plex sessions. The handler satisfies apps.APIHandler, sorry.
func (*Server) KillSession ¶ added in v0.1.5
KillSession kills a Plex session.
type Session ¶
type Session struct { User User `json:"User"` Player Player `json:"Player"` TranscodeSession Transcode `json:"TranscodeSession"` Added int64 `json:"addedAt"` Art string `json:"art"` AudienceRating float64 `json:"audienceRating"` AudienceRatingImg string `json:"audienceRatingImage"` ContentRating string `json:"contentRating"` Duration float64 `json:"duration"` GUID string `json:"guid"` GrandparentArt string `json:"grandparentArt"` GrandparentGUID string `json:"grandparentGuid"` GrandparentKey string `json:"grandparentKey"` GrandparentRatingKey string `json:"grandparentRatingKey"` GrandparentTheme string `json:"grandparentTheme"` GrandparentThumb string `json:"grandparentThumb"` GrandparentTitle string `json:"grandparentTitle"` Index int `json:"index"` Key string `json:"key"` LastViewed int64 `json:"lastViewedAt"` LibrarySectionID string `json:"librarySectionID"` LibrarySectionKey string `json:"librarySectionKey"` LibrarySectionTitle string `json:"librarySectionTitle"` OriginallyAvailable string `json:"originallyAvailableAt"` ParentGUID string `json:"parentGuid"` ParentIndex int `json:"parentIndex"` ParentKey string `json:"parentKey"` ParentRatingKey string `json:"parentRatingKey"` ParentThumb string `json:"parentThumb"` ParentTitle string `json:"parentTitle"` PrimaryExtraKey string `json:"primaryExtraKey"` Rating float64 `json:"rating"` RatingImage string `json:"ratingImage"` RatingKey string `json:"ratingKey"` SessionKey string `json:"sessionKey"` Studio string `json:"studio"` Summary string `json:"summary"` Thumb string `json:"thumb"` Title string `json:"title"` TitleSort string `json:"titleSort"` Type string `json:"type"` Updated int64 `json:"updatedAt"` ViewCount int64 `json:"viewCount"` ViewOffset float64 `json:"viewOffset"` Year int64 `json:"year"` Session struct { Bandwidth int64 `json:"bandwidth"` ID string `json:"id"` Location string `json:"location"` } `json:"Session"` GuID []*GUID `json:"Guid,omitempty"` Media []*Media `json:"Media,omitempty"` }
Session is a Plex json struct.
type Sessions ¶
type Sessions struct { Name string `json:"server"` HostID string `json:"hostId"` Sessions []*Session `json:"sessions"` Updated structDur `json:"updateTime,omitempty"` }
Sessions is the config input data.
type Similar ¶
type Similar struct { Filter string `json:"filter"` ID string `json:"id"` Tag string `json:"tag"` Count string `json:"count,omitempty"` }
Similar is part of a Plex Session.
type Transcode ¶
type Transcode struct { AudioChannels int `json:"audioChannels"` AudioCodec string `json:"audioCodec"` AudioDecision string `json:"audioDecision"` Container string `json:"container"` Context string `json:"context"` Duration int64 `json:"duration"` Key string `json:"key"` MaxOffsetAvailable float64 `json:"maxOffsetAvailable"` MinOffsetAvailable float64 `json:"minOffsetAvailable"` Progress float64 `json:"progress"` Protocol string `json:"protocol"` Remaining int64 `json:"remaining"` Size int64 `json:"size"` SourceAudioCodec string `json:"sourceAudioCodec"` SourceVideoCodec string `json:"sourceVideoCodec"` Speed float64 `json:"speed"` TimeStamp float64 `json:"timeStamp"` VideoCodec string `json:"videoCodec"` VideoDecision string `json:"videoDecision"` Throttled bool `json:"throttled"` Complete bool `json:"complete"` XcodeHwFullPipeline bool `json:"transcodeHwFullPipeline"` XcodeHwRequested bool `json:"transcodeHwRequested"` }
Transcode is part of a Plex Session.