Exemplo n.º 1
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 <IList <WebRecordingBasic> > ProcessAsync(IOwinContext context, int start, int end, WebSortField?sort, WebSortOrder?order, string filter = null)
        {
            if (!ServiceRegistration.IsRegistered <ITvProvider>())
            {
                throw new BadRequestException("GetRecordingsByRange: ITvProvider not found");
            }

            IList <MediaItem> items = MediaLibraryAccess.GetMediaItemsByAspect(context, BasicNecessaryMIATypeIds, BasicOptionalMIATypeIds);

            List <WebRecordingBasic> output = items.Select(item => RecordingBasic(item)).ToList();

            // sort and filter
            if (sort != null && order != null)
            {
                output = output.Filter(filter).SortRecordingList(sort, order).ToList();
            }
            else
            {
                output = output.Filter(filter).ToList();
            }

            // Get Range
            output = output.TakeRange(start, end).ToList();

            return(System.Threading.Tasks.Task.FromResult <IList <WebRecordingBasic> >(output));
        }
        public static Task <WebItemSupportStatus> ProcessAsync(IOwinContext context, WebMediaType type, int?provider, string itemId, int?offset)
        {
            if (itemId == null)
            {
                throw new BadRequestException("GetItemSupportStatus: itemId 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, itemId, necessaryMIATypes, optionalMIATypes);

            bool result = item != null;

            WebItemSupportStatus webItemSupportStatus = new WebItemSupportStatus
            {
                Supported = result,
                Reason    = ""
            };

            return(Task.FromResult(webItemSupportStatus));
        }
Exemplo n.º 4
0
        public static Task <IList <WebGenre> > ProcessAsync(IOwinContext context, WebSortField?sort, WebSortOrder?order)
        {
            ISet <Guid> necessaryMIATypes = new HashSet <Guid>();

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

            HomogenousMap items = MediaLibraryAccess.GetGroups(context, necessaryMIATypes, GenreAspect.ATTR_GENRE);

            if (items.Count == 0)
            {
                return(Task.FromResult <IList <WebGenre> >(new List <WebGenre>()));
            }

            var output = (from item in items where item.Key is string select new WebGenre {
                Title = item.Key.ToString()
            });

            // sort
            if (sort != null && order != null)
            {
                output = output.SortWebGenre(sort, order);
            }

            return(Task.FromResult <IList <WebGenre> >(output.ToList()));
        }
Exemplo n.º 5
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,
            });
        }
Exemplo n.º 6
0
        public static Task <WebIntResult> ProcessAsync(IOwinContext context, string filter)
        {
            ISet <Guid> necessaryMIATypes = new HashSet <Guid>();

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

            var output = new List <WebTVShowBasic>();

            IList <MediaItem> items = MediaLibraryAccess.GetMediaItemsByAspect(context, necessaryMIATypes, null);

            if (items.Count == 0)
            {
                return(System.Threading.Tasks.Task.FromResult(new WebIntResult {
                    Result = output.Count
                }));
            }

            foreach (var item in items)
            {
                var            seriesAspect   = item.GetAspect(SeriesAspect.Metadata);
                WebTVShowBasic webTVShowBasic = new WebTVShowBasic();
                webTVShowBasic.Title = (string)seriesAspect[SeriesAspect.ATTR_SERIES_NAME];

                output.Add(webTVShowBasic);
            }

            // Filter
            output = output.Filter(filter).ToList();
            return(System.Threading.Tasks.Task.FromResult(new WebIntResult {
                Result = output.Count
            }));
        }
Exemplo n.º 7
0
        public static Task <IList <WebTVSeasonBasic> > ProcessAsync(IOwinContext context, string id, string filter, WebSortField?sort, WebSortOrder?order)
        {
            // Get all seasons for this series
            IList <MediaItem> seasons = MediaLibraryAccess.GetMediaItemsByGroup(context, SeasonAspect.ROLE_SEASON, SeriesAspect.ROLE_SERIES, Guid.Parse(id), BasicNecessaryMIATypeIds, BasicOptionalMIATypeIds);

            if (seasons.Count == 0)
            {
                return(Task.FromResult <IList <WebTVSeasonBasic> >(new List <WebTVSeasonBasic>()));
            }

            var output = new List <WebTVSeasonBasic>();

            foreach (var season in seasons)
            {
                output.Add(TVSeasonBasic(context, season, Guid.Parse(id)));
            }

            // sort
            if (sort != null && order != null)
            {
                output = output.SortWebTVSeasonBasic(sort, order).ToList();
            }

            return(Task.FromResult <IList <WebTVSeasonBasic> >(output));
        }
