Beispiel #1
0
        internal static WebTVSeasonBasic TVSeasonBasic(IOwinContext context, MediaItem item, Guid?showId = null)
        {
            Guid?       user = ResourceAccessUtils.GetUser(context);
            ISet <Guid> necessaryMIATypespisodes = new HashSet <Guid>();

            necessaryMIATypespisodes.Add(MediaAspect.ASPECT_ID);
            necessaryMIATypespisodes.Add(EpisodeAspect.ASPECT_ID);

            IFilter unwatchedEpisodeFilter = BooleanCombinationFilter.CombineFilters(BooleanOperator.And,
                                                                                     new RelationshipFilter(EpisodeAspect.ROLE_EPISODE, SeasonAspect.ROLE_SEASON, item.MediaItemId),
                                                                                     new RelationalUserDataFilter(user.Value, UserDataKeysKnown.KEY_PLAY_PERCENTAGE, RelationalOperator.LT, UserDataKeysKnown.GetSortablePlayPercentageString(100), true));

            int unwatchedCount = MediaLibraryAccess.CountMediaItems(context, necessaryMIATypespisodes, unwatchedEpisodeFilter);

            GetShowId(item, ref showId);

            var mediaAspect    = item.GetAspect(MediaAspect.Metadata);
            var seasonAspect   = item.GetAspect(SeasonAspect.Metadata);
            var importerAspect = item.GetAspect(ImporterAspect.Metadata);

            DateTime?firstAired = mediaAspect.GetAttributeValue <DateTime?>(MediaAspect.ATTR_RECORDINGTIME);

            return(new WebTVSeasonBasic
            {
                Title = mediaAspect.GetAttributeValue <string>(MediaAspect.ATTR_TITLE),
                Id = item.MediaItemId.ToString(),
                ShowId = showId.HasValue ? showId.Value.ToString() : null,
                SeasonNumber = seasonAspect.GetAttributeValue <int>(SeasonAspect.ATTR_SEASON),
                EpisodeCount = seasonAspect.GetAttributeValue <int>(SeasonAspect.ATTR_AVAILABLE_EPISODES),
                UnwatchedEpisodeCount = unwatchedCount,
                DateAdded = importerAspect.GetAttributeValue <DateTime>(ImporterAspect.ATTR_DATEADDED),
                Year = firstAired.HasValue ? firstAired.Value.Year : 0,
            });
        }
        internal static WebMovieBasic MovieBasic(MediaItem item)
        {
            MediaItemAspect movieAspect    = item.GetAspect(MovieAspect.Metadata);
            MediaItemAspect videoAspect    = item.GetAspect(VideoAspect.Metadata);
            MediaItemAspect mediaAspect    = item.GetAspect(MediaAspect.Metadata);
            MediaItemAspect importerAspect = item.GetAspect(ImporterAspect.Metadata);

            WebMovieBasic webMovieBasic = new WebMovieBasic
            {
                Title     = movieAspect.GetAttributeValue <string>(MovieAspect.ATTR_MOVIE_NAME),
                Id        = item.MediaItemId.ToString(),
                Type      = WebMediaType.Movie,
                Path      = ResourceAccessUtils.GetPaths(item),
                Year      = mediaAspect.GetAttributeValue <DateTime>(MediaAspect.ATTR_RECORDINGTIME).Year,
                Runtime   = movieAspect.GetAttributeValue <int>(MovieAspect.ATTR_RUNTIME_M),
                Watched   = Convert.ToInt32(item.UserData.FirstOrDefault(d => d.Key == UserDataKeysKnown.KEY_PLAY_PERCENTAGE).Value ?? "0") >= 100,
                DateAdded = importerAspect.GetAttributeValue <DateTime>(ImporterAspect.ATTR_DATEADDED),
                Rating    = Convert.ToSingle(movieAspect.GetAttributeValue <double>(MovieAspect.ATTR_TOTAL_RATING)),
                Artwork   = ResourceAccessUtils.GetWebArtwork(item),
            };

            IEnumerable <string> aspectActors = videoAspect.GetCollectionAttribute <string>(VideoAspect.ATTR_ACTORS);

            if (aspectActors != null)
            {
                webMovieBasic.Actors = aspectActors.Distinct().Select(a => new WebActor(a)).ToList();
            }

            IList <MediaItemAspect> genres;

            if (item.Aspects.TryGetValue(GenreAspect.ASPECT_ID, out genres))
            {
                webMovieBasic.Genres = genres.Select(g => g.GetAttributeValue <string>(GenreAspect.ATTR_GENRE)).ToList();
            }

            string tmdbId;

            if (MediaItemAspect.TryGetExternalAttribute(item.Aspects, ExternalIdentifierAspect.SOURCE_TMDB, ExternalIdentifierAspect.TYPE_MOVIE, out tmdbId) && tmdbId != null)
            {
                webMovieBasic.ExternalId.Add(new WebExternalId {
                    Site = "TMDB", Id = tmdbId
                });
            }
            string imdbId;

            if (MediaItemAspect.TryGetExternalAttribute(item.Aspects, ExternalIdentifierAspect.SOURCE_IMDB, ExternalIdentifierAspect.TYPE_MOVIE, out imdbId) && imdbId != null)
            {
                webMovieBasic.ExternalId.Add(new WebExternalId {
                    Site = "IMDB", Id = imdbId
                });
            }

            return(webMovieBasic);
        }
