예제 #1
0
        public override bool FromMetadata(IDictionary <Guid, IList <MediaItemAspect> > aspectData)
        {
            bool success = false;

            GetMetadataChanged(aspectData);

            if (aspectData.ContainsKey(AudioAlbumAspect.ASPECT_ID))
            {
                MediaItemAspect.TryGetAttribute(aspectData, AudioAlbumAspect.ATTR_ALBUM, out Album);
                MediaItemAspect.TryGetAttribute(aspectData, MediaAspect.ATTR_SORT_TITLE, out AlbumSort);
                MediaItemAspect.TryGetAttribute(aspectData, AudioAlbumAspect.ATTR_DISCID, out DiscNum);
                MediaItemAspect.TryGetAttribute(aspectData, AudioAlbumAspect.ATTR_NUMDISCS, out TotalDiscs);
                MediaItemAspect.TryGetAttribute(aspectData, AudioAlbumAspect.ATTR_NUMTRACKS, out TotalTracks);
                MediaItemAspect.TryGetAttribute(aspectData, AudioAlbumAspect.ATTR_COMPILATION, out Compilation);
                MediaItemAspect.TryGetAttribute(aspectData, MediaAspect.ATTR_RECORDINGTIME, out ReleaseDate);
                MediaItemAspect.TryGetAttribute(aspectData, AudioAlbumAspect.ATTR_SALES, out Sales);

                string tempString;
                MediaItemAspect.TryGetAttribute(aspectData, AudioAlbumAspect.ATTR_DESCRIPTION, out tempString);
                Description = new SimpleTitle(tempString, string.IsNullOrWhiteSpace(tempString));

                double?rating;
                MediaItemAspect.TryGetAttribute(aspectData, AudioAlbumAspect.ATTR_TOTAL_RATING, out rating);
                int?voteCount;
                MediaItemAspect.TryGetAttribute(aspectData, AudioAlbumAspect.ATTR_RATING_COUNT, out voteCount);
                Rating = new SimpleRating(rating, voteCount);

                //Brownard 17.06.2016
                //The returned type of the collection differs on the server and client.
                //On the server it's an object collection but on the client it's a string collection due to [de]serialization.
                //Use the non generic Ienumerable to allow for both types.
                IEnumerable collection;
                Artists.Clear();
                if (MediaItemAspect.TryGetAttribute(aspectData, AudioAlbumAspect.ATTR_ARTISTS, out collection))
                {
                    Artists.AddRange(collection.Cast <string>().Select(s => new PersonInfo {
                        Name = s, Occupation = PersonAspect.OCCUPATION_ARTIST, ParentMediaName = Album
                    }));
                }
                foreach (PersonInfo artist in Artists)
                {
                    artist.AssignNameId();
                }

                Awards.Clear();
                if (MediaItemAspect.TryGetAttribute(aspectData, AudioAlbumAspect.ATTR_AWARDS, out collection))
                {
                    Awards.AddRange(collection.Cast <string>());
                }

                MusicLabels.Clear();
                if (MediaItemAspect.TryGetAttribute(aspectData, AudioAlbumAspect.ATTR_LABELS, out collection))
                {
                    MusicLabels.AddRange(collection.Cast <string>().Select(s => new CompanyInfo {
                        Name = s, Type = CompanyAspect.COMPANY_MUSIC_LABEL
                    }));
                }
                foreach (CompanyInfo company in MusicLabels)
                {
                    company.AssignNameId();
                }

                Genres.Clear();
                IList <MultipleMediaItemAspect> genreAspects;
                if (MediaItemAspect.TryGetAspects(aspectData, GenreAspect.Metadata, out genreAspects))
                {
                    foreach (MultipleMediaItemAspect genre in genreAspects)
                    {
                        Genres.Add(new GenreInfo
                        {
                            Id   = genre.GetAttributeValue <int?>(GenreAspect.ATTR_ID),
                            Name = genre.GetAttributeValue <string>(GenreAspect.ATTR_GENRE)
                        });
                    }
                }

                byte[] data;
                if (MediaItemAspect.TryGetAttribute(aspectData, ThumbnailLargeAspect.ATTR_THUMBNAIL, out data))
                {
                    HasThumbnail = true;
                }

                success = true;
            }
            else if (aspectData.ContainsKey(AudioAspect.ASPECT_ID))
            {
                MediaItemAspect.TryGetAttribute(aspectData, AudioAspect.ATTR_ALBUM, out Album);
                MediaItemAspect.TryGetAttribute(aspectData, AudioAspect.ATTR_DISCID, out DiscNum);
                MediaItemAspect.TryGetAttribute(aspectData, AudioAspect.ATTR_NUMDISCS, out TotalDiscs);
                MediaItemAspect.TryGetAttribute(aspectData, AudioAspect.ATTR_NUMTRACKS, out TotalTracks);
                MediaItemAspect.TryGetAttribute(aspectData, AudioAspect.ATTR_COMPILATION, out Compilation);

                IEnumerable collection;
                Artists.Clear();
                if (MediaItemAspect.TryGetAttribute(aspectData, AudioAspect.ATTR_ALBUMARTISTS, out collection))
                {
                    Artists.AddRange(collection.Cast <string>().Select(s => new PersonInfo {
                        Name = s, Occupation = PersonAspect.OCCUPATION_ARTIST, ParentMediaName = Album
                    }));
                }
                foreach (PersonInfo artist in Artists)
                {
                    artist.AssignNameId();
                }

                success = true;
            }
            else if (aspectData.ContainsKey(MediaAspect.ASPECT_ID))
            {
                MediaItemAspect.TryGetAttribute(aspectData, MediaAspect.ATTR_TITLE, out Album);

                byte[] data;
                if (MediaItemAspect.TryGetAttribute(aspectData, ThumbnailLargeAspect.ATTR_THUMBNAIL, out data))
                {
                    HasThumbnail = true;
                }

                success = true;
            }

            if (success)
            {
                CustomIds.Clear();
                IList <MultipleMediaItemAspect> externalIdAspects;
                if (MediaItemAspect.TryGetAspects(aspectData, ExternalIdentifierAspect.Metadata, out externalIdAspects))
                {
                    foreach (MultipleMediaItemAspect externalId in externalIdAspects)
                    {
                        string source = externalId.GetAttributeValue <string>(ExternalIdentifierAspect.ATTR_SOURCE);
                        string id     = externalId.GetAttributeValue <string>(ExternalIdentifierAspect.ATTR_ID);
                        string type   = externalId.GetAttributeValue <string>(ExternalIdentifierAspect.ATTR_TYPE);
                        if (type == ExternalIdentifierAspect.TYPE_ALBUM)
                        {
                            if (source == ExternalIdentifierAspect.SOURCE_AUDIODB)
                            {
                                AudioDbId = Convert.ToInt32(id);
                            }
                            else if (source == ExternalIdentifierAspect.SOURCE_MUSICBRAINZ)
                            {
                                MusicBrainzId = id;
                            }
                            else if (source == ExternalIdentifierAspect.SOURCE_MUSICBRAINZ_GROUP)
                            {
                                MusicBrainzGroupId = id;
                            }
                            else if (source == ExternalIdentifierAspect.SOURCE_CDDB)
                            {
                                CdDdId = id;
                            }
                            else if (source == ExternalIdentifierAspect.SOURCE_UPCEAN)
                            {
                                UpcEanId = id;
                            }
                            else if (source == ExternalIdentifierAspect.SOURCE_AMAZON)
                            {
                                AmazonId = id;
                            }
                            else if (source == ExternalIdentifierAspect.SOURCE_ITUNES)
                            {
                                ItunesId = id;
                            }
                            else if (source == ExternalIdentifierAspect.SOURCE_NAME)
                            {
                                NameId = id;
                            }
                            else
                            {
                                CustomIds.Add(source, id);
                            }
                        }
                    }
                }
            }
            return(success);
        }
