public static void Valid(this TvDB_ImageFanart fanart) { if (!File.Exists(fanart.GetFullImagePath()) || !File.Exists(fanart.GetFullThumbnailPath())) { //clean leftovers if (File.Exists(fanart.GetFullImagePath())) { File.Delete(fanart.GetFullImagePath()); } if (File.Exists(fanart.GetFullThumbnailPath())) { File.Delete(fanart.GetFullThumbnailPath()); } } }
private string GetFileName(ImageDownloadRequest req, bool thumbNailOnly) { switch (req.ImageType) { case ImageEntityType.AniDB_Cover: SVR_AniDB_Anime anime = req.ImageData as SVR_AniDB_Anime; return(anime.PosterPath); case ImageEntityType.TvDB_Episode: TvDB_Episode ep = req.ImageData as TvDB_Episode; return(ep.GetFullImagePath()); case ImageEntityType.TvDB_FanArt: TvDB_ImageFanart fanart = req.ImageData as TvDB_ImageFanart; if (thumbNailOnly) { return(fanart.GetFullThumbnailPath()); } else { return(fanart.GetFullImagePath()); } case ImageEntityType.TvDB_Cover: TvDB_ImagePoster poster = req.ImageData as TvDB_ImagePoster; return(poster.GetFullImagePath()); case ImageEntityType.TvDB_Banner: TvDB_ImageWideBanner wideBanner = req.ImageData as TvDB_ImageWideBanner; return(wideBanner.GetFullImagePath()); case ImageEntityType.MovieDB_Poster: MovieDB_Poster moviePoster = req.ImageData as MovieDB_Poster; return(moviePoster.GetFullImagePath()); case ImageEntityType.MovieDB_FanArt: MovieDB_Fanart movieFanart = req.ImageData as MovieDB_Fanart; return(movieFanart.GetFullImagePath()); case ImageEntityType.AniDB_Character: AniDB_Character chr = req.ImageData as AniDB_Character; return(chr.GetPosterPath()); case ImageEntityType.AniDB_Creator: AniDB_Seiyuu creator = req.ImageData as AniDB_Seiyuu; return(creator.GetPosterPath()); default: return(string.Empty); } }
/// <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 ReturnImagePath(int type, int id, bool thumb) { JMMImageType imageType = (JMMImageType)type; string path = ""; switch (imageType) { // 1 case JMMImageType.AniDB_Cover: SVR_AniDB_Anime anime = RepoFactory.AniDB_Anime.GetByAnimeID(id); if (anime == null) { return(null); } path = anime.PosterPath; if (Pri.LongPath.File.Exists(path)) { return(path); } else { path = ""; logger.Trace("Could not find AniDB_Cover image: {0}", anime.PosterPath); } break; // 2 case JMMImageType.AniDB_Character: AniDB_Character chr = RepoFactory.AniDB_Character.GetByCharID(id); if (chr == null) { return(null); } path = chr.GetPosterPath(); if (Pri.LongPath.File.Exists(path)) { return(path); } else { path = ""; logger.Trace("Could not find AniDB_Character image: {0}", chr.GetPosterPath()); } break; // 3 case JMMImageType.AniDB_Creator: AniDB_Seiyuu creator = RepoFactory.AniDB_Seiyuu.GetBySeiyuuID(id); if (creator == null) { return(null); } path = creator.GetPosterPath(); if (Pri.LongPath.File.Exists(path)) { return(path); } else { path = ""; logger.Trace("Could not find AniDB_Creator image: {0}", creator.GetPosterPath()); } break; // 4 case JMMImageType.TvDB_Banner: TvDB_ImageWideBanner wideBanner = RepoFactory.TvDB_ImageWideBanner.GetByID(id); if (wideBanner == null) { return(null); } path = wideBanner.GetFullImagePath(); if (Pri.LongPath.File.Exists(path)) { return(path); } else { path = ""; logger.Trace("Could not find TvDB_Banner image: {0}", wideBanner.GetFullImagePath()); } break; // 5 case JMMImageType.TvDB_Cover: TvDB_ImagePoster poster = RepoFactory.TvDB_ImagePoster.GetByID(id); if (poster == null) { return(null); } path = poster.GetFullImagePath(); if (Pri.LongPath.File.Exists(path)) { return(path); } else { path = ""; logger.Trace("Could not find TvDB_Cover image: {0}", poster.GetFullImagePath()); } break; // 6 case JMMImageType.TvDB_Episode: TvDB_Episode ep = RepoFactory.TvDB_Episode.GetByID(id); if (ep == null) { return(null); } path = ep.GetFullImagePath(); if (Pri.LongPath.File.Exists(path)) { return(path); } else { path = ""; logger.Trace("Could not find TvDB_Episode image: {0}", ep.GetFullImagePath()); } break; // 7 case JMMImageType.TvDB_FanArt: TvDB_ImageFanart fanart = RepoFactory.TvDB_ImageFanart.GetByID(id); if (fanart == null) { return(null); } if (thumb) { //ratio path = fanart.GetFullThumbnailPath(); if (Pri.LongPath.File.Exists(path)) { return(path); } else { path = ""; logger.Trace("Could not find TvDB_FanArt image: {0}", fanart.GetFullThumbnailPath()); } } else { path = fanart.GetFullImagePath(); if (Pri.LongPath.File.Exists(path)) { return(path); } else { path = ""; logger.Trace("Could not find TvDB_FanArt image: {0}", fanart.GetFullImagePath()); } } break; // 8 case JMMImageType.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 (Pri.LongPath.File.Exists(path)) { return(path); } else { path = ""; logger.Trace("Could not find MovieDB_FanArt image: {0}", mFanart.GetFullImagePath()); } break; // 9 case JMMImageType.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 (Pri.LongPath.File.Exists(path)) { return(path); } else { path = ""; logger.Trace("Could not find MovieDB_Poster image: {0}", mPoster.GetFullImagePath()); } break; // 10 case JMMImageType.Trakt_Poster: Trakt_ImagePoster tPoster = RepoFactory.Trakt_ImagePoster.GetByID(id); if (tPoster == null) { return(null); } path = tPoster.GetFullImagePath(); if (Pri.LongPath.File.Exists(path)) { return(path); } else { path = ""; logger.Trace("Could not find Trakt_Poster image: {0}", tPoster.GetFullImagePath()); } break; // 11 case JMMImageType.Trakt_Fanart: Trakt_ImageFanart tFanart = RepoFactory.Trakt_ImageFanart.GetByID(id); if (tFanart == null) { return(null); } path = tFanart.GetFullImagePath(); if (Pri.LongPath.File.Exists(path)) { return(path); } else { path = ""; logger.Trace("Could not find Trakt_Fanart image: {0}", tFanart.GetFullImagePath()); } break; // 12 + 16 case JMMImageType.Trakt_Episode: case JMMImageType.Trakt_WatchedEpisode: Trakt_Episode tEpisode = RepoFactory.Trakt_Episode.GetByID(id); if (tEpisode == null) { return(null); } path = tEpisode.GetFullImagePath(); if (Pri.LongPath.File.Exists(path)) { return(path); } else { path = ""; logger.Trace("Could not find Trakt_Episode image: {0}", tEpisode.GetFullImagePath()); } break; // 0, 13-15, 17+ default: path = ""; break; } return(path); }
public string GetImagePath(int imageId, int imageType, bool?thumnbnailOnly) { ImageEntityType it = (ImageEntityType)imageType; switch (it) { case ImageEntityType.AniDB_Cover: SVR_AniDB_Anime anime = Repo.Instance.AniDB_Anime.GetByID(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 = Repo.Instance.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 = Repo.Instance.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 = Repo.Instance.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 = Repo.Instance.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 = Repo.Instance.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 = Repo.Instance.TvDB_ImageFanart.GetByID(imageId); if (fanart == null) { return(null); } if (thumnbnailOnly.HasValue && thumnbnailOnly.Value) { if (File.Exists(fanart.GetFullThumbnailPath())) { return(fanart.GetFullThumbnailPath()); } logger.Trace("Could not find TvDB_FanArt image: {0}", fanart.GetFullThumbnailPath()); return(string.Empty); } else { if (File.Exists(fanart.GetFullImagePath())) { return(fanart.GetFullImagePath()); } logger.Trace("Could not find TvDB_FanArt image: {0}", fanart.GetFullImagePath()); return(string.Empty); } case ImageEntityType.MovieDB_Poster: MovieDB_Poster mPoster = Repo.Instance.MovieDB_Poster.GetByID(imageId); if (mPoster == null) { return(null); } // now find only the original size mPoster = Repo.Instance.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 = Repo.Instance.MovieDB_Fanart.GetByID(imageId); if (mFanart == null) { return(null); } mFanart = Repo.Instance.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); } }
/// <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 (System.IO.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 (System.IO.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 (System.IO.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 (System.IO.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 (System.IO.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 (System.IO.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 (System.IO.File.Exists(path)) { return(path); } path = string.Empty; logger.Trace("Could not find TvDB_FanArt image: {0}", fanart.GetFullThumbnailPath()); } else { path = fanart.GetFullImagePath(); if (System.IO.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 (System.IO.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 (System.IO.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 (System.IO.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 (System.IO.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); }