Exemplo n.º 8
0
        public static Task <IList <WebActor> > ProcessAsync(IOwinContext context, string filter, WebSortField?sort, WebSortOrder?order)
        {
            ISet <Guid> necessaryMIATypes = new HashSet <Guid>();

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

            var items = MediaLibraryAccess.GetMediaItemsByGroup(context, PersonAspect.ROLE_ACTOR, MovieAspect.ROLE_MOVIE, Guid.Empty, necessaryMIATypes, null);

            if (items.Count == 0)
            {
                throw new BadRequestException("No Movies found");
            }

            var output = items.Select(mi => new WebActor(mi.GetAspect(PersonAspect.Metadata).GetAttributeValue <string>(PersonAspect.ATTR_PERSON_NAME)))
                         .Filter(filter);

            // sort and filter
            if (sort != null && order != null)
            {
                output = output.SortWebActor(sort, order);
            }

            return(System.Threading.Tasks.Task.FromResult <IList <WebActor> >(output.ToList()));
        }
Exemplo n.º 9
0
        public static Task <IList <WebMusicTrackDetailed> > ProcessAsync(IOwinContext context, string id, string filter, WebSortField?sort, WebSortOrder?order)
        {
            if (id == null)
            {
                throw new BadRequestException("GetMusicTracksDetailedForAlbum: id is null");
            }

            IList <MediaItem> tracks = MediaLibraryAccess.GetMediaItemsByGroup(context, AudioAspect.ROLE_TRACK, AudioAlbumAspect.ROLE_ALBUM, Guid.Parse(id), BasicNecessaryMIATypeIds, BasicOptionalMIATypeIds);

            if (tracks.Count == 0)
            {
                return(Task.FromResult <IList <WebMusicTrackDetailed> >(new List <WebMusicTrackDetailed>()));
            }

            var output = tracks.Select(t => MusicTrackDetailed(t)).ToList();

            // sort
            if (sort != null && order != null)
            {
                output = output.SortWebMusicTrackBasic(sort, order).ToList();
            }

            // assign artists
            AssignArtists(context, output);

            return(Task.FromResult <IList <WebMusicTrackDetailed> >(output));
        }
Exemplo n.º 10
0
        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));
        }
Exemplo n.º 11
0
        public static Task <Stream> ProcessAsync(IOwinContext context, WebMediaType mediatype, WebFileType filetype, string id, int offset)
        {
            ISet <Guid> necessaryMIATypes = new HashSet <Guid>();

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

            MediaItem item = MediaLibraryAccess.GetMediaItemById(context, id, necessaryMIATypes, null);

            if (item == null)
            {
                throw new NotFoundException("RetrieveFile: no media item found");
            }

            var files = ResourceAccessUtils.GetResourcePaths(item);
            var ra    = GetResourceAccessor(files[offset]);
            IFileSystemResourceAccessor fsra = ra as IFileSystemResourceAccessor;

            if (fsra == null)
            {
                throw new InternalServerException("RetrieveFile: failed to create IFileSystemResourceAccessor");
            }

            return(fsra.OpenReadAsync());
        }
Exemplo n.º 12
0
        public static Task <IList <WebPlaylistItem> > ProcessAsync(IOwinContext context, string playlistId, string filter, WebSortField?sort, WebSortOrder?order)
        {
            // get the playlist
            PlaylistRawData playlistRawData = ServiceRegistration.Get <IMediaLibrary>().ExportPlaylist(Guid.Parse(playlistId));

            IFilter           searchFilter = new MediaItemIdFilter(playlistRawData.MediaItemIds);
            IList <MediaItem> items        = MediaLibraryAccess.Search(context, BasicNecessaryMIATypeIds, BasicOptionalMIATypeIds, searchFilter);

            if (items.Count == 0)
            {
                return(System.Threading.Tasks.Task.FromResult <IList <WebPlaylistItem> >(new List <WebPlaylistItem>()));
            }

            var tracks = items.Select(item => MusicTrackBasic(item))
                         .Filter(filter);

            // sort and filter
            if (sort != null && order != null)
            {
                tracks = tracks.SortWebMusicTrackBasic(sort, order);
            }

            var output = tracks.Select(t => new WebPlaylistItem(t));

            return(System.Threading.Tasks.Task.FromResult <IList <WebPlaylistItem> >(output.ToList()));
        }
