Exemplo n.º 1
0
        /// <summary>
        /// Internal function that return valid image file path on server that exist
        /// </summary>
        /// <param name="id">image id</param>
        /// <param name="type">image type</param>
        /// <param name="thumb">thumb mode</param>
        /// <returns>string</returns>
        internal string GetImagePath(int type, int id, bool thumb)
        {
            ImageEntityType imageType = (ImageEntityType)type;
            string          path;

            switch (imageType)
            {
            // 1
            case ImageEntityType.AniDB_Cover:
                SVR_AniDB_Anime anime = RepoFactory.AniDB_Anime.GetByAnimeID(id);
                if (anime == null)
                {
                    return(null);
                }
                path = anime.PosterPath;
                if (File.Exists(path))
                {
                    return(path);
                }
                else
                {
                    path = string.Empty;
                    logger.Trace("Could not find AniDB_Cover image: {0}", anime.PosterPath);
                }
                break;

            // 2
            case ImageEntityType.AniDB_Character:
                AniDB_Character chr = RepoFactory.AniDB_Character.GetByCharID(id);
                if (chr == null)
                {
                    return(null);
                }
                path = chr.GetPosterPath();
                if (File.Exists(path))
                {
                    return(path);
                }
                else
                {
                    path = string.Empty;
                    logger.Trace("Could not find AniDB_Character image: {0}", chr.GetPosterPath());
                }
                break;

            // 3
            case ImageEntityType.AniDB_Creator:
                AniDB_Seiyuu creator = RepoFactory.AniDB_Seiyuu.GetBySeiyuuID(id);
                if (creator == null)
                {
                    return(null);
                }
                path = creator.GetPosterPath();
                if (File.Exists(path))
                {
                    return(path);
                }
                else
                {
                    path = string.Empty;
                    logger.Trace("Could not find AniDB_Creator image: {0}", creator.GetPosterPath());
                }
                break;

            // 4
            case ImageEntityType.TvDB_Banner:
                TvDB_ImageWideBanner wideBanner = RepoFactory.TvDB_ImageWideBanner.GetByID(id);
                if (wideBanner == null)
                {
                    return(null);
                }
                path = wideBanner.GetFullImagePath();
                if (File.Exists(path))
                {
                    return(path);
                }
                else
                {
                    path = string.Empty;
                    logger.Trace("Could not find TvDB_Banner image: {0}", wideBanner.GetFullImagePath());
                }
                break;

            // 5
            case ImageEntityType.TvDB_Cover:
                TvDB_ImagePoster poster = RepoFactory.TvDB_ImagePoster.GetByID(id);
                if (poster == null)
                {
                    return(null);
                }
                path = poster.GetFullImagePath();
                if (File.Exists(path))
                {
                    return(path);
                }
                else
                {
                    path = string.Empty;
                    logger.Trace("Could not find TvDB_Cover image: {0}", poster.GetFullImagePath());
                }
                break;

            // 6
            case ImageEntityType.TvDB_Episode:
                TvDB_Episode ep = RepoFactory.TvDB_Episode.GetByID(id);
                if (ep == null)
                {
                    return(null);
                }
                path = ep.GetFullImagePath();
                if (File.Exists(path))
                {
                    return(path);
                }
                else
                {
                    path = string.Empty;
                    logger.Trace("Could not find TvDB_Episode image: {0}", ep.GetFullImagePath());
                }
                break;

            // 7
            case ImageEntityType.TvDB_FanArt:
                TvDB_ImageFanart fanart = RepoFactory.TvDB_ImageFanart.GetByID(id);
                if (fanart == null)
                {
                    return(null);
                }
                if (thumb)
                {
                    //ratio
                    path = fanart.GetFullThumbnailPath();
                    if (File.Exists(path))
                    {
                        return(path);
                    }
                    path = string.Empty;
                    logger.Trace("Could not find TvDB_FanArt image: {0}", fanart.GetFullThumbnailPath());
                }
                else
                {
                    path = fanart.GetFullImagePath();
                    if (File.Exists(path))
                    {
                        return(path);
                    }
                    path = string.Empty;
                    logger.Trace("Could not find TvDB_FanArt image: {0}", fanart.GetFullImagePath());
                }
                break;

            // 8
            case ImageEntityType.MovieDB_FanArt:
                MovieDB_Fanart mFanart = RepoFactory.MovieDB_Fanart.GetByID(id);
                if (mFanart == null)
                {
                    return(null);
                }
                mFanart = RepoFactory.MovieDB_Fanart.GetByOnlineID(mFanart.URL);
                if (mFanart == null)
                {
                    return(null);
                }
                path = mFanart.GetFullImagePath();
                if (File.Exists(path))
                {
                    return(path);
                }
                else
                {
                    path = string.Empty;
                    logger.Trace("Could not find MovieDB_FanArt image: {0}", mFanart.GetFullImagePath());
                }
                break;

            // 9
            case ImageEntityType.MovieDB_Poster:
                MovieDB_Poster mPoster = RepoFactory.MovieDB_Poster.GetByID(id);
                if (mPoster == null)
                {
                    return(null);
                }
                mPoster = RepoFactory.MovieDB_Poster.GetByOnlineID(mPoster.URL);
                if (mPoster == null)
                {
                    return(null);
                }
                path = mPoster.GetFullImagePath();
                if (File.Exists(path))
                {
                    return(path);
                }
                else
                {
                    path = string.Empty;
                    logger.Trace("Could not find MovieDB_Poster image: {0}", mPoster.GetFullImagePath());
                }
                break;

            case ImageEntityType.Character:
                AnimeCharacter character = RepoFactory.AnimeCharacter.GetByID(id);
                if (character == null)
                {
                    return(null);
                }
                path = ImageUtils.GetBaseAniDBCharacterImagesPath() + Path.DirectorySeparatorChar + character.ImagePath;
                if (File.Exists(path))
                {
                    return(path);
                }
                else
                {
                    path = string.Empty;
                    logger.Trace("Could not find Character image: {0}",
                                 ImageUtils.GetBaseAniDBCharacterImagesPath() + Path.DirectorySeparatorChar + character.ImagePath);
                }
                break;

            case ImageEntityType.Staff:
                var staff = RepoFactory.AnimeStaff.GetByID(id);
                if (staff == null)
                {
                    return(null);
                }
                path = ImageUtils.GetBaseAniDBCreatorImagesPath() + Path.DirectorySeparatorChar + staff.ImagePath;
                if (File.Exists(path))
                {
                    return(path);
                }
                else
                {
                    path = string.Empty;
                    logger.Trace("Could not find Staff image: {0}",
                                 ImageUtils.GetBaseAniDBCreatorImagesPath() + Path.DirectorySeparatorChar + staff.ImagePath);
                }
                break;

            default:
                path = string.Empty;
                break;
            }

            return(path);
        }
