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);
            }
        }
Esempio n. 2
0
        public static string GetImagePath(ImageEntityType type, int id)
        {
            string path;

            switch (type)
            {
            // 1
            case ImageEntityType.AniDB_Cover:
                SVR_AniDB_Anime anime = Repo.Instance.AniDB_Anime.GetByID(id);
                if (anime == null)
                {
                    return(null);
                }
                path = anime.PosterPath;
                if (File.Exists(path))
                {
                    return(path);
                }
                else
                {
                    path = string.Empty;
                }
                break;

            // 4
            case ImageEntityType.TvDB_Banner:
                TvDB_ImageWideBanner wideBanner = Repo.Instance.TvDB_ImageWideBanner.GetByID(id);
                if (wideBanner == null)
                {
                    return(null);
                }
                path = wideBanner.GetFullImagePath();
                if (File.Exists(path))
                {
                    return(path);
                }
                else
                {
                    path = string.Empty;
                }
                break;

            // 5
            case ImageEntityType.TvDB_Cover:
                TvDB_ImagePoster poster = Repo.Instance.TvDB_ImagePoster.GetByID(id);
                if (poster == null)
                {
                    return(null);
                }
                path = poster.GetFullImagePath();
                if (File.Exists(path))
                {
                    return(path);
                }
                else
                {
                    path = string.Empty;
                }
                break;

            // 6
            case ImageEntityType.TvDB_Episode:
                TvDB_Episode ep = Repo.Instance.TvDB_Episode.GetByID(id);
                if (ep == null)
                {
                    return(null);
                }
                path = ep.GetFullImagePath();
                if (File.Exists(path))
                {
                    return(path);
                }
                else
                {
                    path = string.Empty;
                }
                break;

            // 7
            case ImageEntityType.TvDB_FanArt:
                TvDB_ImageFanart fanart = Repo.Instance.TvDB_ImageFanart.GetByID(id);
                if (fanart == null)
                {
                    return(null);
                }
                path = fanart.GetFullImagePath();
                if (File.Exists(path))
                {
                    return(path);
                }

                path = string.Empty;
                break;

            // 8
            case ImageEntityType.MovieDB_FanArt:
                MovieDB_Fanart mFanart = Repo.Instance.MovieDB_Fanart.GetByID(id);
                if (mFanart == null)
                {
                    return(null);
                }
                mFanart = Repo.Instance.MovieDB_Fanart.GetByOnlineID(mFanart.URL);
                if (mFanart == null)
                {
                    return(null);
                }
                path = mFanart.GetFullImagePath();
                if (File.Exists(path))
                {
                    return(path);
                }
                else
                {
                    path = string.Empty;
                }
                break;

            // 9
            case ImageEntityType.MovieDB_Poster:
                MovieDB_Poster mPoster = Repo.Instance.MovieDB_Poster.GetByID(id);
                if (mPoster == null)
                {
                    return(null);
                }
                mPoster = Repo.Instance.MovieDB_Poster.GetByOnlineID(mPoster.URL);
                if (mPoster == null)
                {
                    return(null);
                }
                path = mPoster.GetFullImagePath();
                if (File.Exists(path))
                {
                    return(path);
                }
                else
                {
                    path = string.Empty;
                }
                break;

            case ImageEntityType.Character:
                AnimeCharacter character = Repo.Instance.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;
                }
                break;

            case ImageEntityType.Staff:
                var staff = Repo.Instance.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;
                }
                break;

            default:
                path = string.Empty;
                break;
            }

            return(path);
        }