예제 #2
0
        public override bool FromMetadata(IDictionary <Guid, IList <MediaItemAspect> > aspectData)
        {
            GetMetadataChanged(aspectData);

            if (aspectData.ContainsKey(SeriesAspect.ASPECT_ID))
            {
                MediaItemAspect.TryGetAttribute(aspectData, SeriesAspect.ATTR_ORIG_SERIES_NAME, out OriginalName);
                MediaItemAspect.TryGetAttribute(aspectData, MediaAspect.ATTR_RECORDINGTIME, out FirstAired);
                MediaItemAspect.TryGetAttribute(aspectData, SeriesAspect.ATTR_CERTIFICATION, out Certification);
                MediaItemAspect.TryGetAttribute(aspectData, SeriesAspect.ATTR_ENDED, out IsEnded);

                MediaItemAspect.TryGetAttribute(aspectData, SeriesAspect.ATTR_POPULARITY, out Popularity);
                MediaItemAspect.TryGetAttribute(aspectData, SeriesAspect.ATTR_SCORE, out Score);

                double?rating;
                MediaItemAspect.TryGetAttribute(aspectData, SeriesAspect.ATTR_TOTAL_RATING, out rating);
                int?voteCount;
                MediaItemAspect.TryGetAttribute(aspectData, SeriesAspect.ATTR_RATING_COUNT, out voteCount);
                Rating = new SimpleRating(rating, voteCount);

                string tempString;
                MediaItemAspect.TryGetAttribute(aspectData, SeriesAspect.ATTR_SERIES_NAME, out tempString);
                SeriesName = new SimpleTitle(tempString, string.IsNullOrWhiteSpace(tempString));
                MediaItemAspect.TryGetAttribute(aspectData, MediaAspect.ATTR_SORT_TITLE, out tempString);
                SeriesNameSort = new SimpleTitle(tempString, string.IsNullOrWhiteSpace(tempString));
                MediaItemAspect.TryGetAttribute(aspectData, SeriesAspect.ATTR_DESCRIPTION, out tempString);
                Description = new SimpleTitle(tempString, string.IsNullOrWhiteSpace(tempString));

                int?count;
                if (MediaItemAspect.TryGetAttribute(aspectData, SeriesAspect.ATTR_NUM_SEASONS, out count))
                {
                    TotalSeasons = count.Value;
                }
                if (MediaItemAspect.TryGetAttribute(aspectData, SeriesAspect.ATTR_NUM_EPISODES, out count))
                {
                    TotalEpisodes = count.Value;
                }

                string id;
                if (MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_TMDB, ExternalIdentifierAspect.TYPE_SERIES, out id))
                {
                    MovieDbId = Convert.ToInt32(id);
                }
                if (MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_TVDB, ExternalIdentifierAspect.TYPE_SERIES, out id))
                {
                    TvdbId = Convert.ToInt32(id);
                }
                if (MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_TVMAZE, ExternalIdentifierAspect.TYPE_SERIES, out id))
                {
                    TvMazeId = Convert.ToInt32(id);
                }
                if (MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_TVRAGE, ExternalIdentifierAspect.TYPE_SERIES, out id))
                {
                    TvRageId = Convert.ToInt32(id);
                }
                MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_IMDB, ExternalIdentifierAspect.TYPE_SERIES, out ImdbId);
                MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_NAME, ExternalIdentifierAspect.TYPE_SERIES, out NameId);

                //Brownard 17.06.2016
                //The returned type of the collection differs on the server and client.
                //On the server it's an object collection but on the client it's a string collection due to [de]serialization.
                //Use the non generic Ienumerable to allow for both types.
                IEnumerable collection;

                Actors.Clear();
                if (MediaItemAspect.TryGetAttribute(aspectData, SeriesAspect.ATTR_ACTORS, out collection))
                {
                    Actors.AddRange(collection.Cast <string>().Select(s => new PersonInfo {
                        Name = s, Occupation = PersonAspect.OCCUPATION_ACTOR, ParentMediaName = SeriesName.Text
                    }));
                }
                foreach (PersonInfo actor in Actors)
                {
                    actor.AssignNameId();
                }

                Characters.Clear();
                if (MediaItemAspect.TryGetAttribute(aspectData, SeriesAspect.ATTR_CHARACTERS, out collection))
                {
                    Characters.AddRange(collection.Cast <string>().Select(s => new CharacterInfo {
                        Name = s, ParentMediaName = SeriesName.Text
                    }));
                }
                foreach (CharacterInfo character in Characters)
                {
                    character.AssignNameId();
                }

                Genres.Clear();
                IList <MultipleMediaItemAspect> genreAspects;
                if (MediaItemAspect.TryGetAspects(aspectData, GenreAspect.Metadata, out genreAspects))
                {
                    foreach (MultipleMediaItemAspect genre in genreAspects)
                    {
                        Genres.Add(new GenreInfo
                        {
                            Id   = genre.GetAttributeValue <int?>(GenreAspect.ATTR_ID),
                            Name = genre.GetAttributeValue <string>(GenreAspect.ATTR_GENRE)
                        });
                    }
                }

                Awards.Clear();
                if (MediaItemAspect.TryGetAttribute(aspectData, SeriesAspect.ATTR_AWARDS, out collection))
                {
                    Awards.AddRange(collection.Cast <string>().Select(s => s));
                }

                Networks.Clear();
                if (MediaItemAspect.TryGetAttribute(aspectData, SeriesAspect.ATTR_NETWORKS, out collection))
                {
                    Networks.AddRange(collection.Cast <string>().Select(s => new CompanyInfo {
                        Name = s, Type = CompanyAspect.COMPANY_TV_NETWORK
                    }));
                }
                foreach (CompanyInfo network in Networks)
                {
                    network.AssignNameId();
                }

                ProductionCompanies.Clear();
                if (MediaItemAspect.TryGetAttribute(aspectData, SeriesAspect.ATTR_COMPANIES, out collection))
                {
                    ProductionCompanies.AddRange(collection.Cast <string>().Select(s => new CompanyInfo {
                        Name = s, Type = CompanyAspect.COMPANY_PRODUCTION
                    }));
                }
                foreach (CompanyInfo company in ProductionCompanies)
                {
                    company.AssignNameId();
                }

                DateTime dateNextEpisode;
                if (MediaItemAspect.TryGetAttribute(aspectData, SeriesAspect.ATTR_NEXT_AIR_DATE, out dateNextEpisode) && dateNextEpisode > DateTime.Now)
                {
                    NextEpisodeAirDate = dateNextEpisode;
                    MediaItemAspect.TryGetAttribute(aspectData, SeriesAspect.ATTR_NEXT_EPISODE_NAME, out tempString);
                    NextEpisodeName = new SimpleTitle(tempString, false);
                    MediaItemAspect.TryGetAttribute(aspectData, SeriesAspect.ATTR_NEXT_SEASON, out NextEpisodeSeasonNumber);
                    MediaItemAspect.TryGetAttribute(aspectData, SeriesAspect.ATTR_NEXT_EPISODE, out NextEpisodeNumber);
                }

                byte[] data;
                if (MediaItemAspect.TryGetAttribute(aspectData, ThumbnailLargeAspect.ATTR_THUMBNAIL, out data))
                {
                    HasThumbnail = true;
                }

                return(true);
            }
            else if (aspectData.ContainsKey(SeasonAspect.ASPECT_ID))
            {
                string tempString;
                MediaItemAspect.TryGetAttribute(aspectData, SeasonAspect.ATTR_SERIES_NAME, out tempString);
                SeriesName = new SimpleTitle(tempString, false);

                string id;
                if (MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_TMDB, ExternalIdentifierAspect.TYPE_SERIES, out id))
                {
                    MovieDbId = Convert.ToInt32(id);
                }
                if (MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_TVDB, ExternalIdentifierAspect.TYPE_SERIES, out id))
                {
                    TvdbId = Convert.ToInt32(id);
                }
                if (MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_TVMAZE, ExternalIdentifierAspect.TYPE_SERIES, out id))
                {
                    TvMazeId = Convert.ToInt32(id);
                }
                if (MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_TVRAGE, ExternalIdentifierAspect.TYPE_SERIES, out id))
                {
                    TvRageId = Convert.ToInt32(id);
                }
                MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_IMDB, ExternalIdentifierAspect.TYPE_SERIES, out ImdbId);
                MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_NAME, ExternalIdentifierAspect.TYPE_SERIES, out NameId);

                return(true);
            }
            else if (aspectData.ContainsKey(EpisodeAspect.ASPECT_ID))
            {
                string tempString;
                MediaItemAspect.TryGetAttribute(aspectData, EpisodeAspect.ATTR_SERIES_NAME, out tempString);
                SeriesName = new SimpleTitle(tempString, false);

                string id;
                if (MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_TMDB, ExternalIdentifierAspect.TYPE_SERIES, out id))
                {
                    MovieDbId = Convert.ToInt32(id);
                }
                if (MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_TVDB, ExternalIdentifierAspect.TYPE_SERIES, out id))
                {
                    TvdbId = Convert.ToInt32(id);
                }
                if (MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_TVMAZE, ExternalIdentifierAspect.TYPE_SERIES, out id))
                {
                    TvMazeId = Convert.ToInt32(id);
                }
                if (MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_TVRAGE, ExternalIdentifierAspect.TYPE_SERIES, out id))
                {
                    TvRageId = Convert.ToInt32(id);
                }
                MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_IMDB, ExternalIdentifierAspect.TYPE_SERIES, out ImdbId);
                MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_NAME, ExternalIdentifierAspect.TYPE_SERIES, out NameId);

                if (aspectData.ContainsKey(VideoAudioStreamAspect.ASPECT_ID))
                {
                    Languages.Clear();
                    IList <MultipleMediaItemAspect> audioAspects;
                    if (MediaItemAspect.TryGetAspects(aspectData, VideoAudioStreamAspect.Metadata, out audioAspects))
                    {
                        foreach (MultipleMediaItemAspect audioAspect in audioAspects)
                        {
                            string language = audioAspect.GetAttributeValue <string>(VideoAudioStreamAspect.ATTR_AUDIOLANGUAGE);
                            if (!string.IsNullOrEmpty(language) && !Languages.Contains(language))
                            {
                                Languages.Add(language);
                            }
                        }
                    }
                }

                return(true);
            }
            else if (aspectData.ContainsKey(MediaAspect.ASPECT_ID))
            {
                string tempString;
                MediaItemAspect.TryGetAttribute(aspectData, MediaAspect.ATTR_TITLE, out tempString);
                SeriesName = new SimpleTitle(tempString, false);

                string id;
                if (MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_TMDB, ExternalIdentifierAspect.TYPE_SERIES, out id))
                {
                    MovieDbId = Convert.ToInt32(id);
                }
                if (MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_TVDB, ExternalIdentifierAspect.TYPE_SERIES, out id))
                {
                    TvdbId = Convert.ToInt32(id);
                }
                if (MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_TVMAZE, ExternalIdentifierAspect.TYPE_SERIES, out id))
                {
                    TvMazeId = Convert.ToInt32(id);
                }
                if (MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_TVRAGE, ExternalIdentifierAspect.TYPE_SERIES, out id))
                {
                    TvRageId = Convert.ToInt32(id);
                }
                MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_IMDB, ExternalIdentifierAspect.TYPE_SERIES, out ImdbId);
                MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_NAME, ExternalIdentifierAspect.TYPE_SERIES, out NameId);

                byte[] data;
                if (MediaItemAspect.TryGetAttribute(aspectData, ThumbnailLargeAspect.ATTR_THUMBNAIL, out data))
                {
                    HasThumbnail = true;
                }

                if (aspectData.ContainsKey(VideoAudioStreamAspect.ASPECT_ID))
                {
                    Languages.Clear();
                    IList <MultipleMediaItemAspect> audioAspects;
                    if (MediaItemAspect.TryGetAspects(aspectData, VideoAudioStreamAspect.Metadata, out audioAspects))
                    {
                        foreach (MultipleMediaItemAspect audioAspect in audioAspects)
                        {
                            string language = audioAspect.GetAttributeValue <string>(VideoAudioStreamAspect.ATTR_AUDIOLANGUAGE);
                            if (!string.IsNullOrEmpty(language) && !Languages.Contains(language))
                            {
                                Languages.Add(language);
                            }
                        }
                    }
                }

                return(true);
            }
            return(false);
        }