Exemplo n.º 2
0
        private string GetFileName(ImageDownloadRequest req, bool thumbNailOnly)
        {
            switch (req.ImageType)
            {
            case JMMImageType.AniDB_Cover:
                SVR_AniDB_Anime anime = req.ImageData as SVR_AniDB_Anime;
                return(anime.PosterPath);

            case JMMImageType.TvDB_Episode:
                TvDB_Episode ep = req.ImageData as TvDB_Episode;
                return(ep.GetFullImagePath());

            case JMMImageType.TvDB_FanArt:
                TvDB_ImageFanart fanart = req.ImageData as TvDB_ImageFanart;
                if (thumbNailOnly)
                {
                    return(fanart.GetFullThumbnailPath());
                }
                else
                {
                    return(fanart.GetFullImagePath());
                }

            case JMMImageType.TvDB_Cover:
                TvDB_ImagePoster poster = req.ImageData as TvDB_ImagePoster;
                return(poster.GetFullImagePath());

            case JMMImageType.TvDB_Banner:
                TvDB_ImageWideBanner wideBanner = req.ImageData as TvDB_ImageWideBanner;
                return(wideBanner.GetFullImagePath());

            case JMMImageType.MovieDB_Poster:
                MovieDB_Poster moviePoster = req.ImageData as MovieDB_Poster;
                return(moviePoster.GetFullImagePath());

            case JMMImageType.MovieDB_FanArt:
                MovieDB_Fanart movieFanart = req.ImageData as MovieDB_Fanart;
                return(movieFanart.GetFullImagePath());

            case JMMImageType.Trakt_Poster:
                Trakt_ImagePoster traktPoster = req.ImageData as Trakt_ImagePoster;
                return(traktPoster.GetFullImagePath());

            case JMMImageType.Trakt_Fanart:
                Trakt_ImageFanart traktFanart = req.ImageData as Trakt_ImageFanart;
                return(traktFanart.GetFullImagePath());

            case JMMImageType.Trakt_Friend:
                Trakt_Friend traktFriend = req.ImageData as Trakt_Friend;
                return(traktFriend.GetFullImagePath());

            case JMMImageType.Trakt_Episode:
                Trakt_Episode traktEp = req.ImageData as Trakt_Episode;
                return(traktEp.GetFullImagePath());

            case JMMImageType.AniDB_Character:
                AniDB_Character chr = req.ImageData as AniDB_Character;
                return(chr.GetPosterPath());

            case JMMImageType.AniDB_Creator:
                AniDB_Seiyuu creator = req.ImageData as AniDB_Seiyuu;
                return(creator.GetPosterPath());

            default:
                return("");
            }
        }
