예제 #1
0
        /// <summary>Adds a <see cref="TraktEpisode" />, which will be added to the collection post.</summary>
        /// <param name="episode">The Trakt episode, which will be added.</param>
        /// <param name="metadata">An <see cref="TraktMetadata" /> instance, containing metadata about the given episode.</param>
        /// <param name="collectedAt">The datetime, when the given episode was collected. Will be converted to the Trakt UTC-datetime and -format.</param>
        /// <returns>The current <see cref="TraktSyncCollectionPostBuilder" /> instance.</returns>
        /// <exception cref="ArgumentNullException">
        /// Thrown, if the given episode is null.
        /// Thrown, if the given episode ids are null.
        /// </exception>
        /// <exception cref="ArgumentException">Thrown, if the given episode has no valid ids set.</exception>
        public TraktSyncCollectionPostBuilder AddEpisode(TraktEpisode episode, TraktMetadata metadata, DateTime collectedAt)
        {
            ValidateEpisode(episode);
            EnsureEpisodesListExists();

            return(AddEpisodeOrIgnore(episode, metadata, collectedAt));
        }
예제 #2
0
 public static bool IsEmpty(this TraktMetadata metadata)
 {
     return(string.IsNullOrEmpty(metadata.media_type) &&
            string.IsNullOrEmpty(metadata.resolution) &&
            string.IsNullOrEmpty(metadata.audio) &&
            string.IsNullOrEmpty(metadata.audio_channels));
 }
예제 #3
0
        private void CreateOrSetShow(TraktShow show, IEnumerable <TraktSyncCollectionPostShowSeason> showSeasons,
                                     TraktMetadata metadata = null, DateTime?collectedAt = null)
        {
            var existingShow = _collectionPost.Shows.Where(s => s.Ids == show.Ids).FirstOrDefault();

            if (existingShow != null)
            {
                existingShow.Seasons = showSeasons;
            }
            else
            {
                var collectionShow = new TraktSyncCollectionPostShow();
                collectionShow.Ids   = show.Ids;
                collectionShow.Title = show.Title;
                collectionShow.Year  = show.Year;

                if (metadata != null)
                {
                    collectionShow.Metadata = metadata;
                }

                if (collectedAt.HasValue)
                {
                    collectionShow.CollectedAt = collectedAt.Value.ToUniversalTime();
                }

                collectionShow.Seasons = showSeasons;
                (_collectionPost.Shows as List <TraktSyncCollectionPostShow>).Add(collectionShow);
            }
        }
예제 #4
0
        /// <summary>Adds a <see cref="TraktMovie" />, which will be added to the collection post.</summary>
        /// <param name="movie">The Trakt movie, which will be added.</param>
        /// <param name="metadata">An <see cref="TraktMetadata" /> instance, containing metadata about the given movie.</param>
        /// <param name="collectedAt">The datetime, when the given movie was collected. Will be converted to the Trakt UTC-datetime and -format.</param>
        /// <returns>The current <see cref="TraktSyncCollectionPostBuilder" /> instance.</returns>
        /// <exception cref="ArgumentNullException">
        /// Thrown, if the given movie is null.
        /// Thrown, if the given movie ids are null.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// Thrown, if the given movie has no valid ids set.
        /// Thrown, if the given movie has an year set, which has more or less than four digits.
        /// </exception>
        public TraktSyncCollectionPostBuilder AddMovie(TraktMovie movie, TraktMetadata metadata, DateTime collectedAt)
        {
            ValidateMovie(movie);
            EnsureMoviesListExists();

            return(AddMovieOrIgnore(movie, metadata, collectedAt));
        }
