public static Task <IList <string> > ProcessAsync(IOwinContext context, WebMediaType mediatype, WebFileType filetype, string id) { if (id == null) { throw new BadRequestException("GetPathList: 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(SeriesAspect.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("GetPathList: No MediaItem found with id: {0}", id)); } var output = ResourceAccessUtils.GetPaths(item); return(System.Threading.Tasks.Task.FromResult(output)); }
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); }
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); }
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); }
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 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(), }); }
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); }