Beispiel #3
0
        internal static WebMusicTrackBasic MusicTrackBasic(MediaItem item)
        {
            MediaItemAspect audioAspect    = item.GetAspect(AudioAspect.Metadata);
            MediaItemAspect mediaAspect    = item.GetAspect(MediaAspect.Metadata);
            MediaItemAspect importerAspect = item.GetAspect(ImporterAspect.Metadata);

            WebMusicTrackBasic webTrackBasic = new WebMusicTrackBasic
            {
                Title       = audioAspect.GetAttributeValue <string>(AudioAspect.ATTR_TRACKNAME),
                Id          = item.MediaItemId.ToString(),
                Type        = WebMediaType.MusicTrack,
                Path        = ResourceAccessUtils.GetPaths(item),
                Year        = mediaAspect.GetAttributeValue <DateTime>(MediaAspect.ATTR_RECORDINGTIME).Year,
                Duration    = (int)audioAspect.GetAttributeValue <long>(AudioAspect.ATTR_DURATION),
                DateAdded   = importerAspect.GetAttributeValue <DateTime>(ImporterAspect.ATTR_DATEADDED),
                Rating      = Convert.ToSingle(audioAspect.GetAttributeValue <double>(AudioAspect.ATTR_TOTAL_RATING)),
                Artwork     = ResourceAccessUtils.GetWebArtwork(item),
                Album       = audioAspect.GetAttributeValue <string>(AudioAspect.ATTR_ALBUM),
                DiscNumber  = audioAspect.GetAttributeValue <int>(AudioAspect.ATTR_DISCID),
                TrackNumber = audioAspect.GetAttributeValue <int>(AudioAspect.ATTR_TRACK),
            };

            IEnumerable <string> aspectArtists = audioAspect.GetCollectionAttribute <string>(AudioAspect.ATTR_ARTISTS);

            if (aspectArtists != null)
            {
                webTrackBasic.Artist = aspectArtists.Distinct().ToList();
            }

            aspectArtists = audioAspect.GetCollectionAttribute <string>(AudioAspect.ATTR_ALBUMARTISTS);
            if (aspectArtists != null)
            {
                webTrackBasic.AlbumArtist = aspectArtists.FirstOrDefault();
            }

            if (MediaItemAspect.TryGetAspects(item.Aspects, RelationshipAspect.Metadata, out var relationAspects))
            {
                webTrackBasic.ArtistId      = relationAspects.Where(r => (Guid?)r[RelationshipAspect.ATTR_LINKED_ROLE] == PersonAspect.ROLE_ARTIST).Select(r => r[RelationshipAspect.ATTR_LINKED_ID].ToString()).ToList();
                webTrackBasic.AlbumId       = relationAspects.Where(r => (Guid?)r[RelationshipAspect.ATTR_LINKED_ROLE] == AudioAlbumAspect.ROLE_ALBUM).Select(r => r[RelationshipAspect.ATTR_LINKED_ID].ToString()).FirstOrDefault();
                webTrackBasic.AlbumArtistId = relationAspects.Where(r => (Guid?)r[RelationshipAspect.ATTR_LINKED_ROLE] == PersonAspect.ROLE_ALBUMARTIST).Select(r => r[RelationshipAspect.ATTR_LINKED_ID].ToString()).FirstOrDefault();
            }

            IList <MediaItemAspect> genres;

            if (item.Aspects.TryGetValue(GenreAspect.ASPECT_ID, out genres))
            {
                webTrackBasic.Genres = genres.Select(g => g.GetAttributeValue <string>(GenreAspect.ATTR_GENRE)).ToList();
            }

            return(webTrackBasic);
        }