Exemplo n.º 13
0
        public static async Task <bool> ProcessAsync(IOwinContext context, WebMediaType type, string id)
        {
            if (id == null)
            {
                throw new BadRequestException("GetImage: id is null");
            }

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

            necessaryMIATypes.Add(MediaAspect.ASPECT_ID);
            necessaryMIATypes.Add(ProviderResourceAspect.ASPECT_ID);
            necessaryMIATypes.Add(ImporterAspect.ASPECT_ID);
            necessaryMIATypes.Add(ImageAspect.ASPECT_ID);
            MediaItem item = MediaLibraryAccess.GetMediaItemById(context, id, necessaryMIATypes, null);

            var resourcePathStr = item.PrimaryResources[item.ActiveResourceLocatorIndex].GetAttributeValue(ProviderResourceAspect.ATTR_RESOURCE_ACCESSOR_PATH);
            var resourcePath    = ResourcePath.Deserialize(resourcePathStr.ToString());

            var ra = GetResourceAccessor(resourcePath);
            IFileSystemResourceAccessor fsra = ra as IFileSystemResourceAccessor;

            if (fsra == null)
            {
                throw new InternalServerException("GetImage: failed to create IFileSystemResourceAccessor");
            }

            using (var resourceStream = fsra.OpenRead())
            {
                // HTTP/1.1 RFC2616 section 14.25 'If-Modified-Since'
                if (!string.IsNullOrEmpty(context.Request.Headers["If-Modified-Since"]))
                {
                    DateTime lastRequest = DateTime.Parse(context.Request.Headers["If-Modified-Since"]);
                    if (lastRequest.CompareTo(fsra.LastChanged) <= 0)
                    {
                        context.Response.StatusCode = (int)HttpStatusCode.NotModified;
                    }
                }

                // HTTP/1.1 RFC2616 section 14.29 'Last-Modified'
                context.Response.Headers["Last-Modified"] = fsra.LastChanged.ToUniversalTime().ToString("r");

                string        byteRangesSpecifier = context.Request.Headers["Range"];
                IList <Range> ranges      = ParseByteRanges(byteRangesSpecifier, resourceStream.Length);
                bool          onlyHeaders = context.Request.Method == "HEAD" || context.Response.StatusCode == (int)HttpStatusCode.NotModified;
                if (ranges != null && ranges.Count > 0)
                {
                    // We only support last range
                    await SendRangeAsync(context, resourceStream, ranges[ranges.Count - 1], onlyHeaders);
                }
                else
                {
                    await SendWholeFileAsync(context, resourceStream, onlyHeaders);
                }
            }
            return(true);
        }
Exemplo n.º 14
0
        public static Task <WebPictureBasic> ProcessAsync(IOwinContext context, string id)
        {
            MediaItem item = MediaLibraryAccess.GetMediaItemById(context, Guid.Parse(id), BasicNecessaryMIATypeIds, BasicOptionalMIATypeIds);

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

            return(Task.FromResult(PictureBasic(item)));
        }
Exemplo n.º 15
0
        public static Task <WebTVShowBasic> ProcessAsync(IOwinContext context, string id)
        {
            MediaItem item = MediaLibraryAccess.GetMediaItemById(context, Guid.Parse(id), BasicNecessaryMIATypeIds, BasicOptionalMIATypeIds);

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

            return(Task.FromResult(TVShowBasic(context, item)));
        }
Exemplo n.º 16
0
        public static Task <WebRecordingBasic> ProcessAsync(IOwinContext context, string id)
        {
            if (!ServiceRegistration.IsRegistered <ITvProvider>())
            {
                throw new BadRequestException("GetRecordingById: ITvProvider not found");
            }

            MediaItem         item = MediaLibraryAccess.GetMediaItemById(context, Guid.Parse(id), BasicNecessaryMIATypeIds, BasicOptionalMIATypeIds);
            WebRecordingBasic webRecordingBasic = RecordingBasic(item);

            return(Task.FromResult(webRecordingBasic));
        }
Exemplo n.º 17
0
        public static Task <WebIntResult> ProcessAsync(IOwinContext context)
        {
            ISet <Guid> necessaryMIATypes = new HashSet <Guid>();

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

            int count = MediaLibraryAccess.CountMediaItems(context, necessaryMIATypes);

            return(Task.FromResult(new WebIntResult {
                Result = count
            }));
        }