Exemplo n.º 3
0
        public string GetImagePath(int imageId, int imageType, bool?thumnbnailOnly)
        {
            ImageEntityType it = (ImageEntityType)imageType;

            switch (it)
            {
            case ImageEntityType.AniDB_Cover:
                SVR_AniDB_Anime anime = RepoFactory.AniDB_Anime.GetByAnimeID(imageId);
                if (anime == null)
                {
                    return(null);
                }
                if (File.Exists(anime.PosterPath))
                {
                    return(anime.PosterPath);
                }
                else
                {
                    logger.Trace("Could not find AniDB_Cover image: {0}", anime.PosterPath);
                    return(string.Empty);
                }

            case ImageEntityType.AniDB_Character:
                AniDB_Character chr = RepoFactory.AniDB_Character.GetByID(imageId);
                if (chr == null)
                {
                    return(null);
                }
                if (File.Exists(chr.GetPosterPath()))
                {
                    return(chr.GetPosterPath());
                }
                else
                {
                    logger.Trace("Could not find AniDB_Character image: {0}", chr.GetPosterPath());
                    return(string.Empty);
                }

            case ImageEntityType.AniDB_Creator:
                AniDB_Seiyuu creator = RepoFactory.AniDB_Seiyuu.GetByID(imageId);
                if (creator == null)
                {
                    return(string.Empty);
                }
                if (File.Exists(creator.GetPosterPath()))
                {
                    return(creator.GetPosterPath());
                }
                else
                {
                    logger.Trace("Could not find AniDB_Creator image: {0}", creator.GetPosterPath());
                    return(string.Empty);
                }

            case ImageEntityType.TvDB_Cover:
                TvDB_ImagePoster poster = RepoFactory.TvDB_ImagePoster.GetByID(imageId);
                if (poster == null)
                {
                    return(null);
                }
                if (File.Exists(poster.GetFullImagePath()))
                {
                    return(poster.GetFullImagePath());
                }
                else
                {
                    logger.Trace("Could not find TvDB_Cover image: {0}", poster.GetFullImagePath());
                    return(string.Empty);
                }

            case ImageEntityType.TvDB_Banner:
                TvDB_ImageWideBanner wideBanner = RepoFactory.TvDB_ImageWideBanner.GetByID(imageId);
                if (wideBanner == null)
                {
                    return(null);
                }
                if (File.Exists(wideBanner.GetFullImagePath()))
                {
                    return(wideBanner.GetFullImagePath());
                }
                else
                {
                    logger.Trace("Could not find TvDB_Banner image: {0}", wideBanner.GetFullImagePath());
                    return(string.Empty);
                }

            case ImageEntityType.TvDB_Episode:
                TvDB_Episode ep = RepoFactory.TvDB_Episode.GetByID(imageId);
                if (ep == null)
                {
                    return(null);
                }
                if (File.Exists(ep.GetFullImagePath()))
                {
                    return(ep.GetFullImagePath());
                }
                else
                {
                    logger.Trace("Could not find TvDB_Episode image: {0}", ep.GetFullImagePath());
                    return(string.Empty);
                }

            case ImageEntityType.TvDB_FanArt:
                TvDB_ImageFanart fanart = RepoFactory.TvDB_ImageFanart.GetByID(imageId);
                if (fanart == null)
                {
                    return(null);
                }
                if (thumnbnailOnly.HasValue && thumnbnailOnly.Value)
                {
                    if (File.Exists(fanart.GetFullThumbnailPath()))
                    {
                        return(fanart.GetFullThumbnailPath());
                    }
                    else
                    {
                        logger.Trace("Could not find TvDB_FanArt image: {0}", fanart.GetFullThumbnailPath());
                        return(string.Empty);
                    }
                }
                else
                {
                    if (File.Exists(fanart.GetFullImagePath()))
                    {
                        return(fanart.GetFullImagePath());
                    }
                    else
                    {
                        logger.Trace("Could not find TvDB_FanArt image: {0}", fanart.GetFullImagePath());
                        return(string.Empty);
                    }
                }

            case ImageEntityType.MovieDB_Poster:
                MovieDB_Poster mPoster = RepoFactory.MovieDB_Poster.GetByID(imageId);
                if (mPoster == null)
                {
                    return(null);
                }

                // now find only the original size
                mPoster = RepoFactory.MovieDB_Poster.GetByOnlineID(mPoster.URL);
                if (mPoster == null)
                {
                    return(null);
                }
                if (File.Exists(mPoster.GetFullImagePath()))
                {
                    return(mPoster.GetFullImagePath());
                }
                else
                {
                    logger.Trace("Could not find MovieDB_Poster image: {0}", mPoster.GetFullImagePath());
                    return(string.Empty);
                }

            case ImageEntityType.MovieDB_FanArt:
                MovieDB_Fanart mFanart = RepoFactory.MovieDB_Fanart.GetByID(imageId);
                if (mFanart == null)
                {
                    return(null);
                }
                mFanart = RepoFactory.MovieDB_Fanart.GetByOnlineID(mFanart.URL);
                if (mFanart == null)
                {
                    return(null);
                }
                if (File.Exists(mFanart.GetFullImagePath()))
                {
                    return(mFanart.GetFullImagePath());
                }
                else
                {
                    logger.Trace("Could not find MovieDB_FanArt image: {0}", mFanart.GetFullImagePath());
                    return(string.Empty);
                }

            default:
                return(string.Empty);
            }
        }