Beispiel #4
0
        internal static WebTVEpisodeBasic EpisodeBasic(MediaItem item, Guid?showId = null, Guid?seasonId = null)
        {
            MediaItemAspect episodeAspect  = item.GetAspect(EpisodeAspect.Metadata);
            MediaItemAspect importerAspect = item.GetAspect(ImporterAspect.Metadata);
            MediaItemAspect mediaAspect    = item.GetAspect(MediaAspect.Metadata);

            IEnumerable <int> episodeNumbers = episodeAspect.GetCollectionAttribute <int>(EpisodeAspect.ATTR_EPISODE);
            int episodeNumber = episodeNumbers != null?episodeNumbers.FirstOrDefault() : 0;

            GetParentIds(item, ref showId, ref seasonId);

            WebTVEpisodeBasic webTvEpisodeBasic = new WebTVEpisodeBasic
            {
                Title         = episodeAspect.GetAttributeValue <string>(EpisodeAspect.ATTR_EPISODE_NAME),
                EpisodeNumber = episodeNumber,
                Id            = item.MediaItemId.ToString(),
                ShowId        = showId.HasValue ? showId.Value.ToString() : null,
                SeasonId      = seasonId.HasValue ? seasonId.Value.ToString() : null,
                Type          = WebMediaType.TVEpisode,
                Path          = ResourceAccessUtils.GetPaths(item),
                Watched       = Convert.ToInt32(item.UserData.FirstOrDefault(d => d.Key == UserDataKeysKnown.KEY_PLAY_PERCENTAGE).Value ?? "0") >= 100,
                DateAdded     = importerAspect.GetAttributeValue <DateTime>(ImporterAspect.ATTR_DATEADDED),
                SeasonNumber  = episodeAspect.GetAttributeValue <int>(EpisodeAspect.ATTR_SEASON),
                FirstAired    = mediaAspect.GetAttributeValue <DateTime>(MediaAspect.ATTR_RECORDINGTIME),
                Rating        = Convert.ToSingle(episodeAspect.GetAttributeValue <double>(EpisodeAspect.ATTR_TOTAL_RATING)),
                Artwork       = ResourceAccessUtils.GetWebArtwork(item),
            };

            string TvDbId;

            MediaItemAspect.TryGetExternalAttribute(item.Aspects, ExternalIdentifierAspect.SOURCE_TVDB, ExternalIdentifierAspect.TYPE_SERIES, out TvDbId);
            if (TvDbId != null)
            {
                webTvEpisodeBasic.ExternalId.Add(new WebExternalId {
                    Site = "TVDB", Id = TvDbId
                });
            }
            string ImdbId;

            MediaItemAspect.TryGetExternalAttribute(item.Aspects, ExternalIdentifierAspect.SOURCE_IMDB, ExternalIdentifierAspect.TYPE_SERIES, out ImdbId);
            if (ImdbId != null)
            {
                webTvEpisodeBasic.ExternalId.Add(new WebExternalId {
                    Site = "IMDB", Id = ImdbId
                });
            }

            return(webTvEpisodeBasic);
        }
        internal static WebTVShowDetailed TVShowDetailed(IOwinContext context, MediaItem item, MediaItem showItem = null)
        {
            var seriesAspect = item.GetAspect(SeriesAspect.Metadata);
            var tvShowBasic  = TVShowBasic(context, item);

            return(new WebTVShowDetailed()
            {
                Summary = seriesAspect.GetAttributeValue <string>(SeriesAspect.ATTR_DESCRIPTION),
                // From TvShowBasic
                Id = tvShowBasic.Id,
                Title = tvShowBasic.Title,
                DateAdded = tvShowBasic.DateAdded,
                EpisodeCount = tvShowBasic.EpisodeCount,
                UnwatchedEpisodeCount = tvShowBasic.UnwatchedEpisodeCount,
                PID = tvShowBasic.PID,
                Genres = tvShowBasic.Genres,
                Actors = tvShowBasic.Actors,
                Artwork = tvShowBasic.Artwork,
                ContentRating = tvShowBasic.ContentRating,
                ExternalId = tvShowBasic.ExternalId,
                IsProtected = tvShowBasic.IsProtected,
                Rating = tvShowBasic.Rating,
                SeasonCount = tvShowBasic.SeasonCount,
                Year = tvShowBasic.Year
            });
        }
        internal static WebPictureDetailed PictureDetailed(MediaItem item)
        {
            MediaItemAspect imageAspects = item.GetAspect(ImageAspect.Metadata);

            WebPictureBasic    webPictureBasic    = PictureBasic(item);
            WebPictureDetailed webPictureDetailed = new WebPictureDetailed
            {
                Type               = webPictureBasic.Type,
                DateAdded          = webPictureBasic.DateAdded,
                Id                 = item.MediaItemId.ToString(),
                Title              = webPictureBasic.Title,
                DateTaken          = webPictureBasic.DateTaken,
                Path               = webPictureBasic.Path,
                Artwork            = webPictureBasic.Artwork,
                Categories         = webPictureBasic.Categories,
                Width              = imageAspects.GetAttributeValue <int?>(ImageAspect.ATTR_WIDTH)?.ToString(),
                Height             = imageAspects.GetAttributeValue <int?>(ImageAspect.ATTR_HEIGHT)?.ToString(),
                CameraModel        = imageAspects.GetAttributeValue <string>(ImageAspect.ATTR_MODEL),
                CameraManufacturer = imageAspects.GetAttributeValue <string>(ImageAspect.ATTR_MAKE),
                PID                = webPictureBasic.PID
            };

            if (double.TryParse(webPictureDetailed.Width, out double width) && double.TryParse(webPictureDetailed.Height, out double height))
            {
                webPictureDetailed.Mpixel = (width * height) / 1000000.0;
            }

            return(webPictureDetailed);
        }