Esempio n. 3
0
        private void RemoveImageAndQueueRedownload(ImageEntityType EntityTypeEnum, int EntityID, object Entity)
        {
            CommandRequest_DownloadImage cmd;

            switch (EntityTypeEnum)
            {
            case ImageEntityType.TvDB_Episode:
                TvDB_Episode episode = Entity as TvDB_Episode;
                if (episode == null)
                {
                    return;
                }
                try
                {
                    if (File.Exists(episode.GetFullImagePath()))
                    {
                        File.Delete(episode.GetFullImagePath());
                    }
                }
                catch (Exception e)
                {
                    logger.Error($"Unable to delete {episode.GetFullImagePath()} - {e.Message}");
                }

                cmd = new CommandRequest_DownloadImage(EntityID, ImageEntityType.TvDB_Episode, true);
                break;

            case ImageEntityType.TvDB_FanArt:
                TvDB_ImageFanart fanart = Entity as TvDB_ImageFanart;
                if (fanart == null)
                {
                    return;
                }
                try
                {
                    if (File.Exists(fanart.GetFullImagePath()))
                    {
                        File.Delete(fanart.GetFullImagePath());
                    }
                }
                catch (Exception e)
                {
                    logger.Error($"Unable to delete {fanart.GetFullImagePath()} - {e.Message}");
                }

                cmd = new CommandRequest_DownloadImage(EntityID, ImageEntityType.TvDB_FanArt, true);
                break;

            case ImageEntityType.TvDB_Cover:
                TvDB_ImagePoster poster = Entity as TvDB_ImagePoster;
                if (poster == null)
                {
                    return;
                }
                try
                {
                    if (File.Exists(poster.GetFullImagePath()))
                    {
                        File.Delete(poster.GetFullImagePath());
                    }
                }
                catch (Exception e)
                {
                    logger.Error($"Unable to delete {poster.GetFullImagePath()} - {e.Message}");
                }

                cmd = new CommandRequest_DownloadImage(EntityID, ImageEntityType.TvDB_Cover, true);
                break;

            case ImageEntityType.TvDB_Banner:
                TvDB_ImageWideBanner wideBanner = Entity as TvDB_ImageWideBanner;
                if (wideBanner == null)
                {
                    return;
                }
                try
                {
                    if (File.Exists(wideBanner.GetFullImagePath()))
                    {
                        File.Delete(wideBanner.GetFullImagePath());
                    }
                }
                catch (Exception e)
                {
                    logger.Error($"Unable to delete {wideBanner.GetFullImagePath()} - {e.Message}");
                }

                cmd = new CommandRequest_DownloadImage(EntityID, ImageEntityType.TvDB_Banner, true);
                break;

            case ImageEntityType.MovieDB_Poster:
                MovieDB_Poster moviePoster = Entity as MovieDB_Poster;
                if (moviePoster == null)
                {
                    return;
                }
                try
                {
                    if (File.Exists(moviePoster.GetFullImagePath()))
                    {
                        File.Delete(moviePoster.GetFullImagePath());
                    }
                }
                catch (Exception e)
                {
                    logger.Error($"Unable to delete {moviePoster.GetFullImagePath()} - {e.Message}");
                }

                cmd = new CommandRequest_DownloadImage(EntityID, ImageEntityType.MovieDB_Poster, true);
                break;

            case ImageEntityType.MovieDB_FanArt:
                MovieDB_Fanart movieFanart = Entity as MovieDB_Fanart;
                if (movieFanart == null)
                {
                    return;
                }
                try
                {
                    if (File.Exists(movieFanart.GetFullImagePath()))
                    {
                        File.Delete(movieFanart.GetFullImagePath());
                    }
                }
                catch (Exception e)
                {
                    logger.Error($"Unable to delete {movieFanart.GetFullImagePath()} - {e.Message}");
                }

                cmd = new CommandRequest_DownloadImage(EntityID, ImageEntityType.MovieDB_FanArt, true);
                break;

            case ImageEntityType.AniDB_Cover:
                string coverpath = (Entity as SVR_AniDB_Anime)?.PosterPath;
                if (string.IsNullOrEmpty(coverpath))
                {
                    return;
                }
                try
                {
                    if (File.Exists(coverpath))
                    {
                        File.Delete(coverpath);
                    }
                }
                catch (Exception e)
                {
                    logger.Error($"Unable to delete {coverpath} - {e.Message}");
                }

                cmd = new CommandRequest_DownloadImage(EntityID, ImageEntityType.AniDB_Cover, true);
                break;

            case ImageEntityType.AniDB_Creator:
                string creatorpath = (Entity as AniDB_Seiyuu)?.GetPosterPath();
                if (string.IsNullOrEmpty(creatorpath))
                {
                    return;
                }
                try
                {
                    if (File.Exists(creatorpath))
                    {
                        File.Delete(creatorpath);
                    }
                }
                catch (Exception e)
                {
                    logger.Error($"Unable to delete {creatorpath} - {e.Message}");
                }

                cmd = new CommandRequest_DownloadImage(EntityID, ImageEntityType.AniDB_Creator, true);
                break;

            case ImageEntityType.AniDB_Character:
                string characterpath = (Entity as AniDB_Character)?.GetPosterPath();
                if (string.IsNullOrEmpty(characterpath))
                {
                    return;
                }
                try
                {
                    if (File.Exists(characterpath))
                    {
                        File.Delete(characterpath);
                    }
                }
                catch (Exception e)
                {
                    logger.Error($"Unable to delete {characterpath} - {e.Message}");
                }

                cmd = new CommandRequest_DownloadImage(EntityID, ImageEntityType.AniDB_Character, true);
                break;

            default:
                return;
            }
            cmd.Save();
        }
