示例#1
0
        public static T ForItem <T>(T item, int?provider, ProviderType providerType) where T : WebObject
        {
            if (item == null)
            {
                return(null);
            }

            item.PID = ProviderHandler.GetProviderId(providerType, provider);
            if (item is IArtwork)
            {
                (item as IArtwork).Artwork = (item as IArtwork).Artwork.Select(x => new WebArtwork()
                {
                    Offset   = x.Offset,
                    Type     = x.Type,
                    Filetype = x.Filetype,
                    Id       = x.Id,
                    Rating   = x.Rating
                }).ToList();
            }

            if (item is ICategorySortable)
            {
                (item as ICategorySortable).Categories = (item as ICategorySortable).Categories.Select(x => new WebCategory()
                {
                    Id    = x.Id,
                    PID   = item.PID,
                    Title = x.Title
                }).ToList();
            }

            return(item);
        }
示例#2
0
        public WebMediaServiceDescription GetServiceDescription()
        {
            return(new WebMediaServiceDescription()
            {
                MovieApiVersion = MOVIE_API,
                MusicApiVersion = MUSIC_API,
                PicturesApiVersion = PICTURES_API,
                TvShowsApiVersion = TVSHOWS_API,
                FilesystemApiVersion = FILESYSTEM_API,

                ServiceVersion = VersionUtil.GetVersionName(),

                AvailableFileSystemLibraries = FileSystemLibraries.GetAllAsBackendProvider(),
                AvailableMovieLibraries = MovieLibraries.GetAllAsBackendProvider(),
                AvailableMusicLibraries = MusicLibraries.GetAllAsBackendProvider(),
                AvailablePictureLibraries = PictureLibraries.GetAllAsBackendProvider(),
                AvailableTvShowLibraries = TVShowLibraries.GetAllAsBackendProvider(),

                DefaultFileSystemLibrary = ProviderHandler.GetDefaultProvider(ProviderType.Filesystem),
                DefaultMovieLibrary = ProviderHandler.GetDefaultProvider(ProviderType.Movie),
                DefaultMusicLibrary = ProviderHandler.GetDefaultProvider(ProviderType.Music),
                DefaultPictureLibrary = ProviderHandler.GetDefaultProvider(ProviderType.Picture),
                DefaultTvShowLibrary = ProviderHandler.GetDefaultProvider(ProviderType.TVShow),
            });
        }
示例#3
0
        public static List <T> ForList <T>(IEnumerable <T> list, int?provider, ProviderType providerType) where T : WebObject
        {
            // special-case LazyQuery here again: execute the query just once instead of a lot of times
            var operList = list.ToList();

            if (operList.Count() == 0)
            {
                return(new List <T>());
            }

            int  realProvider = ProviderHandler.GetProviderId(providerType, provider);
            bool isArtwork    = operList.First() is IArtwork;

            List <T> retlist = new List <T>();

            foreach (T item in operList)
            {
                item.PID = realProvider;
                if (isArtwork)
                {
                    (item as IArtwork).Artwork = (item as IArtwork).Artwork.Select(x => new WebArtwork()
                    {
                        Offset   = x.Offset,
                        Type     = x.Type,
                        Filetype = x.Filetype,
                        Id       = x.Id,
                        Rating   = x.Rating
                    }).ToList();
                }
                retlist.Add(item);
            }

            return(retlist);
        }
示例#4
0
        public T GetValue(int?passedId)
        {
            int key = passedId.HasValue ? passedId.Value : ProviderHandler.GetDefaultProvider(type);

            if (!items.ContainsKey(key) || !items[key].Value.Supported)
            {
                Log.Error("Tried to get library for unknown id {0}", key);
                return(default(T));
            }

            return(items[key].Value);
        }
示例#5
0
        public T this[int?key]
        {
            get
            {
                int realKey = key.HasValue ? key.Value : ProviderHandler.GetDefaultProvider(type);

                if (!items.ContainsKey(realKey) || !items[realKey].Value.Supported)
                {
                    Log.Error("Tried to get library for unknown id {0}", key);
                    throw new MethodCallFailedException(String.Format("Tried to get library for unknown id {0}", key));
                }

                return(items[realKey].Value);
            }
        }
示例#6
0
        public static List <T> ForList <T>(IEnumerable <T> list, int?provider, ProviderType providerType) where T : WebObject
        {
            // do not error out on null result
            if (list == null)
            {
                return(null);
            }

            // special-case LazyQuery here again: execute the query just once instead of a lot of times
            var operList = list.ToList();

            if (operList.Count() == 0)
            {
                return(new List <T>());
            }

            int  realProvider = ProviderHandler.GetProviderId(providerType, provider);
            bool isArtwork    = operList.First() is IArtwork;
            bool isActors     = operList.First() is IActors;
            bool isGuestStars = operList.First() is IGuestStars;

            List <T> retlist = new List <T>();

            foreach (T item in operList)
            {
                item.PID = realProvider;

                if (isArtwork)
                {
                    (item as IArtwork).Artwork = (item as IArtwork).Artwork.Select(x => new WebArtwork()
                    {
                        Offset   = x.Offset,
                        Type     = x.Type,
                        Filetype = x.Filetype,
                        Id       = x.Id,
                        Rating   = x.Rating
                    })
                                                 .OrderByDescending(x => x.Rating)
                                                 .ToList();
                }

                if (isActors)
                {
                    (item as IActors).Actors = (item as IActors).Actors.Select(x => new WebActor()
                    {
                        PID   = realProvider,
                        Title = x.Title
                    }).ToList();
                }

                if (isGuestStars)
                {
                    (item as IGuestStars).GuestStars = (item as IGuestStars).GuestStars.Select(x => new WebActor()
                    {
                        PID   = realProvider,
                        Title = x.Title
                    }).ToList();
                }

                retlist.Add(item);
            }

            return(retlist);
        }