Beispiel #7
0
        /// <summary>
        /// Checks if an image is already in the cache
        /// </summary>
        /// <param name="id">Guid of the media item</param>
        /// <param name="identifier">identifier from GetIdentifier()</param>
        /// <param name="width">Width of the finale image</param>
        /// <param name="height">height of the final image</param>
        /// <param name="borders">borders of the final image</param>
        /// <returns>Returns true if the image was added to the cache, false if the image is already in the cache</returns>
        /// <returns>true if the image is in the cache, otherwise false</returns>
        internal static bool IsInCache(IOwinContext context, CacheIdentifier identifier)
        {
            lock (_lockObject)
            {
                string   filepath = GetFilePath(identifier);
                DateTime dateAdded;
                if (!identifier.IsTvRadio)
                {
                    ISet <Guid> necessaryMIATypes = new HashSet <Guid>();
                    necessaryMIATypes.Add(ImporterAspect.ASPECT_ID);
                    MediaItem item = MediaLibraryAccess.GetMediaItemById(context, identifier.MediaItemId, necessaryMIATypes, null);
                    if (item == null)
                    {
                        return(false);
                    }
                    dateAdded = (DateTime)item.GetAspect(ImporterAspect.Metadata)[ImporterAspect.ATTR_DATEADDED];
                }
                else
                {
                    dateAdded = DateTime.Now.AddMonths(-1); // refresh image evry month
                }

                return(File.Exists(GetFilePath(identifier)) && DateTime.Compare(GetLastModifiedTime(filepath), dateAdded) >= 0);
            }
        }
        public static Task <WebMediaItem> ProcessAsync(IOwinContext context, string id)
        {
            if (id == null)
            {
                throw new BadRequestException("GetMediaItem: id is null");
            }

            ISet <Guid> necessaryMIATypes = new HashSet <Guid>();

            necessaryMIATypes.Add(MediaAspect.ASPECT_ID);
            necessaryMIATypes.Add(ProviderResourceAspect.ASPECT_ID);
            necessaryMIATypes.Add(ImporterAspect.ASPECT_ID);

            ISet <Guid> optionalMIATypes = new HashSet <Guid>();

            optionalMIATypes.Add(VideoAspect.ASPECT_ID);
            optionalMIATypes.Add(MovieAspect.ASPECT_ID);
            optionalMIATypes.Add(EpisodeAspect.ASPECT_ID);
            optionalMIATypes.Add(AudioAspect.ASPECT_ID);
            optionalMIATypes.Add(ImageAspect.ASPECT_ID);

            MediaItem item = MediaLibraryAccess.GetMediaItemById(context, Guid.Parse(id), necessaryMIATypes, optionalMIATypes);

            if (item == null)
            {
                throw new NotFoundException(String.Format("GetMediaItem: No MediaItem found with id: {0}", id));
            }

            WebMediaItem webMediaItem = new WebMediaItem();

            webMediaItem.Id        = item.MediaItemId.ToString();
            webMediaItem.Artwork   = ResourceAccessUtils.GetWebArtwork(item);
            webMediaItem.DateAdded = item.GetAspect(ImporterAspect.Metadata).GetAttributeValue <DateTime>(ImporterAspect.ATTR_DATEADDED);
            webMediaItem.Path      = ResourceAccessUtils.GetPaths(item);
            webMediaItem.Type      = ResourceAccessUtils.GetWebMediaType(item);
            webMediaItem.Title     = item.GetAspect(MediaAspect.Metadata).GetAttributeValue <string>(MediaAspect.ATTR_TITLE);

            return(Task.FromResult(webMediaItem));
        }
        internal static WebMusicAlbumBasic MusicAlbumBasic(MediaItem item)
        {
            MediaItemAspect importerAspect = item.GetAspect(ImporterAspect.Metadata);
            MediaItemAspect mediaAspect    = item.GetAspect(MediaAspect.Metadata);
            MediaItemAspect albumAspect    = item.GetAspect(AudioAlbumAspect.Metadata);

            var artists = albumAspect.GetCollectionAttribute <string>(AudioAlbumAspect.ATTR_ARTISTS);

            IList <MultipleMediaItemAspect> genres;

            if (!MediaItemAspect.TryGetAspects(item.Aspects, GenreAspect.Metadata, out genres))
            {
                genres = new List <MultipleMediaItemAspect>();
            }

            var artistIds = new HashSet <string>();

            if (MediaItemAspect.TryGetAspects(item.Aspects, RelationshipAspect.Metadata, out var relationAspects))
            {
                artistIds = new HashSet <string>(relationAspects.Where(r => (Guid?)r[RelationshipAspect.ATTR_LINKED_ROLE] == PersonAspect.ROLE_ALBUMARTIST).Select(r => r[RelationshipAspect.ATTR_LINKED_ID].ToString()));
            }

            return(new WebMusicAlbumBasic
            {
                Id = item.MediaItemId.ToString(),
                Artists = artists?.ToList(),
                ArtistsId = artistIds?.ToList(),
                AlbumArtist = artists?.FirstOrDefault()?.ToString(),
                AlbumArtistId = artistIds?.FirstOrDefault()?.ToString(),
                Genres = genres?.Select(a => a.GetAttributeValue <string>(GenreAspect.ATTR_GENRE)).ToList(),
                Title = albumAspect.GetAttributeValue <string>(AudioAlbumAspect.ATTR_ALBUM),
                Year = mediaAspect.GetAttributeValue <DateTime>(MediaAspect.ATTR_RECORDINGTIME).Year,
                DateAdded = importerAspect.GetAttributeValue <DateTime>(ImporterAspect.ATTR_DATEADDED),
                Rating = Convert.ToSingle(albumAspect.GetAttributeValue <double>(AudioAlbumAspect.ATTR_TOTAL_RATING)),
                Artwork = ResourceAccessUtils.GetWebArtwork(item),
                //Composer = composers.Cast<string>().ToList()
            });
        }
        internal static WebRecordingBasic RecordingBasic(MediaItem item)
        {
            MediaItemAspect recordingAspect = item.GetAspect(RecordingAspect.Metadata);

            string genre = string.Empty;

            if (MediaItemAspect.TryGetAttribute(item.Aspects, GenreAspect.ATTR_GENRE, out List <string> genres))
            {
                genre = string.Join(", ", genres);
            }

            return(new WebRecordingBasic
            {
                Id = item.MediaItemId.ToString(),
                Title = (string)item.GetAspect(MediaAspect.Metadata).GetAttributeValue(MediaAspect.ATTR_TITLE),
                ChannelName = (string)recordingAspect.GetAttributeValue(RecordingAspect.ATTR_CHANNEL),
                Description = (string)item.GetAspect(VideoAspect.Metadata).GetAttributeValue(VideoAspect.ATTR_STORYPLOT),
                StartTime = (DateTime)(recordingAspect.GetAttributeValue(RecordingAspect.ATTR_STARTTIME) ?? DateTime.Now),
                EndTime = (DateTime)(recordingAspect.GetAttributeValue(RecordingAspect.ATTR_ENDTIME) ?? DateTime.Now),
                Genre = genre,
                TimesWatched = Convert.ToInt32(item.UserData.FirstOrDefault(d => d.Key == UserDataKeysKnown.KEY_PLAY_COUNT).Value ?? "0"),
                FileName = ResourceAccessUtils.GetPaths(item).FirstOrDefault(),
            });
        }