Esempio n. 4
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 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);
            }
        }
Esempio n. 6
0
        private string GetRandomImagePath(int type)
        {
            ImageEntityType imageType = (ImageEntityType)type;
            string          path;

            switch (imageType)
            {
            // 1
            case ImageEntityType.AniDB_Cover:
                SVR_AniDB_Anime anime = RepoFactory.AniDB_Anime.GetAll()
                                        .Where(a => a?.PosterPath != null && !a.GetAllTags().Contains("18 restricted"))
                                        .GetRandomElement();
                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:
                var chr = RepoFactory.AniDB_Anime.GetAll()
                          .Where(a => a != null && !a.GetAllTags().Contains("18 restricted"))
                          .SelectMany(a => a.GetAnimeCharacters()).Select(a => a.GetCharacter()).Where(a => a != null)
                          .GetRandomElement();
                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 -- this will likely be slow
            case ImageEntityType.AniDB_Creator:
                var creator = RepoFactory.AniDB_Anime.GetAll()
                              .Where(a => a != null && !a.GetAllTags().Contains("18 restricted"))
                              .SelectMany(a => a.GetAnimeCharacters())
                              .SelectMany(a => RepoFactory.AniDB_Character_Seiyuu.GetByCharID(a.CharID))
                              .Select(a => RepoFactory.AniDB_Seiyuu.GetBySeiyuuID(a.SeiyuuID)).Where(a => a != null)
                              .GetRandomElement();
                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 doesn't allow H content, so we get to skip the check!
                TvDB_ImageWideBanner wideBanner = RepoFactory.TvDB_ImageWideBanner.GetAll().GetRandomElement();
                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 doesn't allow H content, so we get to skip the check!
                TvDB_ImagePoster poster = RepoFactory.TvDB_ImagePoster.GetAll().GetRandomElement();
                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 doesn't allow H content, so we get to skip the check!
                TvDB_Episode ep = RepoFactory.TvDB_Episode.GetAll().GetRandomElement();
                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 doesn't allow H content, so we get to skip the check!
                TvDB_ImageFanart fanart = RepoFactory.TvDB_ImageFanart.GetAll().GetRandomElement();
                if (fanart == null)
                {
                    return(null);
                }
                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.GetAll().GetRandomElement();
                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.GetAll().GetRandomElement();
                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:
                var character = RepoFactory.AniDB_Anime.GetAll()
                                .Where(a => a != null && !a.GetAllTags().Contains("18 restricted"))
                                .SelectMany(a => RepoFactory.CrossRef_Anime_Staff.GetByAnimeID(a.AnimeID))
                                .Where(a => a.RoleType == (int)StaffRoleType.Seiyuu && a.RoleID.HasValue)
                                .Select(a => RepoFactory.AnimeCharacter.GetByID(a.RoleID.Value)).GetRandomElement();
                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.AniDB_Anime.GetAll()
                            .Where(a => a != null && !a.GetAllTags().Contains("18 restricted"))
                            .SelectMany(a => RepoFactory.CrossRef_Anime_Staff.GetByAnimeID(a.AnimeID))
                            .Select(a => RepoFactory.AnimeStaff.GetByID(a.StaffID)).GetRandomElement();
                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);
        }
Esempio n. 7
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 (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);
        }
