Пример #1
0
        /// <inheritdoc/>
        public async Task SendPlayQueueToPlayer(string plexServerHost, string authToken, string hostIdentifier, PlayQueueContainer playQueue, string type, string playerIdentifier, string transientToken, long offset)
        {
            var uri = new Uri(plexServerHost);

            var queryParams =
                new Dictionary <string, string>
            {
                { "providerIdentifier", "com.plexapp.plugins.library" },
                { "protocol", uri.Scheme },
                { "address", uri.DnsSafeHost },
                { "port", uri.Port.ToString() },
                { "containerKey", "/playQueues/" + playQueue.PlayQueueId + "?own=1" },
                { "key", "/library/metadata/" + playQueue.PlayQueueSelectedMetadataItemId },
                { "offset", offset.ToString() },
                { "commandID", "1" },
                { "type", type },
                { "machineIdentifier", hostIdentifier },
                { "token", transientToken }
            };

            var apiRequest =
                new ApiRequestBuilder(plexServerHost, $"player/playback/playMedia", HttpMethod.Get)
                .AddPlexToken(authToken)
                .AddQueryParams(queryParams)
                .AddHeader("X-Plex-Target-Client-Identifier", playerIdentifier)
                .AddRequestHeaders(ClientUtilities.GetClientIdentifierHeader(this.clientOptions.ClientId))
                .AcceptJson()
                .Build();

            await this.apiService.InvokeApiAsync(apiRequest);
        }
Пример #2
0
        /// <inheritdoc/>
        public async Task <CollectionContainer> GetCollectionsAsync(string authToken, string plexServerHost,
                                                                    string libraryKey, string title)
        {
            var queryParams =
                new Dictionary <string, string> {
                { "includeCollections", "1" }, { "includeExternalMedia", "true" }
            };

            if (!string.IsNullOrEmpty(title))
            {
                queryParams.Add("title" + "%3d", title);
            }

            var apiRequest = new ApiRequestBuilder(plexServerHost, $"library/sections/{libraryKey}/collections",
                                                   HttpMethod.Get)
                             .AddQueryParams(queryParams)
                             .AddPlexToken(authToken)
                             .AddRequestHeaders(ClientUtilities.GetClientIdentifierHeader(this.clientOptions.ClientId))
                             .AcceptJson()
                             .Build();

            var wrapper = await this.apiService.InvokeApiAsync <GenericWrapper <CollectionContainer> >(apiRequest);

            return(wrapper.Container);
        }
Пример #3
0
        /// <inheritdoc/>
        public async Task <PlayQueueContainer> CreatePlayQueue(string authToken, string plexServerHost, string hostIdentifier, string type,
                                                               string key, bool isRepeat, bool isShuffle, bool isContinous)
        {
            var uri = "server://" + hostIdentifier + "/com.plexapp.plugins.library/library/metadata/" + key;

            var queryParams =
                new Dictionary <string, string>
            {
                { "continuous", isContinous ? "1" : "0" },
                { "uri", uri },
                { "type", type },
                { "repeat", isRepeat ? "1" : "0" },
                { "shuffle", isShuffle ? "1" : "0" },
                { "own", "1" },
                { "includeChapters", "1" },
                { "includeMarkers", "1" },
                { "includeGeolocation", "1" },
                { "includeExternalMedia", "1" },
            };

            var apiRequest =
                new ApiRequestBuilder(plexServerHost, $"playQueues", HttpMethod.Post)
                .AddPlexToken(authToken)
                .AddQueryParams(queryParams)
                .AddRequestHeaders(ClientUtilities.GetClientIdentifierHeader(this.clientOptions.ClientId))
                .AcceptJson()
                .Build();

            var wrapper = await this.apiService.InvokeApiAsync <GenericWrapper <PlayQueueContainer> >(apiRequest);

            return(wrapper.Container);
        }
Пример #4
0
        /// <inheritdoc/>
        public async Task CancelScanForNewItems(string authToken, string plexServerHost, string key)
        {
            var apiRequest =
                new ApiRequestBuilder(plexServerHost, $"library/sections/{key}/refresh", HttpMethod.Delete)
                .AddPlexToken(authToken)
                .AddRequestHeaders(ClientUtilities.GetClientIdentifierHeader(this.clientOptions.ClientId))
                .AcceptJson()
                .Build();

            await this.apiService.InvokeApiAsync(apiRequest);
        }