Beispiel #11
0
        internal static WebMusicArtistDetailed MusicArtistDetailed(MediaItem item)
        {
            WebMusicArtistBasic webMusicArtistBasic = MusicArtistBasic(item);

            MediaItemAspect personAspect = item.GetAspect(PersonAspect.Metadata);

            return(new WebMusicArtistDetailed
            {
                HasAlbums = webMusicArtistBasic.HasAlbums,
                Id = webMusicArtistBasic.Id,
                Title = webMusicArtistBasic.Title,
                Artwork = webMusicArtistBasic.Artwork,
                Biography = personAspect.GetAttributeValue <string>(PersonAspect.ATTR_BIOGRAPHY),
            });
        }
        internal static WebPictureBasic PictureBasic(MediaItem item)
        {
            MediaItemAspect imageAspects = item.GetAspect(ImageAspect.Metadata);

            WebPictureBasic webPictureBasic = new WebPictureBasic
            {
                Type      = WebMediaType.Picture,
                DateAdded = (DateTime)item.GetAspect(ImporterAspect.Metadata).GetAttributeValue(ImporterAspect.ATTR_DATEADDED),
                Id        = item.MediaItemId.ToString(),
                Title     = (string)item.GetAspect(MediaAspect.Metadata).GetAttributeValue(MediaAspect.ATTR_TITLE),
                DateTaken = (DateTime)item.GetAspect(MediaAspect.Metadata)[MediaAspect.ATTR_RECORDINGTIME],
                Path      = ResourceAccessUtils.GetPaths(item),
                Artwork   = ResourceAccessUtils.GetWebArtwork(item),
            };

            webPictureBasic.Categories = new[]
            {
                new WebCategory {
                    Title = (webPictureBasic.DateTaken).ToString("yyyy"), Id = (webPictureBasic.DateTaken).ToString("yyyy")
                }
            };

            return(webPictureBasic);
        }