예제 #3
0
        public override bool FromMetadata(IDictionary <Guid, IList <MediaItemAspect> > aspectData)
        {
            GetMetadataChanged(aspectData);

            if (aspectData.ContainsKey(MovieAspect.ASPECT_ID))
            {
                MediaItemAspect.TryGetAttribute(aspectData, MediaAspect.ATTR_RECORDINGTIME, out ReleaseDate);
                MediaItemAspect.TryGetAttribute(aspectData, MovieAspect.ATTR_TAGLINE, out Tagline);
                MediaItemAspect.TryGetAttribute(aspectData, MovieAspect.ATTR_CERTIFICATION, out Certification);

                MediaItemAspect.TryGetAttribute(aspectData, MovieAspect.ATTR_RUNTIME_M, out Runtime);
                MediaItemAspect.TryGetAttribute(aspectData, MovieAspect.ATTR_BUDGET, out Budget);
                MediaItemAspect.TryGetAttribute(aspectData, MovieAspect.ATTR_REVENUE, out Revenue);
                MediaItemAspect.TryGetAttribute(aspectData, MovieAspect.ATTR_POPULARITY, out Popularity);
                MediaItemAspect.TryGetAttribute(aspectData, MovieAspect.ATTR_SCORE, out Score);

                double?rating;
                MediaItemAspect.TryGetAttribute(aspectData, MovieAspect.ATTR_TOTAL_RATING, out rating);
                int?voteCount;
                MediaItemAspect.TryGetAttribute(aspectData, MovieAspect.ATTR_RATING_COUNT, out voteCount);
                Rating = new SimpleRating(rating, voteCount);

                string tempString;
                MediaItemAspect.TryGetAttribute(aspectData, MovieAspect.ATTR_MOVIE_NAME, out tempString);
                MovieName = new SimpleTitle(tempString, false);
                MediaItemAspect.TryGetAttribute(aspectData, MediaAspect.ATTR_SORT_TITLE, out tempString);
                MovieNameSort = new SimpleTitle(tempString, false);
                MediaItemAspect.TryGetAttribute(aspectData, VideoAspect.ATTR_STORYPLOT, out tempString);
                Summary = new SimpleTitle(tempString, false);
                MediaItemAspect.TryGetAttribute(aspectData, MovieAspect.ATTR_COLLECTION_NAME, out tempString);
                CollectionName = new SimpleTitle(tempString, false);
                MediaItemAspect.TryGetAttribute(aspectData, MovieAspect.ATTR_ORIG_MOVIE_NAME, out tempString);
                OriginalName = tempString;

                string id;
                if (MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_TMDB, ExternalIdentifierAspect.TYPE_MOVIE, out id))
                {
                    MovieDbId = Convert.ToInt32(id);
                }
                if (MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_ALLOCINE, ExternalIdentifierAspect.TYPE_MOVIE, out id))
                {
                    AllocinebId = Convert.ToInt32(id);
                }
                if (MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_CINEPASSION, ExternalIdentifierAspect.TYPE_MOVIE, out id))
                {
                    CinePassionId = Convert.ToInt32(id);
                }

                if (MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_TMDB, ExternalIdentifierAspect.TYPE_COLLECTION, out id))
                {
                    CollectionMovieDbId = Convert.ToInt32(id);
                }

                MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_IMDB, ExternalIdentifierAspect.TYPE_MOVIE, out ImdbId);
                MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_NAME, ExternalIdentifierAspect.TYPE_MOVIE, out NameId);

                MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_NAME, ExternalIdentifierAspect.TYPE_COLLECTION, out CollectionNameId);

                //Brownard 17.06.2016
                //The returned type of the collection differs on the server and client.
                //On the server it's an object collection but on the client it's a string collection due to [de]serialization.
                //Use the non generic Ienumerable to allow for both types.
                IEnumerable collection;
                Actors.Clear();
                if (MediaItemAspect.TryGetAttribute(aspectData, VideoAspect.ATTR_ACTORS, out collection))
                {
                    Actors.AddRange(collection.Cast <string>().Select(s => new PersonInfo {
                        Name = s, Occupation = PersonAspect.OCCUPATION_ACTOR, MediaName = MovieName.Text
                    }));
                }
                foreach (PersonInfo actor in Actors)
                {
                    actor.AssignNameId();
                }

                Directors.Clear();
                if (MediaItemAspect.TryGetAttribute(aspectData, VideoAspect.ATTR_DIRECTORS, out collection))
                {
                    Directors.AddRange(collection.Cast <string>().Select(s => new PersonInfo {
                        Name = s, Occupation = PersonAspect.OCCUPATION_DIRECTOR, MediaName = MovieName.Text
                    }));
                }
                foreach (PersonInfo director in Directors)
                {
                    director.AssignNameId();
                }

                Writers.Clear();
                if (MediaItemAspect.TryGetAttribute(aspectData, VideoAspect.ATTR_WRITERS, out collection))
                {
                    Writers.AddRange(collection.Cast <string>().Select(s => new PersonInfo {
                        Name = s, Occupation = PersonAspect.OCCUPATION_WRITER, MediaName = MovieName.Text
                    }));
                }
                foreach (PersonInfo writer in Writers)
                {
                    writer.AssignNameId();
                }

                Characters.Clear();
                if (MediaItemAspect.TryGetAttribute(aspectData, VideoAspect.ATTR_CHARACTERS, out collection))
                {
                    Characters.AddRange(collection.Cast <string>().Select(s => new CharacterInfo {
                        Name = s, MediaName = MovieName.Text
                    }));
                }
                foreach (CharacterInfo character in Characters)
                {
                    character.AssignNameId();
                }

                Genres.Clear();
                IList <MultipleMediaItemAspect> genreAspects;
                if (MediaItemAspect.TryGetAspects(aspectData, GenreAspect.Metadata, out genreAspects))
                {
                    foreach (MultipleMediaItemAspect genre in genreAspects)
                    {
                        Genres.Add(new GenreInfo
                        {
                            Id   = genre.GetAttributeValue <int?>(GenreAspect.ATTR_ID),
                            Name = genre.GetAttributeValue <string>(GenreAspect.ATTR_GENRE)
                        });
                    }
                }

                Awards.Clear();
                if (MediaItemAspect.TryGetAttribute(aspectData, MovieAspect.ATTR_AWARDS, out collection))
                {
                    Awards.AddRange(collection.Cast <string>());
                }

                ProductionCompanies.Clear();
                if (MediaItemAspect.TryGetAttribute(aspectData, MovieAspect.ATTR_COMPANIES, out collection))
                {
                    ProductionCompanies.AddRange(collection.Cast <string>().Select(s => new CompanyInfo {
                        Name = s, Type = CompanyAspect.COMPANY_PRODUCTION
                    }));
                }
                foreach (CompanyInfo company in ProductionCompanies)
                {
                    company.AssignNameId();
                }

                byte[] data;
                if (MediaItemAspect.TryGetAttribute(aspectData, ThumbnailLargeAspect.ATTR_THUMBNAIL, out data))
                {
                    HasThumbnail = true;
                }

                if (aspectData.ContainsKey(VideoAudioStreamAspect.ASPECT_ID))
                {
                    Languages.Clear();
                    IList <MultipleMediaItemAspect> audioAspects;
                    if (MediaItemAspect.TryGetAspects(aspectData, VideoAudioStreamAspect.Metadata, out audioAspects))
                    {
                        foreach (MultipleMediaItemAspect audioAspect in audioAspects)
                        {
                            string language = audioAspect.GetAttributeValue <string>(VideoAudioStreamAspect.ATTR_AUDIOLANGUAGE);
                            if (!string.IsNullOrEmpty(language) && !Languages.Contains(language))
                            {
                                Languages.Add(language);
                            }
                        }
                    }
                }

                return(true);
            }
            else if (aspectData.ContainsKey(MediaAspect.ASPECT_ID))
            {
                string tempString;
                MediaItemAspect.TryGetAttribute(aspectData, MediaAspect.ATTR_TITLE, out tempString);
                MovieName = new SimpleTitle(tempString, false);

                string id;
                if (MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_TMDB, ExternalIdentifierAspect.TYPE_MOVIE, out id))
                {
                    MovieDbId = Convert.ToInt32(id);
                }
                if (MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_ALLOCINE, ExternalIdentifierAspect.TYPE_MOVIE, out id))
                {
                    AllocinebId = Convert.ToInt32(id);
                }
                if (MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_CINEPASSION, ExternalIdentifierAspect.TYPE_MOVIE, out id))
                {
                    CinePassionId = Convert.ToInt32(id);
                }

                if (MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_TMDB, ExternalIdentifierAspect.TYPE_COLLECTION, out id))
                {
                    CollectionMovieDbId = Convert.ToInt32(id);
                }

                MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_IMDB, ExternalIdentifierAspect.TYPE_MOVIE, out ImdbId);
                MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_NAME, ExternalIdentifierAspect.TYPE_MOVIE, out NameId);

                MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_NAME, ExternalIdentifierAspect.TYPE_COLLECTION, out CollectionNameId);

                byte[] data;
                if (MediaItemAspect.TryGetAttribute(aspectData, ThumbnailLargeAspect.ATTR_THUMBNAIL, out data))
                {
                    HasThumbnail = true;
                }

                if (aspectData.ContainsKey(VideoAudioStreamAspect.ASPECT_ID))
                {
                    Languages.Clear();
                    IList <MultipleMediaItemAspect> audioAspects;
                    if (MediaItemAspect.TryGetAspects(aspectData, VideoAudioStreamAspect.Metadata, out audioAspects))
                    {
                        foreach (MultipleMediaItemAspect audioAspect in audioAspects)
                        {
                            string language = audioAspect.GetAttributeValue <string>(VideoAudioStreamAspect.ATTR_AUDIOLANGUAGE);
                            if (!string.IsNullOrEmpty(language) && !Languages.Contains(language))
                            {
                                Languages.Add(language);
                            }
                        }
                    }
                }

                return(true);
            }
            return(false);
        }
