Exemple #1
0
        private async Task <Either <BaseError, PlexSeason> > UpdateArtwork(PlexSeason existing, PlexSeason incoming)
        {
            SeasonMetadata existingMetadata = existing.SeasonMetadata.Head();
            SeasonMetadata incomingMetadata = incoming.SeasonMetadata.Head();

            if (incomingMetadata.DateUpdated > existingMetadata.DateUpdated)
            {
                await UpdateArtworkIfNeeded(existingMetadata, incomingMetadata, ArtworkKind.Poster);

                await _metadataRepository.MarkAsUpdated(existingMetadata, incomingMetadata.DateUpdated);
            }

            return(existing);
        }
Exemple #2
0
    private async Task <Either <BaseError, PlexSeason> > UpdateMetadataAndArtwork(
        PlexSeason existing,
        PlexSeason incoming,
        bool deepScan)
    {
        SeasonMetadata existingMetadata = existing.SeasonMetadata.Head();
        SeasonMetadata incomingMetadata = incoming.SeasonMetadata.Head();

        if (existing.Etag != incoming.Etag || deepScan)
        {
            foreach (MetadataGuid guid in existingMetadata.Guids
                     .Filter(g => incomingMetadata.Guids.All(g2 => g2.Guid != g.Guid))
                     .ToList())
            {
                existingMetadata.Guids.Remove(guid);
                await _metadataRepository.RemoveGuid(guid);
            }

            foreach (MetadataGuid guid in incomingMetadata.Guids
                     .Filter(g => existingMetadata.Guids.All(g2 => g2.Guid != g.Guid))
                     .ToList())
            {
                existingMetadata.Guids.Add(guid);
                await _metadataRepository.AddGuid(existingMetadata, guid);
            }

            foreach (Tag tag in existingMetadata.Tags
                     .Filter(g => incomingMetadata.Tags.All(g2 => g2.Name != g.Name))
                     .ToList())
            {
                existingMetadata.Tags.Remove(tag);
                await _metadataRepository.RemoveTag(tag);
            }

            foreach (Tag tag in incomingMetadata.Tags
                     .Filter(g => existingMetadata.Tags.All(g2 => g2.Name != g.Name))
                     .ToList())
            {
                existingMetadata.Tags.Add(tag);
                await _televisionRepository.AddTag(existingMetadata, tag);
            }

            await UpdateArtworkIfNeeded(existingMetadata, incomingMetadata, ArtworkKind.Poster);

            await _metadataRepository.MarkAsUpdated(existingMetadata, incomingMetadata.DateUpdated);
        }

        return(existing);
    }
        private async Task <Either <BaseError, Season> > UpdatePoster(Season season, string seasonFolder)
        {
            try
            {
                await LocatePoster(season, seasonFolder).IfSomeAsync(
                    async posterFile =>
                {
                    SeasonMetadata metadata = season.SeasonMetadata.Head();
                    await RefreshArtwork(posterFile, metadata, ArtworkKind.Poster);
                });

                return(season);
            }
            catch (Exception ex)
            {
                return(BaseError.New(ex.ToString()));
            }
        }
    private async Task <Either <BaseError, Season> > EnsureMetadataExists(Season season)
    {
        season.SeasonMetadata ??= new List <SeasonMetadata>();

        if (!season.SeasonMetadata.Any())
        {
            var metadata = new SeasonMetadata
            {
                SeasonId  = season.Id,
                Season    = season,
                DateAdded = DateTime.UtcNow,
                Guids     = new List <MetadataGuid>(),
                Tags      = new List <Tag>()
            };

            season.SeasonMetadata.Add(metadata);
            await _metadataRepository.Add(metadata);
        }

        return(season);
    }
    private async Task <Either <BaseError, Season> > UpdatePoster(
        Season season,
        string seasonFolder,
        CancellationToken cancellationToken)
    {
        try
        {
            Option <string> maybePoster = LocatePoster(season, seasonFolder);
            foreach (string posterFile in maybePoster)
            {
                SeasonMetadata metadata = season.SeasonMetadata.Head();
                await RefreshArtwork(posterFile, metadata, ArtworkKind.Poster, None, None, cancellationToken);
            }

            return(season);
        }
        catch (Exception ex)
        {
            _client.Notify(ex);
            return(BaseError.New(ex.ToString()));
        }
    }
Exemple #6
0
    private async Task UpdateSeason(ISearchRepository searchRepository, Season season)
    {
        Option <SeasonMetadata> maybeMetadata     = season.SeasonMetadata.HeadOrNone();
        Option <ShowMetadata>   maybeShowMetadata = season.Show.ShowMetadata.HeadOrNone();

        if (maybeMetadata.IsSome && maybeShowMetadata.IsSome)
        {
            SeasonMetadata metadata     = maybeMetadata.ValueUnsafe();
            ShowMetadata   showMetadata = maybeShowMetadata.ValueUnsafe();

            try
            {
                string seasonTitle = $"{showMetadata.Title} - S{season.SeasonNumber}";
                string sortTitle   = $"{showMetadata.SortTitle}_{season.SeasonNumber:0000}"
                                     .ToLowerInvariant();
                string titleAndYear = $"{showMetadata.Title}_{showMetadata.Year}_{season.SeasonNumber}"
                                      .ToLowerInvariant();

                var doc = new Document
                {
                    new StringField(IdField, season.Id.ToString(), Field.Store.YES),
                    new StringField(TypeField, SeasonType, Field.Store.YES),
                    new TextField(TitleField, seasonTitle, Field.Store.NO),
                    new StringField(SortTitleField, sortTitle, Field.Store.NO),
                    new TextField(LibraryNameField, season.LibraryPath.Library.Name, Field.Store.NO),
                    new StringField(LibraryIdField, season.LibraryPath.Library.Id.ToString(), Field.Store.NO),
                    new StringField(TitleAndYearField, titleAndYear, Field.Store.NO),
                    new StringField(JumpLetterField, GetJumpLetter(showMetadata), Field.Store.YES)
                };

                List <string> languages = await searchRepository.GetLanguagesForSeason(season);
                await AddLanguages(searchRepository, doc, languages);

                if (!string.IsNullOrWhiteSpace(showMetadata.ContentRating))
                {
                    foreach (string contentRating in (showMetadata.ContentRating ?? string.Empty).Split("/")
                             .Map(x => x.Trim()).Where(x => !string.IsNullOrWhiteSpace(x)))
                    {
                        doc.Add(new StringField(ContentRatingField, contentRating, Field.Store.NO));
                    }
                }

                if (metadata.ReleaseDate.HasValue)
                {
                    doc.Add(
                        new StringField(
                            ReleaseDateField,
                            metadata.ReleaseDate.Value.ToString("yyyyMMdd"),
                            Field.Store.NO));
                }

                doc.Add(new StringField(AddedDateField, metadata.DateAdded.ToString("yyyyMMdd"), Field.Store.NO));

                foreach (TraktListItem item in season.TraktListItems)
                {
                    doc.Add(new StringField(TraktListField, item.TraktList.TraktId.ToString(), Field.Store.NO));
                }

                foreach (Tag tag in metadata.Tags)
                {
                    doc.Add(new TextField(TagField, tag.Name, Field.Store.NO));
                }

                _writer.UpdateDocument(new Term(IdField, season.Id.ToString()), doc);
            }
            catch (Exception ex)
            {
                metadata.Season = null;
                _logger.LogWarning(ex, "Error indexing show with metadata {@Metadata}", metadata);
            }
        }
    }