Beispiel #13
0
        internal static List <WebActor> MovieActors(MediaItem item)
        {
            List <WebActor> output = new List <WebActor>();

            var movieActors = (HashSet <object>)item.GetAspect(VideoAspect.Metadata)[VideoAspect.ATTR_ACTORS];

            if (movieActors != null)
            {
                output.AddRange(movieActors.Select(actor => new WebActor
                {
                    Title = actor.ToString()
                }));
            }

            return(output);
        }
Beispiel #14
0
        internal static WebMusicArtistBasic MusicArtistBasic(MediaItem item)
        {
            MediaItemAspect artistAspect = item.GetAspect(PersonAspect.Metadata);

            bool hasAlbum = false;

            if (MediaItemAspect.TryGetAspects(item.Aspects, RelationshipAspect.Metadata, out var relationAspects))
            {
                hasAlbum = relationAspects.Any(r => (Guid?)r[RelationshipAspect.ATTR_LINKED_ROLE] == AudioAlbumAspect.ROLE_ALBUM);
            }

            return(new WebMusicArtistBasic
            {
                HasAlbums = hasAlbum,
                Id = item.MediaItemId.ToString(),
                Title = artistAspect.GetAttributeValue <string>(PersonAspect.ATTR_PERSON_NAME),
                Artwork = ResourceAccessUtils.GetWebArtwork(item)
            });
        }