Пример #5
0
        /// <inheritdoc/>
        public async Task RefreshContent(string authToken, string plexServerHost)
        {
            var apiRequest =
                new ApiRequestBuilder(plexServerHost, "sync/refreshContent", HttpMethod.Put)
                .AddPlexToken(authToken)
                .AddQueryParams(ClientUtilities.GetClientIdentifierHeader(this.clientOptions.ClientId))
                .AcceptJson()
                .Build();

            await this.apiService.InvokeApiAsync(apiRequest);
        }
Пример #6
0
        /// <inheritdoc/>
        public async Task <LibraryContainer> GetLibrariesAsync(string authToken, string plexServerHost)
        {
            var apiRequest = new ApiRequestBuilder(plexServerHost, "library/sections", HttpMethod.Get)
                             .AddPlexToken(authToken)
                             .AddRequestHeaders(ClientUtilities.GetClientIdentifierHeader(this.clientOptions.ClientId))
                             .AcceptJson()
                             .Build();

            var wrapper = await this.apiService.InvokeApiAsync <GenericWrapper <LibraryContainer> >(apiRequest);

            return(wrapper.Container);
        }
Пример #7
0
        /// <inheritdoc/>
        public async Task <PlexServer> GetPlexServerInfo(string authToken, string plexServerHost)
        {
            var apiRequest = new ApiRequestBuilder(plexServerHost, string.Empty, HttpMethod.Get)
                             .AddPlexToken(authToken)
                             .AddRequestHeaders(ClientUtilities.GetClientIdentifierHeader(this.clientOptions.ClientId))
                             .AcceptJson()
                             .Build();

            var plexMediaContainer = await this.apiService.InvokeApiAsync <PlexServerContainer>(apiRequest);

            return(plexMediaContainer.PlexServer);
        }
Пример #8
0
        /// <inheritdoc/>
        public async Task ScrobbleItemAsync(string authToken, string plexServerHost, string key)
        {
            var apiRequest = new ApiRequestBuilder(
                plexServerHost,
                ":/scrobble?identifier=com.plexapp.plugins.library&key=" + key,
                HttpMethod.Get)
                             .AddPlexToken(authToken)
                             .AddRequestHeaders(ClientUtilities.GetClientIdentifierHeader(this.clientOptions.ClientId))
                             .AcceptJson()
                             .Build();

            await this.apiService.InvokeApiAsync(apiRequest);
        }
Пример #9
0
        /// <inheritdoc/>
        public async Task <int> GetLibrarySize(string authToken, string plexServerHost, string key)
        {
            var apiRequest =
                new ApiRequestBuilder(plexServerHost, $"library/sections/{key}/all", HttpMethod.Get)
                .AddPlexToken(authToken)
                .AddQueryParams(ClientUtilities.GetClientIdentifierHeader(this.clientOptions.ClientId))
                .AcceptJson()
                .Build();

            var wrapper = await this.apiService.InvokeApiAsync <GenericWrapper <MediaContainer> >(apiRequest);

            return(wrapper.Container.Size);
        }
Пример #10
0
        /// <inheritdoc/>
        public async Task ScanForNewItems(string authToken, string plexServerHost, string key,
                                          bool forceMetadataRefresh)
        {
            var apiRequest =
                new ApiRequestBuilder(plexServerHost, $"library/sections/{key}/refresh", HttpMethod.Get)
                .AddPlexToken(authToken)
                .AddQueryParam("force", forceMetadataRefresh ? "1" : "0")
                .AddRequestHeaders(ClientUtilities.GetClientIdentifierHeader(this.clientOptions.ClientId))
                .AcceptJson()
                .Build();

            await this.apiService.InvokeApiAsync(apiRequest);
        }