Esempio n. 8
0
        public void DownloadAutomaticImages(XmlDocument doc, int seriesID, bool forceDownload)
        {
            List <object> banners = ParseBanners(seriesID, doc);

            int numFanartDownloaded  = 0;
            int numPostersDownloaded = 0;
            int numBannersDownloaded = 0;

            // find out how many images we already have locally


            using (var session = DatabaseFactory.SessionFactory.OpenSession())
            {
                ISessionWrapper sessionWrapper = session.Wrap();

                foreach (TvDB_ImageFanart fanart in RepoFactory.TvDB_ImageFanart
                         .GetBySeriesID(sessionWrapper, seriesID))
                {
                    if (!string.IsNullOrEmpty(fanart.GetFullImagePath()) && File.Exists(fanart.GetFullImagePath()))
                    {
                        numFanartDownloaded++;
                    }
                }

                foreach (TvDB_ImagePoster poster in RepoFactory.TvDB_ImagePoster
                         .GetBySeriesID(sessionWrapper, seriesID))
                {
                    if (!string.IsNullOrEmpty(poster.GetFullImagePath()) && File.Exists(poster.GetFullImagePath()))
                    {
                        numPostersDownloaded++;
                    }
                }

                foreach (TvDB_ImageWideBanner banner in RepoFactory.TvDB_ImageWideBanner.GetBySeriesID(session,
                                                                                                       seriesID))
                {
                    if (!string.IsNullOrEmpty(banner.GetFullImagePath()) && File.Exists(banner.GetFullImagePath()))
                    {
                        numBannersDownloaded++;
                    }
                }
            }


            foreach (object obj in banners)
            {
                if (obj.GetType() == typeof(TvDB_ImageFanart))
                {
                    TvDB_ImageFanart img = obj as TvDB_ImageFanart;
                    if (ServerSettings.TvDB_AutoFanart && numFanartDownloaded < ServerSettings.TvDB_AutoFanartAmount)
                    {
                        bool fileExists = File.Exists(img.GetFullImagePath());
                        if (!fileExists || (fileExists && forceDownload))
                        {
                            CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(img.TvDB_ImageFanartID,
                                                                                                JMMImageType.TvDB_FanArt, forceDownload);
                            cmd.Save();
                            numFanartDownloaded++;
                        }
                    }
                    else
                    {
                        //The TvDB_AutoFanartAmount point to download less images than its available
                        // we should clean those image that we didn't download because those dont exists in local repo
                        // first we check if file was downloaded
                        if (!File.Exists(img.GetFullImagePath()))
                        {
                            RepoFactory.TvDB_ImageFanart.Delete(img.TvDB_ImageFanartID);
                        }
                    }
                }

                if (obj.GetType() == typeof(TvDB_ImagePoster))
                {
                    TvDB_ImagePoster img = obj as TvDB_ImagePoster;
                    if (ServerSettings.TvDB_AutoPosters && numPostersDownloaded < ServerSettings.TvDB_AutoPostersAmount)
                    {
                        bool fileExists = File.Exists(img.GetFullImagePath());
                        if (!fileExists || (fileExists && forceDownload))
                        {
                            CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(img.TvDB_ImagePosterID,
                                                                                                JMMImageType.TvDB_Cover, forceDownload);
                            cmd.Save();
                            numPostersDownloaded++;
                        }
                    }
                    else
                    {
                        //The TvDB_AutoPostersAmount point to download less images than its available
                        // we should clean those image that we didn't download because those dont exists in local repo
                        // first we check if file was downloaded
                        if (!File.Exists(img.GetFullImagePath()))
                        {
                            RepoFactory.TvDB_ImagePoster.Delete(img.TvDB_ImagePosterID);
                        }
                    }
                }

                if (obj.GetType() == typeof(TvDB_ImageWideBanner))
                {
                    TvDB_ImageWideBanner img = obj as TvDB_ImageWideBanner;
                    if (ServerSettings.TvDB_AutoWideBanners &&
                        numBannersDownloaded < ServerSettings.TvDB_AutoWideBannersAmount)
                    {
                        bool fileExists = File.Exists(img.GetFullImagePath());
                        if (!fileExists || (fileExists && forceDownload))
                        {
                            CommandRequest_DownloadImage cmd =
                                new CommandRequest_DownloadImage(img.TvDB_ImageWideBannerID,
                                                                 JMMImageType.TvDB_Banner, forceDownload);
                            cmd.Save();
                            numBannersDownloaded++;
                        }
                    }
                    else
                    {
                        //The TvDB_AutoWideBannersAmount point to download less images than its available
                        // we should clean those image that we didn't download because those dont exists in local repo
                        // first we check if file was downloaded
                        if (!File.Exists(img.GetFullImagePath()))
                        {
                            RepoFactory.TvDB_ImageWideBanner.Delete(img.TvDB_ImageWideBannerID);
                        }
                    }
                }
            }
        }