예제 #4
0
        public override bool FromMetadata(IDictionary <Guid, IList <MediaItemAspect> > aspectData)
        {
            if (!aspectData.ContainsKey(AudioAspect.ASPECT_ID))
            {
                return(false);
            }

            GetMetadataChanged(aspectData);

            MediaItemAspect.TryGetAttribute(aspectData, AudioAspect.ATTR_TRACKNAME, out TrackName);
            MediaItemAspect.TryGetAttribute(aspectData, MediaAspect.ATTR_SORT_TITLE, out TrackNameSort);
            MediaItemAspect.TryGetAttribute(aspectData, AudioAspect.ATTR_LYRICS, out TrackLyrics);
            MediaItemAspect.TryGetAttribute(aspectData, MediaAspect.ATTR_RECORDINGTIME, out ReleaseDate);
            MediaItemAspect.TryGetAttribute(aspectData, AudioAspect.ATTR_TRACK, out TrackNum);
            MediaItemAspect.TryGetAttribute(aspectData, AudioAspect.ATTR_NUMTRACKS, out TotalTracks);
            MediaItemAspect.TryGetAttribute(aspectData, AudioAspect.ATTR_COMPILATION, out Compilation);
            MediaItemAspect.TryGetAttribute(aspectData, AudioAspect.ATTR_BITRATE, out BitRate);
            MediaItemAspect.TryGetAttribute(aspectData, AudioAspect.ATTR_SAMPLERATE, out SampleRate);
            MediaItemAspect.TryGetAttribute(aspectData, AudioAspect.ATTR_CHANNELS, out Channels);
            MediaItemAspect.TryGetAttribute(aspectData, AudioAspect.ATTR_ALBUM, out Album);
            MediaItemAspect.TryGetAttribute(aspectData, AudioAspect.ATTR_DISCID, out DiscNum);
            MediaItemAspect.TryGetAttribute(aspectData, AudioAspect.ATTR_NUMDISCS, out TotalDiscs);
            MediaItemAspect.TryGetAttribute(aspectData, AudioAspect.ATTR_DURATION, out Duration);
            MediaItemAspect.TryGetAttribute(aspectData, AudioAspect.ATTR_ENCODING, out Encoding);
            MediaItemAspect.TryGetAttribute(aspectData, AudioAspect.ATTR_CONTENT_GROUP, out ContentGroup);

            double?rating;

            MediaItemAspect.TryGetAttribute(aspectData, AudioAspect.ATTR_TOTAL_RATING, out rating);
            int?voteCount;

            MediaItemAspect.TryGetAttribute(aspectData, AudioAspect.ATTR_RATING_COUNT, out voteCount);
            Rating = new SimpleRating(rating, voteCount);

            string id;

            if (MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_AUDIODB, ExternalIdentifierAspect.TYPE_TRACK, out id))
            {
                AudioDbId = Convert.ToInt64(id);
            }
            if (MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_LYRIC, ExternalIdentifierAspect.TYPE_TRACK, out id))
            {
                LyricId = Convert.ToInt64(id);
            }
            if (MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_MVDB, ExternalIdentifierAspect.TYPE_TRACK, out id))
            {
                MvDbId = Convert.ToInt64(id);
            }
            MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_MUSICBRAINZ, ExternalIdentifierAspect.TYPE_TRACK, out MusicBrainzId);
            MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_ISRC, ExternalIdentifierAspect.TYPE_TRACK, out IsrcId);
            MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_MUSIC_IP, ExternalIdentifierAspect.TYPE_TRACK, out MusicIpId);
            MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_NAME, ExternalIdentifierAspect.TYPE_TRACK, out NameId);

            if (MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_AUDIODB, ExternalIdentifierAspect.TYPE_ALBUM, out id))
            {
                AlbumAudioDbId = Convert.ToInt64(id);
            }
            MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_MUSICBRAINZ, ExternalIdentifierAspect.TYPE_ALBUM, out AlbumMusicBrainzId);
            MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_MUSICBRAINZ_GROUP, ExternalIdentifierAspect.TYPE_ALBUM, out AlbumMusicBrainzGroupId);
            MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_CDDB, ExternalIdentifierAspect.TYPE_ALBUM, out AlbumCdDdId);
            MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_UPCEAN, ExternalIdentifierAspect.TYPE_ALBUM, out AlbumUpcEanId);
            MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_AMAZON, ExternalIdentifierAspect.TYPE_ALBUM, out AlbumAmazonId);
            MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_ITUNES, ExternalIdentifierAspect.TYPE_ALBUM, out AlbumItunesId);
            MediaItemAspect.TryGetExternalAttribute(aspectData, ExternalIdentifierAspect.SOURCE_NAME, ExternalIdentifierAspect.TYPE_ALBUM, out AlbumNameId);

            //Brownard 17.06.2016
            //The returned type of the collection differs on the server and client.
            //On the server it's an object collection but on the client it's a string collection due to [de]serialization.
            //Use the non generic Ienumerable to allow for both types.
            IEnumerable collection;

            Artists.Clear();
            if (MediaItemAspect.TryGetAttribute(aspectData, AudioAspect.ATTR_ARTISTS, out collection))
            {
                Artists.AddRange(collection.Cast <string>().Select(s => new PersonInfo {
                    Name = s, Occupation = PersonAspect.OCCUPATION_ARTIST, MediaName = TrackName, ParentMediaName = Album
                }));
            }
            foreach (PersonInfo artist in Artists)
            {
                artist.AssignNameId();
            }

            AlbumArtists.Clear();
            if (MediaItemAspect.TryGetAttribute(aspectData, AudioAspect.ATTR_ALBUMARTISTS, out collection))
            {
                AlbumArtists.AddRange(collection.Cast <string>().Select(s => new PersonInfo {
                    Name = s, Occupation = PersonAspect.OCCUPATION_ARTIST, MediaName = TrackName, ParentMediaName = Album
                }));
            }
            foreach (PersonInfo artist in AlbumArtists)
            {
                artist.AssignNameId();
            }

            Composers.Clear();
            if (MediaItemAspect.TryGetAttribute(aspectData, AudioAspect.ATTR_COMPOSERS, out collection))
            {
                Composers.AddRange(collection.Cast <string>().Select(s => new PersonInfo {
                    Name = s, Occupation = PersonAspect.OCCUPATION_COMPOSER, MediaName = TrackName, ParentMediaName = Album
                }));
            }
            foreach (PersonInfo composer in Composers)
            {
                composer.AssignNameId();
            }

            Conductors.Clear();
            if (MediaItemAspect.TryGetAttribute(aspectData, AudioAspect.ATTR_CONDUCTERS, out collection))
            {
                Conductors.AddRange(collection.Cast <string>().Select(s => new PersonInfo {
                    Name = s, Occupation = PersonAspect.OCCUPATION_CONDUCTOR, MediaName = TrackName, ParentMediaName = Album
                }));
            }
            foreach (PersonInfo conductor in Conductors)
            {
                conductor.AssignNameId();
            }

            Genres.Clear();
            IList <MultipleMediaItemAspect> genreAspects;

            if (MediaItemAspect.TryGetAspects(aspectData, GenreAspect.Metadata, out genreAspects))
            {
                foreach (MultipleMediaItemAspect genre in genreAspects)
                {
                    Genres.Add(new GenreInfo
                    {
                        Id   = genre.GetAttributeValue <int?>(GenreAspect.ATTR_ID),
                        Name = genre.GetAttributeValue <string>(GenreAspect.ATTR_GENRE)
                    });
                }
            }

            byte[] data;
            if (MediaItemAspect.TryGetAttribute(aspectData, ThumbnailLargeAspect.ATTR_THUMBNAIL, out data))
            {
                HasThumbnail = true;
            }

            return(true);
        }