Пример #11
0
        /// <inheritdoc/>
        public async Task <StatisticContainer> GetStatistics(string authToken, string plexServerHost)
        {
            var apiRequest =
                new ApiRequestBuilder(plexServerHost, "statistics/resources?timespan=6", HttpMethod.Get)
                .AddPlexToken(authToken)
                .AddQueryParam("timespan", "6")
                .AddQueryParams(ClientUtilities.GetClientIdentifierHeader(this.clientOptions.ClientId))
                .AcceptJson()
                .Build();

            var wrapper = await this.apiService.InvokeApiAsync <GenericWrapper <StatisticContainer> >(apiRequest);

            return(wrapper.Container);
        }
Пример #12
0
        /// <inheritdoc/>
        public async Task <MediaContainer> GetCollectionItemMetadataByKey(string authToken, string plexServerHost,
                                                                          string collectionKey)
        {
            var apiRequest =
                new ApiRequestBuilder(plexServerHost, $"library/collections/{collectionKey}/children", HttpMethod.Get)
                .AddPlexToken(authToken)
                .AddRequestHeaders(ClientUtilities.GetClientIdentifierHeader(this.clientOptions.ClientId))
                .AcceptJson()
                .Build();

            var wrapper = await this.apiService.InvokeApiAsync <GenericWrapper <MediaContainer> >(apiRequest);

            return(wrapper.Container);
        }
Пример #13
0
        /// <inheritdoc/>
        public async Task <MediaContainer> GetHomeRecentlyAddedAsync(string authToken, string plexServerHost,
                                                                     int start = 0, int count = 50)
        {
            var apiRequest =
                new ApiRequestBuilder(plexServerHost, $"hubs/home/recentlyAdded", HttpMethod.Get)
                .AddPlexToken(authToken)
                .AddRequestHeaders(ClientUtilities.GetClientIdentifierHeader(this.clientOptions.ClientId))
                .AddRequestHeaders(ClientUtilities.GetClientLimitHeaders(start, count))
                .AcceptJson()
                .Build();

            var wrapper = await this.apiService.InvokeApiAsync <GenericWrapper <MediaContainer> >(apiRequest);

            return(wrapper.Container);
        }
Пример #14
0
        private async Task <T> FetchWithWrapper <T>(string baseUrl, string endpoint, string authToken, HttpMethod method,
                                                    Dictionary <string, string> queryParams = null)
        {
            var apiRequest =
                new ApiRequestBuilder(baseUrl, endpoint, method)
                .AddPlexToken(authToken)
                .AddQueryParams(queryParams)
                .AddQueryParams(ClientUtilities.GetClientIdentifierHeader(this.clientOptions.ClientId))
                .AcceptJson()
                .Build();

            var wrapper = await this.apiService.InvokeApiAsync <GenericWrapper <T> >(apiRequest);

            return(wrapper.Container);
        }
Пример #15
0
        /// <inheritdoc/>
        public async Task <MediaContainer> GetLibraryRecentlyAddedAsync(string authToken, string plexServerHost,
                                                                        SearchType libraryType, string key, int start = 0, int count = 50)
        {
            var apiRequest =
                new ApiRequestBuilder(plexServerHost, $"library/sections/{key}/recentlyAdded", HttpMethod.Get)
                .AddPlexToken(authToken)
                .AddQueryParam("type", ((int)libraryType).ToString())
                .AddRequestHeaders(ClientUtilities.GetClientIdentifierHeader(this.clientOptions.ClientId))
                .AddRequestHeaders(ClientUtilities.GetClientLimitHeaders(start, count))
                .AcceptJson()
                .Build();

            var wrapper = await this.apiService.InvokeApiAsync <GenericWrapper <MediaContainer> >(apiRequest);

            return(wrapper.Container);
        }