예제 #5
0
        private TraktSyncCollectionPostBuilder AddShowOrIgnore(TraktShow show, TraktMetadata metadata = null,
                                                               DateTime?collectedAt = null)
        {
            if (ContainsShow(show))
            {
                return(this);
            }

            var collectionShow = new TraktSyncCollectionPostShow();

            collectionShow.Ids   = show.Ids;
            collectionShow.Title = show.Title;
            collectionShow.Year  = show.Year;

            if (metadata != null)
            {
                collectionShow.Metadata = metadata;
            }

            if (collectedAt.HasValue)
            {
                collectionShow.CollectedAt = collectedAt.Value.ToUniversalTime();
            }

            (_collectionPost.Shows as List <TraktSyncCollectionPostShow>).Add(collectionShow);

            return(this);
        }
 public async Task Test_MetadataObjectJsonWriter_WriteObject_StringWriter_Exceptions()
 {
     var                   traktJsonWriter = new MetadataObjectJsonWriter();
     ITraktMetadata        traktMetadata   = new TraktMetadata();
     Func <Task <string> > action          = () => traktJsonWriter.WriteObjectAsync(default(StringWriter), traktMetadata);
     await action.Should().ThrowAsync <ArgumentNullException>();
 }
예제 #7
0
 public static bool IsEmpty(this TraktMetadata metadata)
 {
     return(string.IsNullOrEmpty(metadata.MediaType) &&
            string.IsNullOrEmpty(metadata.Resolution) &&
            string.IsNullOrEmpty(metadata.Audio) &&
            string.IsNullOrEmpty(metadata.AudioChannels));
 }
예제 #8
0
        /// <summary>Adds a <see cref="TraktShow" />, which will be added to the collection post.</summary>
        /// <param name="show">The Trakt show, which will be added.</param>
        /// <param name="metadata">An <see cref="TraktMetadata" /> instance, containing metadata about the given show.</param>
        /// <param name="collectedAt">The datetime, when the given show was collected. Will be converted to the Trakt UTC-datetime and -format.</param>
        /// <returns>The current <see cref="TraktSyncCollectionPostBuilder" /> instance.</returns>
        /// <exception cref="ArgumentNullException">
        /// Thrown, if the given show is null.
        /// Thrown, if the given show ids are null.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// Thrown, if the given show has no valid ids set.
        /// Thrown, if the given show has an year set, which has more or less than four digits.
        /// </exception>
        public TraktSyncCollectionPostBuilder AddShow(TraktShow show, TraktMetadata metadata, DateTime collectedAt)
        {
            ValidateShow(show);
            EnsureShowsListExists();

            return(AddShowOrIgnore(show, metadata, collectedAt));
        }
예제 #9
0
        private TraktSyncCollectionPostBuilder AddMovieOrIgnore(TraktMovie movie, TraktMetadata metadata = null,
                                                                DateTime?collectedAt = null)
        {
            if (ContainsMovie(movie))
            {
                return(this);
            }

            var collectionMovie = new TraktSyncCollectionPostMovie();

            collectionMovie.Ids   = movie.Ids;
            collectionMovie.Title = movie.Title;
            collectionMovie.Year  = movie.Year;

            if (metadata != null)
            {
                collectionMovie.Metadata = metadata;
            }

            if (collectedAt.HasValue)
            {
                collectionMovie.CollectedAt = collectedAt.Value.ToUniversalTime();
            }

            (_collectionPost.Movies as List <TraktSyncCollectionPostMovie>).Add(collectionMovie);

            return(this);
        }
        public void Test_MetadataObjectJsonWriter_WriteObject_JsonWriter_Exceptions()
        {
            var            traktJsonWriter = new MetadataObjectJsonWriter();
            ITraktMetadata traktMetadata   = new TraktMetadata();
            Func <Task>    action          = () => traktJsonWriter.WriteObjectAsync(default(JsonTextWriter), traktMetadata);

            action.Should().Throw <ArgumentNullException>();
        }