Exemplo n.º 18
0
        public static Task <WebIntResult> ProcessAsync(IOwinContext context)
        {
            if (!ServiceRegistration.IsRegistered <ITvProvider>())
            {
                throw new BadRequestException("GetRecordingCount: ITvProvider not found");
            }

            IList <MediaItem> items = MediaLibraryAccess.GetMediaItemsByAspect(context, BasicNecessaryMIATypeIds, BasicOptionalMIATypeIds);

            return(Task.FromResult(new WebIntResult {
                Result = items.Count
            }));
        }
Exemplo n.º 19
0
        public static Task <WebTVEpisodeDetailed> ProcessAsync(IOwinContext context, string id)
        {
            MediaItem item = MediaLibraryAccess.GetMediaItemById(context, Guid.Parse(id), DetailedNecessaryMIATypeIds, DetailedOptionalMIATypeIds);

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

            WebTVEpisodeDetailed webTvEpisodeDetailed = EpisodeDetailed(item);

            return(Task.FromResult(webTvEpisodeDetailed));
        }
Exemplo n.º 20
0
        public static Task <WebMusicTrackDetailed> ProcessAsync(IOwinContext context, string id)
        {
            MediaItem item = MediaLibraryAccess.GetMediaItemById(context, Guid.Parse(id), BasicNecessaryMIATypeIds, BasicOptionalMIATypeIds);

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

            var track = MusicTrackDetailed(item);

            AssignArtists(context, new[] { track });

            return(Task.FromResult(track));
        }
Exemplo n.º 21
0
        public static Task <IList <WebPictureDetailed> > ProcessAsync(IOwinContext context, string id)
        {
            if (string.IsNullOrEmpty(id) || id.Length != 4)
            {
                throw new BadRequestException("GetPicturesDetailedByCategory: Couldn't convert id to year");
            }

            DateTime          start = new DateTime(Convert.ToInt32(id), 1, 1);
            DateTime          end   = new DateTime(Convert.ToInt32(id), 12, 31);
            IList <MediaItem> items = MediaLibraryAccess.GetMediaItemsByRecordingTime(context, start, end, BasicNecessaryMIATypeIds, BasicOptionalMIATypeIds);

            var output = items.Select(item => PictureDetailed(item)).ToList();

            return(Task.FromResult <IList <WebPictureDetailed> >(output));
        }
        public static Task <IList <WebCategory> > ProcessAsync(IOwinContext context)
        {
            IList <MediaItem> items = MediaLibraryAccess.GetMediaItemsByAspect(context, BasicNecessaryMIATypeIds, BasicOptionalMIATypeIds);

            if (items.Count == 0)
            {
                return(Task.FromResult <IList <WebCategory> >(new List <WebCategory>()));
            }

            var output = items.Select(i => (i.GetAspect(MediaAspect.Metadata).GetAttributeValue <DateTime>(MediaAspect.ATTR_RECORDINGTIME)).ToString("yyyy")).
                         Distinct().Select(y => new WebCategory {
                Id = y, Title = y
            }).ToList();

            return(Task.FromResult <IList <WebCategory> >(output));
        }
Exemplo n.º 23
0
        public static Task <WebMusicAlbumBasic> ProcessAsync(IOwinContext context, string id)
        {
            if (id == null)
            {
                throw new BadRequestException("GetMusicTrackBasicById: id is null");
            }

            MediaItem item = MediaLibraryAccess.GetMediaItemById(context, Guid.Parse(id), BasicNecessaryMIATypeIds, BasicOptionalMIATypeIds);

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

            return(Task.FromResult(MusicAlbumBasic(item)));
        }
Exemplo n.º 24
0
        public static Task <WebBoolResult> ProcessAsync(IOwinContext context, string id)
        {
            if (!ServiceRegistration.IsRegistered <ITvProvider>())
            {
                throw new BadRequestException("DeleteRecording: ITvProvider not found");
            }

            MediaItem item = MediaLibraryAccess.GetMediaItemById(context, Guid.Parse(id), BasicNecessaryMIATypeIds, BasicOptionalMIATypeIds);

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

            return(System.Threading.Tasks.Task.FromResult(new WebBoolResult {
                Result = MediaLibraryAccess.Delete(context, item)
            }));
        }