Пример #16
0
        /// <inheritdoc/>
        public async Task UpdateCollectionAsync(string authToken, string plexServerHost, string libraryKey,
                                                CollectionModel collectionModel)
        {
            if (authToken == null)
            {
                throw new ArgumentNullException(nameof(authToken));
            }

            if (plexServerHost == null)
            {
                throw new ArgumentNullException(nameof(plexServerHost));
            }

            if (libraryKey == null)
            {
                throw new ArgumentNullException(nameof(libraryKey));
            }

            if (collectionModel == null)
            {
                throw new ArgumentNullException(nameof(collectionModel));
            }

            var apiRequest =
                new ApiRequestBuilder(plexServerHost, "library/sections/" + libraryKey + "/all", HttpMethod.Put)
                .AddPlexToken(authToken)
                .AddRequestHeaders(ClientUtilities.GetClientIdentifierHeader(this.clientOptions.ClientId))
                .AcceptJson()
                .AddQueryParams(new Dictionary <string, string>()
            {
                { "type", "18" },
                { "id", collectionModel.RatingKey },
                { "includeExternalMedia", "1" },
                { "title.value", collectionModel.Title },
                { "titleSort.value", collectionModel.TitleSort },
                { "summary.value", collectionModel.Summary },
                { "contentRating.value", collectionModel.ContentRating },
                { "title.locked", "1" },
                { "titleSort.locked", "1" },
                { "contentRating.locked", "1" },
            })
                .Build();

            await this.apiService.InvokeApiAsync(apiRequest);
        }
Пример #17
0
        /// <inheritdoc/>
        public async Task <CollectionContainer> GetCollectionAsync(string authToken, string plexServerHost,
                                                                   string collectionKey)
        {
            var queryParams =
                new Dictionary <string, string> {
                { "includeCollections", "1" }, { "includeExternalMedia", "true" }
            };

            var apiRequest =
                new ApiRequestBuilder(plexServerHost, "library/collections/" + collectionKey, HttpMethod.Get)
                .AddPlexToken(authToken)
                .AddQueryParams(queryParams)
                .AddRequestHeaders(ClientUtilities.GetClientIdentifierHeader(this.clientOptions.ClientId))
                .AcceptJson()
                .Build();

            var wrapper = await this.apiService.InvokeApiAsync <GenericWrapper <CollectionContainer> >(apiRequest);

            return(wrapper.Container);
        }
Пример #18
0
        /// <inheritdoc/>
        public async Task DeleteCollectionFromLibraryItemAsync(string authToken, string plexServerHost,
                                                               string libraryKey, string ratingKey, string collectionName)
        {
            var apiRequest =
                new ApiRequestBuilder(plexServerHost, "library/sections/" + libraryKey + "/all", HttpMethod.Put)
                .AddPlexToken(authToken)
                .AddQueryParams(ClientUtilities.GetClientIdentifierHeader(this.clientOptions.ClientId))
                .AcceptJson()
                .AddJsonBody(new Dictionary <string, string>()
            {
                { "type", "1" },
                { "id", ratingKey },
                { "includeExternalMedia", "1" },
                { "collection.locked", "1" },
                { "collection[0].tag.tag-", collectionName },
            })
                .Build();

            await this.apiService.InvokeApiAsync(apiRequest);
        }
Пример #19
0
        /// <inheritdoc/>
        public async Task <MediaContainer> LibrarySearch(string authToken, string plexServerHost, string title,
                                                         string libraryKey, string sort, SearchType libraryType, List <FilterRequest> filters = null, int start = 0,
                                                         int count = 100)
        {
            var queryParams = new Dictionary <string, string> {
                { "type", ((int)libraryType).ToString() }
            };

            if (!string.IsNullOrEmpty(title))
            {
                queryParams.Add("title", title);
            }

            if (!string.IsNullOrEmpty(sort))
            {
                queryParams.Add("sort", sort);
            }

            // Include Guids now available PMS v1.24.3.5033
            queryParams.Add("includeGuids", "1");

            var apiRequest =
                new ApiRequestBuilder(plexServerHost, $"library/sections/{libraryKey}/all", HttpMethod.Get)
                .AddPlexToken(authToken)
                .AddQueryParams(queryParams)
                .AddFilterFields(filters)
                .AddQueryParams(ClientUtilities.GetLibraryFlagFields())
                .AddQueryParams(ClientUtilities.GetClientIdentifierHeader(this.clientOptions.ClientId))
                .AddQueryParams(ClientUtilities.GetClientLimitHeaders(start, count))
                .AcceptJson()
                .Build();

            var wrapper = await this.apiService.InvokeApiAsync <GenericWrapper <MediaContainer> >(apiRequest);

            return(wrapper.Container);
        }