예제 #11
0
        public override async Task <ITraktMetadata> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default)
        {
            CheckJsonTextReader(jsonReader);

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject)
            {
                ITraktMetadata traktMetadata = new TraktMetadata();

                while (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.PropertyName)
                {
                    var propertyName = jsonReader.Value.ToString();

                    switch (propertyName)
                    {
                    case JsonProperties.PROPERTY_NAME_MEDIA_TYPE:
                        traktMetadata.MediaType = await JsonReaderHelper.ReadEnumerationValueAsync <TraktMediaType>(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_RESOLUTION:
                        traktMetadata.MediaResolution = await JsonReaderHelper.ReadEnumerationValueAsync <TraktMediaResolution>(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_AUDIO:
                        traktMetadata.Audio = await JsonReaderHelper.ReadEnumerationValueAsync <TraktMediaAudio>(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_AUDIO_CHANNELS:
                        traktMetadata.AudioChannels = await JsonReaderHelper.ReadEnumerationValueAsync <TraktMediaAudioChannel>(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_HDR:
                        traktMetadata.HDR = await JsonReaderHelper.ReadEnumerationValueAsync <TraktMediaHDR>(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_3D:
                        traktMetadata.ThreeDimensional = await jsonReader.ReadAsBooleanAsync(cancellationToken);

                        break;

                    default:
                        await JsonReaderHelper.ReadAndIgnoreInvalidContentAsync(jsonReader, cancellationToken);

                        break;
                    }
                }

                return(traktMetadata);
            }

            return(await Task.FromResult(default(ITraktMetadata)));
        }
예제 #12
0
        public void Test_TraktMetadata_Default_Constructor()
        {
            var traktMetadata = new TraktMetadata();

            traktMetadata.MediaType.Should().BeNull();
            traktMetadata.MediaResolution.Should().BeNull();
            traktMetadata.Audio.Should().BeNull();
            traktMetadata.AudioChannels.Should().BeNull();
            traktMetadata.ThreeDimensional.Should().BeNull();
        }
예제 #13
0
        /// <summary>Adds a <see cref="TraktShow" />, which will be added to the collection post.</summary>
        /// <param name="show">The Trakt show, which will be added.</param>
        /// <param name="metadata">An <see cref="TraktMetadata" /> instance, containing metadata about the given show.</param>
        /// <param name="collectedAt">The datetime, when the given show was collected. Will be converted to the Trakt UTC-datetime and -format.</param>
        /// <param name="seasons">
        /// An array of season numbers for seasons in the given show.
        /// All seasons numbers will be added to the collection.
        /// </param>
        /// <returns>The current <see cref="TraktSyncCollectionPostBuilder" /> instance.</returns>
        /// <exception cref="ArgumentNullException">
        /// Thrown, if the given show is null.
        /// Thrown, if the given show ids are null.
        /// Thrown, if the given seasons array is null.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// Thrown, if the given show has no valid ids set.
        /// Thrown, if the given show has an year set, which has more or less than four digits.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// Thrown, if at least one of the given season numbers is below zero.
        /// </exception>
        public TraktSyncCollectionPostBuilder AddShow(TraktShow show, TraktMetadata metadata, DateTime collectedAt, int[] seasons)
        {
            ValidateShow(show);
            EnsureShowsListExists();

            var showSeasons = CreateShowSeasons(seasons);

            CreateOrSetShow(show, showSeasons, metadata, collectedAt);

            return(this);
        }
예제 #14
0
        public async Task Test_MetadataObjectJsonWriter_WriteObject_Object_Only_MediaType_Property()
        {
            ITraktMetadata traktMetadata = new TraktMetadata
            {
                MediaType = TraktMediaType.Digital
            };

            var    traktJsonWriter = new MetadataObjectJsonWriter();
            string json            = await traktJsonWriter.WriteObjectAsync(traktMetadata);

            json.Should().Be(@"{""media_type"":""digital""}");
        }
예제 #15
0
        public async Task Test_MetadataObjectJsonWriter_WriteObject_Object_Only_Audio_Property()
        {
            ITraktMetadata traktMetadata = new TraktMetadata
            {
                Audio = TraktMediaAudio.DolbyAtmos
            };

            var    traktJsonWriter = new MetadataObjectJsonWriter();
            string json            = await traktJsonWriter.WriteObjectAsync(traktMetadata);

            json.Should().Be(@"{""audio"":""dolby_atmos""}");
        }
예제 #16
0
        public async Task Test_MetadataObjectJsonWriter_WriteObject_Object_Only_MediaResolution_Property()
        {
            ITraktMetadata traktMetadata = new TraktMetadata
            {
                MediaResolution = TraktMediaResolution.UHD_4k
            };

            var    traktJsonWriter = new MetadataObjectJsonWriter();
            string json            = await traktJsonWriter.WriteObjectAsync(traktMetadata);

            json.Should().Be(@"{""resolution"":""uhd_4k""}");
        }
예제 #17
0
        public async Task Test_MetadataObjectJsonWriter_WriteObject_Object_Only_ThreeDimensional_Property()
        {
            ITraktMetadata traktMetadata = new TraktMetadata
            {
                ThreeDimensional = true
            };

            var    traktJsonWriter = new MetadataObjectJsonWriter();
            string json            = await traktJsonWriter.WriteObjectAsync(traktMetadata);

            json.Should().Be(@"{""3d"":true}");
        }
예제 #18
0
        public async Task Test_MetadataObjectJsonWriter_WriteObject_Object_Only_AudioChannels_Property()
        {
            ITraktMetadata traktMetadata = new TraktMetadata
            {
                AudioChannels = TraktMediaAudioChannel.Channels_7_1
            };

            var    traktJsonWriter = new MetadataObjectJsonWriter();
            string json            = await traktJsonWriter.WriteObjectAsync(traktMetadata);

            json.Should().Be(@"{""audio_channels"":""7.1""}");
        }
예제 #19
0
        private ITraktSyncCollectionPost GetCollectedShowsForSync(IList <MediaItem> localCollectedEpisodes, IEnumerable <EpisodeCollected> traktEpisodesCollected)
        {
            _mediaPortalServices.GetLogger().Info("Trakt: finding local episodes to add to trakt collection");
            TraktSyncCollectionPostBuilder     builder        = new TraktSyncCollectionPostBuilder();
            ILookup <string, EpisodeCollected> onlineEpisodes = traktEpisodesCollected.ToLookup(tce => CreateLookupKey(tce), tce => tce);

            foreach (var episode in localCollectedEpisodes)
            {
                string           tvdbKey      = CreateLookupKey(episode);
                EpisodeCollected traktEpisode = onlineEpisodes[tvdbKey].FirstOrDefault();

                if (traktEpisode == null)
                {
                    TraktShow show = new TraktShow
                    {
                        Title = MediaItemAspectsUtl.GetSeriesTitle(episode),
                        Ids   = new TraktShowIds
                        {
                            Tvdb = MediaItemAspectsUtl.GetTvdbId(episode),
                            Imdb = MediaItemAspectsUtl.GetSeriesImdbId(episode)
                        }
                    };

                    TraktMetadata metadata = new TraktMetadata
                    {
                        Audio            = MediaItemAspectsUtl.GetVideoAudioCodec(episode),
                        AudioChannels    = MediaItemAspectsUtl.GetVideoAudioChannel(episode),
                        MediaResolution  = MediaItemAspectsUtl.GetVideoResolution(episode),
                        MediaType        = MediaItemAspectsUtl.GetVideoMediaType(episode),
                        ThreeDimensional = false
                    };

                    DateTime collectedAt = MediaItemAspectsUtl.GetDateAddedToDb(episode);

                    builder.AddShow(show,
                                    new PostSeasons
                    {
                        {
                            MediaItemAspectsUtl.GetSeasonIndex(episode),
                            new PostEpisodes
                            {
                                { MediaItemAspectsUtl.GetEpisodeIndex(episode), metadata, collectedAt }
                            }
                        }
                    });
                }
            }
            return(builder.Build());
        }
        public async Task Test_MetadataObjectJsonWriter_WriteObject_StringWriter_Only_HDR_Property()
        {
            ITraktMetadata traktMetadata = new TraktMetadata
            {
                HDR = TraktMediaHDR.DolbyVision
            };

            using (var stringWriter = new StringWriter())
            {
                var    traktJsonWriter = new MetadataObjectJsonWriter();
                string json            = await traktJsonWriter.WriteObjectAsync(stringWriter, traktMetadata);

                json.Should().Be(@"{""hdr"":""dolby_vision""}");
            }
        }
예제 #21
0
        public async Task Test_MetadataObjectJsonWriter_WriteObject_JsonWriter_Only_MediaType_Property()
        {
            ITraktMetadata traktMetadata = new TraktMetadata
            {
                MediaType = TraktMediaType.Digital
            };

            using (var stringWriter = new StringWriter())
                using (var jsonWriter = new JsonTextWriter(stringWriter))
                {
                    var traktJsonWriter = new MetadataObjectJsonWriter();
                    await traktJsonWriter.WriteObjectAsync(jsonWriter, traktMetadata);

                    stringWriter.ToString().Should().Be(@"{""media_type"":""digital""}");
                }
        }
예제 #22
0
        public async Task Test_MetadataObjectJsonWriter_WriteObject_JsonWriter_Only_AudioChannels_Property()
        {
            ITraktMetadata traktMetadata = new TraktMetadata
            {
                AudioChannels = TraktMediaAudioChannel.Channels_7_1
            };

            using (var stringWriter = new StringWriter())
                using (var jsonWriter = new JsonTextWriter(stringWriter))
                {
                    var traktJsonWriter = new MetadataObjectJsonWriter();
                    await traktJsonWriter.WriteObjectAsync(jsonWriter, traktMetadata);

                    stringWriter.ToString().Should().Be(@"{""audio_channels"":""7.1""}");
                }
        }
예제 #23
0
        public async Task Test_MetadataObjectJsonWriter_WriteObject_JsonWriter_Only_MediaResolution_Property()
        {
            ITraktMetadata traktMetadata = new TraktMetadata
            {
                MediaResolution = TraktMediaResolution.UHD_4k
            };

            using (var stringWriter = new StringWriter())
                using (var jsonWriter = new JsonTextWriter(stringWriter))
                {
                    var traktJsonWriter = new MetadataObjectJsonWriter();
                    await traktJsonWriter.WriteObjectAsync(jsonWriter, traktMetadata);

                    stringWriter.ToString().Should().Be(@"{""resolution"":""uhd_4k""}");
                }
        }
예제 #24
0
        public async Task Test_MetadataObjectJsonWriter_WriteObject_JsonWriter_Only_Audio_Property()
        {
            ITraktMetadata traktMetadata = new TraktMetadata
            {
                Audio = TraktMediaAudio.DolbyAtmos
            };

            using (var stringWriter = new StringWriter())
                using (var jsonWriter = new JsonTextWriter(stringWriter))
                {
                    var traktJsonWriter = new MetadataObjectJsonWriter();
                    await traktJsonWriter.WriteObjectAsync(jsonWriter, traktMetadata);

                    stringWriter.ToString().Should().Be(@"{""audio"":""dolby_atmos""}");
                }
        }
예제 #25
0
        public async Task Test_MetadataObjectJsonWriter_WriteObject_JsonWriter_Only_ThreeDimensional_Property()
        {
            ITraktMetadata traktMetadata = new TraktMetadata
            {
                ThreeDimensional = true
            };

            using (var stringWriter = new StringWriter())
                using (var jsonWriter = new JsonTextWriter(stringWriter))
                {
                    var traktJsonWriter = new MetadataObjectJsonWriter();
                    await traktJsonWriter.WriteObjectAsync(jsonWriter, traktMetadata);

                    stringWriter.ToString().Should().Be(@"{""3d"":true}");
                }
        }
예제 #26
0
        /// <summary>Adds a <see cref="TraktShow" />, which will be added to the collection post.</summary>
        /// <param name="show">The Trakt show, which will be added.</param>
        /// <param name="metadata">An <see cref="TraktMetadata" /> instance, containing metadata about the given show.</param>
        /// <param name="collectedAt">The datetime, when the given show was collected. Will be converted to the Trakt UTC-datetime and -format.</param>
        /// <param name="seasons">
        /// An <see cref="PostSeasons" /> instance, containing season and episode numbers.<para />
        /// If it contains episode numbers, only the episodes with the given episode numbers will be added to the collection.
        /// </param>
        /// <returns>The current <see cref="TraktSyncCollectionPostBuilder" /> instance.</returns>
        /// <exception cref="ArgumentNullException">
        /// Thrown, if the given show is null.
        /// Thrown, if the given show ids are null.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// Thrown, if the given show has no valid ids set.
        /// Thrown, if the given show has an year set, which has more or less than four digits.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// Thrown, if at least one of the given season numbers in <paramref name="seasons" /> is below zero.
        /// Thrown, if at least one of the given episode numbers in <paramref name="seasons" /> is below zero.
        /// </exception>
        public TraktSyncCollectionPostBuilder AddShow(TraktShow show, TraktMetadata metadata, DateTime collectedAt, PostSeasons seasons)
        {
            ValidateShow(show);

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

            EnsureShowsListExists();

            var showSeasons = CreateShowSeasons(seasons);

            CreateOrSetShow(show, showSeasons, metadata, collectedAt);

            return(this);
        }
예제 #27
0
        public async Task Test_MetadataObjectJsonWriter_WriteObject_Object_Complete()
        {
            ITraktMetadata traktMetadata = new TraktMetadata
            {
                MediaType        = TraktMediaType.Digital,
                MediaResolution  = TraktMediaResolution.UHD_4k,
                Audio            = TraktMediaAudio.DolbyAtmos,
                AudioChannels    = TraktMediaAudioChannel.Channels_7_1,
                ThreeDimensional = true
            };

            var    traktJsonWriter = new MetadataObjectJsonWriter();
            string json            = await traktJsonWriter.WriteObjectAsync(traktMetadata);

            json.Should().Be(@"{""media_type"":""digital"",""resolution"":""uhd_4k"",""audio"":""dolby_atmos""," +
                             @"""audio_channels"":""7.1"",""3d"":true}");
        }
예제 #28
0
        public async Task Test_MetadataObjectJsonWriter_WriteObject_JsonWriter_Complete()
        {
            ITraktMetadata traktMetadata = new TraktMetadata
            {
                MediaType        = TraktMediaType.Digital,
                MediaResolution  = TraktMediaResolution.UHD_4k,
                Audio            = TraktMediaAudio.DolbyAtmos,
                AudioChannels    = TraktMediaAudioChannel.Channels_7_1,
                HDR              = TraktMediaHDR.DolbyVision,
                ThreeDimensional = true
            };

            using (var stringWriter = new StringWriter())
                using (var jsonWriter = new JsonTextWriter(stringWriter))
                {
                    var traktJsonWriter = new MetadataObjectJsonWriter();
                    await traktJsonWriter.WriteObjectAsync(jsonWriter, traktMetadata);

                    stringWriter.ToString().Should().Be(@"{""media_type"":""digital"",""resolution"":""uhd_4k"",""audio"":""dolby_atmos""," +
                                                        @"""audio_channels"":""7.1"",""3d"":true,""hdr"":""dolby_vision""}");
                }
        }
예제 #29
0
        private TraktSyncCollectionPostBuilder AddEpisodeOrIgnore(TraktEpisode episode, TraktMetadata metadata = null,
                                                                  DateTime?collectedAt = null)
        {
            if (ContainsEpisode(episode))
            {
                return(this);
            }

            var collectionEpisode = new TraktSyncCollectionPostEpisode();

            collectionEpisode.Ids = episode.Ids;

            if (metadata != null)
            {
                collectionEpisode.Metadata = metadata;
            }

            if (collectedAt.HasValue)
            {
                collectionEpisode.CollectedAt = collectedAt.Value.ToUniversalTime();
            }

            (_collectionPost.Episodes as List <TraktSyncCollectionPostEpisode>).Add(collectionEpisode);

            return(this);
        }