Exemplo n.º 25
0
        public static Task <WebRecordingFileInfo> ProcessAsync(IOwinContext context, string id)
        {
            ISet <Guid> necessaryMIATypes = new HashSet <Guid>();

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

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

            if (item == null)
            {
                throw new BadRequestException("GetRecordingFileInfo: no media item found");
            }

            var resourcePathStr = item.PrimaryProviderResourcePath();
            var resourcePath    = ResourcePath.Deserialize(resourcePathStr.ToString());

            var ra = GetResourceAccessor(resourcePath);
            IFileSystemResourceAccessor fsra = ra as IFileSystemResourceAccessor;

            if (fsra == null)
            {
                throw new InternalServerException("GetRecordingFileInfo: failed to create IFileSystemResourceAccessor");
            }

            WebRecordingFileInfo webFileInfo = new WebRecordingFileInfo
            {
                Exists           = fsra.Exists,
                Extension        = fsra.Path.Split('.').Last(),
                IsLocalFile      = true,
                IsReadOnly       = true,
                LastAccessTime   = DateTime.Now,
                LastModifiedTime = fsra.LastChanged,
                Name             = fsra.ResourceName,
                OnNetworkDrive   = false,
                Path             = resourcePath.FileName,
                Size             = fsra.Size,
            };

            return(Task.FromResult(webFileInfo));
        }
Exemplo n.º 26
0
        public static Task <IList <WebTVEpisodeBasic> > ProcessAsync(IOwinContext context, WebSortField?sort, WebSortOrder?order)
        {
            IList <MediaItem> items = MediaLibraryAccess.GetMediaItemsByAspect(context, BasicNecessaryMIATypeIds, BasicOptionalMIATypeIds, null);

            if (items.Count == 0)
            {
                return(Task.FromResult <IList <WebTVEpisodeBasic> >(new List <WebTVEpisodeBasic>()));
            }

            var output = items.Select(item => EpisodeBasic(item));

            // sort
            if (sort != null && order != null)
            {
                output = output.SortWebTVEpisodeBasic(sort, order);
            }

            return(Task.FromResult <IList <WebTVEpisodeBasic> >(output.ToList()));
        }
        public static Task <IList <WebMusicArtistBasic> > ProcessAsync(IOwinContext context, string filter, WebSortField?sort, WebSortOrder?order)
        {
            var items = MediaLibraryAccess.GetMediaItemsByGroup(context, PersonAspect.ROLE_ARTIST, AudioAspect.ROLE_TRACK, Guid.Empty, BasicNecessaryMIATypeIds, BasicOptionalMIATypeIds);

            if (items.Count == 0)
            {
                return(System.Threading.Tasks.Task.FromResult <IList <WebMusicArtistBasic> >(new List <WebMusicArtistBasic>()));
            }

            var output = items.Select(mi => MusicArtistBasic(mi)).Filter(filter);

            // sort and filter
            if (sort != null && order != null)
            {
                output = output.SortWebMusicArtistBasic(sort, order);
            }

            return(System.Threading.Tasks.Task.FromResult <IList <WebMusicArtistBasic> >(output.ToList()));
        }
Exemplo n.º 28
0
        public static Task <IList <WebMovieBasic> > ProcessAsync(IOwinContext context, string filter, WebSortField?sort, WebSortOrder?order)
        {
            IList <MediaItem> items = MediaLibraryAccess.GetMediaItemsByAspect(context, BasicNecessaryMIATypeIds, BasicOptionalMIATypeIds, null);

            if (items.Count == 0)
            {
                return(System.Threading.Tasks.Task.FromResult <IList <WebMovieBasic> >(new List <WebMovieBasic>()));
            }

            var output = items.Select(item => MovieBasic(item))
                         .Filter(filter);

            // sort and filter
            if (sort != null && order != null)
            {
                output = output.Filter(filter).SortWebMovieBasic(sort, order);
            }

            return(System.Threading.Tasks.Task.FromResult <IList <WebMovieBasic> >(output.ToList()));
        }
Exemplo n.º 29
0
        public static Task <IList <WebTVEpisodeBasic> > ProcessAsync(IOwinContext context, string id, WebSortField?sort, WebSortOrder?order)
        {
            // Get all episodes for this season
            IList <MediaItem> episodes = MediaLibraryAccess.GetMediaItemsByGroup(context, EpisodeAspect.ROLE_EPISODE, SeasonAspect.ROLE_SEASON, Guid.Parse(id), BasicNecessaryMIATypeIds, BasicOptionalMIATypeIds);

            if (episodes.Count == 0)
            {
                return(Task.FromResult <IList <WebTVEpisodeBasic> >(new List <WebTVEpisodeBasic>()));
            }

            var output = episodes.Select(episode => EpisodeBasic(episode, null, Guid.Parse(id)));

            // sort
            if (sort != null && order != null)
            {
                output = output.SortWebTVEpisodeBasic(sort, order);
            }

            return(Task.FromResult <IList <WebTVEpisodeBasic> >(output.ToList()));
        }
Exemplo n.º 30
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
            }));
        }