Beispiel #15
0
        public static Task <WebIntResult> ProcessAsync(IOwinContext context, string id)
        {
            ISet <Guid> necessaryMIATypes = new HashSet <Guid>();

            necessaryMIATypes.Add(MediaAspect.ASPECT_ID);
            necessaryMIATypes.Add(SeasonAspect.ASPECT_ID);

            // this is the MediaItem for the season
            MediaItem item = MediaLibraryAccess.GetMediaItemById(context, Guid.Parse(id), necessaryMIATypes, null);

            if (item == null)
            {
                throw new NotFoundException(String.Format("GetTVEpisodeCountForSeason: No MediaItem found with id: {0}", id));
            }

            int count = item.GetAspect(SeasonAspect.Metadata).GetAttributeValue <int>(SeasonAspect.ATTR_AVAILABLE_EPISODES);

            return(Task.FromResult(new WebIntResult {
                Result = count
            }));
        }
        internal static WebTVShowBasic TVShowBasic(IOwinContext context, MediaItem item)
        {
            ISet <Guid> necessaryMIATypespisodes = new HashSet <Guid>();

            necessaryMIATypespisodes.Add(MediaAspect.ASPECT_ID);
            necessaryMIATypespisodes.Add(EpisodeAspect.ASPECT_ID);

            IFilter unwatchedEpisodeFilter = BooleanCombinationFilter.CombineFilters(BooleanOperator.And,
                                                                                     new RelationshipFilter(EpisodeAspect.ROLE_EPISODE, SeriesAspect.ROLE_SERIES, item.MediaItemId),
                                                                                     new RelationalUserDataFilter(Guid.Empty, UserDataKeysKnown.KEY_PLAY_PERCENTAGE, RelationalOperator.LT,
                                                                                                                  UserDataKeysKnown.GetSortablePlayPercentageString(100), true));

            int unwatchedCount = MediaLibraryAccess.CountMediaItems(context, necessaryMIATypespisodes, unwatchedEpisodeFilter);

            var              mediaAspect    = item.GetAspect(MediaAspect.Metadata);
            var              seriesAspect   = item.GetAspect(SeriesAspect.Metadata);
            var              importerAspect = item.GetAspect(ImporterAspect.Metadata);
            DateTime?        firstAired     = mediaAspect.GetAttributeValue <DateTime?>(MediaAspect.ATTR_RECORDINGTIME);
            IList <WebActor> actors         = seriesAspect.GetCollectionAttribute <string>(SeriesAspect.ATTR_ACTORS)?.Distinct().Select(a => new WebActor(a)).ToList() ?? new List <WebActor>();
            WebArtwork       aw             = new WebArtwork();

            var show = new WebTVShowBasic()
            {
                Id                    = item.MediaItemId.ToString(),
                Title                 = seriesAspect.GetAttributeValue <string>(SeriesAspect.ATTR_SERIES_NAME),
                DateAdded             = importerAspect.GetAttributeValue <DateTime>(ImporterAspect.ATTR_DATEADDED),
                EpisodeCount          = seriesAspect.GetAttributeValue <int>(SeriesAspect.ATTR_AVAILABLE_EPISODES),
                SeasonCount           = seriesAspect.GetAttributeValue <int>(SeriesAspect.ATTR_AVAILABLE_SEASONS),
                Rating                = Convert.ToSingle(seriesAspect.GetAttributeValue <double>(SeriesAspect.ATTR_TOTAL_RATING)),
                ContentRating         = seriesAspect.GetAttributeValue <string>(SeriesAspect.ATTR_CERTIFICATION),
                Actors                = actors,
                UnwatchedEpisodeCount = unwatchedCount,
                Year                  = firstAired.HasValue ? firstAired.Value.Year : 0,
            };

            IList <MediaItemAspect> genres;

            if (item.Aspects.TryGetValue(GenreAspect.ASPECT_ID, out genres))
            {
                show.Genres = genres.Select(g => g.GetAttributeValue <string>(GenreAspect.ATTR_GENRE)).ToList();
            }

            string tvDbId;

            MediaItemAspect.TryGetExternalAttribute(item.Aspects, ExternalIdentifierAspect.SOURCE_TVDB, ExternalIdentifierAspect.TYPE_SERIES, out tvDbId);
            if (tvDbId != null)
            {
                show.ExternalId.Add(new WebExternalId {
                    Site = "TVDB", Id = tvDbId
                });
            }
            string imdbId;

            MediaItemAspect.TryGetExternalAttribute(item.Aspects, ExternalIdentifierAspect.SOURCE_IMDB, ExternalIdentifierAspect.TYPE_SERIES, out imdbId);
            if (imdbId != null)
            {
                show.ExternalId.Add(new WebExternalId {
                    Site = "IMDB", Id = imdbId
                });
            }

            return(show);
        }