Example #1
0
 public async Task <PlexMediaItemRow> GetExistingMediaItemByAgent(PlexMediaTypes mediaType, AgentTypes agentType, string agentSourceId)
 {
     return(await _plexMediaRepository.GetOne(x =>
                                              x.MediaType == mediaType &&
                                              x.AgentType == agentType &&
                                              x.AgentSourceId == agentSourceId));
 }
Example #2
0
        private async Task AutoCompleteRequests(SyncResult syncResult, PlexMediaTypes syncProcessorType)
        {
            var plexKeysByAgentType = syncResult.NewItems.Concat(syncResult.ExistingItems)
                                      .ToDictionary(x => new MediaAgent(x.AgentType, x.AgentSourceId),
                                                    x => x);

            await _completionService.AutoCompleteRequests(plexKeysByAgentType, syncProcessorType);
        }
Example #3
0
 private void Creates_Issue_Successfully(PlexMediaTypes mediaType)
 {
     this.Given(x => x.GivenACommand())
     .Given(x => x.GivenAMediaType(mediaType))
     .Given(x => x.GivenMediaItemIsReturned())
     .Given(x => x.GivenAnIssueIsCreated())
     .Given(x => x.GivenUserDetailsFromClaims())
     .When(x => x.WhenCommandActionIsCreated())
     .Then(x => x.ThenIssueIsCreated())
     .Then(x => x.ThenChangesAreCommitted())
     .BDDfy();
 }
 public MoviePlexMediaItemRowBuilder()
 {
     _plexMediaItemId = new Random().Next(1, int.MaxValue);
     _identifier      = Guid.NewGuid();
     _key             = new Random().Next(1, int.MaxValue);
     _title           = Guid.NewGuid().ToString();
     _agentType       = AgentTypes.TheMovieDb;
     _agentSourceId   = "447109";
     _mediaUri        = Guid.NewGuid().ToString();
     _year            = DateTime.UtcNow.Year;
     _mediaType       = PlexMediaTypes.Movie;
     _resolution      = Guid.NewGuid().ToString();
 }
Example #5
0
        public async Task AutoCompleteRequests(Dictionary <MediaAgent, PlexMediaItemRow> agentsByPlexId,
                                               PlexMediaTypes mediaType)
        {
            var completer = _autoCompleters.FirstOrDefault(x => x.MediaType == mediaType);

            if (completer == null)
            {
                _logger.LogError($"Attempt to execute auto completion on PlexMediaType '{mediaType}' that has no configured auto complete implementation.");
                return;
            }

            await completer.AutoComplete(agentsByPlexId);
        }
Example #6
0
        private void WhenGetMediaItemActionIsCreated(bool isExistingMediaItem)
        {
            _mediaType  = PlexMediaTypes.Show;
            _localMedia = new MoviePlexMediaItemRowBuilder().CreateMany();
            var authToken         = Guid.NewGuid().ToString();
            var plexUri           = Guid.NewGuid().ToString();
            var machineIdentifier = Guid.NewGuid().ToString();
            var plexUriFormat     = Guid.NewGuid().ToString();

            if (isExistingMediaItem)
            {
                var matchingMediaItem = _localMedia.First();
                matchingMediaItem.MediaItemKey = _ratingKey;
                matchingMediaItem.MediaType    = _mediaType;
            }

            _getMediaItemAction = async() => await _underTest.GetMediaItem(_ratingKey, _mediaType, _localMedia, authToken, plexUri, machineIdentifier, plexUriFormat);
        }
        public async Task <MediaItemResult> GetMediaItem(int ratingKey, PlexMediaTypes mediaType, List <PlexMediaItemRow> localMedia, string authToken, string plexUri, string machineIdentifier, string plexUriFormat)
        {
            var metadata = await TryGetPlexMetadata(ratingKey, authToken, plexUri);

            if (metadata == null)
            {
                return(null);
            }

            var mediaItem = localMedia.FirstOrDefault(x => x.MediaItemKey == ratingKey);
            var isNewItem = false;

            if (mediaItem == null)
            {
                mediaItem = new PlexMediaItemRow
                {
                    Identifier   = Guid.NewGuid(),
                    MediaItemKey = ratingKey,
                    MediaType    = mediaType,
                    Title        = metadata.Title,
                    Year         = metadata.Year
                };
                isNewItem = true;
            }

            mediaItem.Resolution = metadata.Media?.FirstOrDefault()?.VideoResolution;

            var agentResult = _agentGuidParser.TryGetAgentDetails(metadata.Guid);

            if (agentResult == null)
            {
                return(null);
            }

            mediaItem.AgentType     = agentResult.AgentType;
            mediaItem.AgentSourceId = agentResult.AgentSourceId;

            mediaItem.MediaUri = PlexHelper.GenerateMediaItemUri(plexUriFormat, machineIdentifier, ratingKey);

            return(new MediaItemResult(isNewItem, mediaItem));
        }
        private async Task <PlexMediaItemRow> GetPlexMediaItem(int theMovieDbId, PlexMediaTypes mediaType)
        {
            var plexMediaItem = await _plexService.GetExistingMediaItemByAgent(mediaType, AgentTypes.TheMovieDb, theMovieDbId.ToString());

            return(plexMediaItem);
        }
Example #9
0
 private void GivenAMediaType(PlexMediaTypes mediaType)
 {
     _command.MediaType = mediaType;
 }
Example #10
0
 public async Task <List <PlexMediaItemRow> > GetMediaItems(PlexMediaTypes mediaType)
 {
     return(await _plexMediaRepository.GetMany(x => x.MediaType == mediaType));
 }