Example #1
0
        private string GetRandomImagePath(int type)
        {
            ImageEntityType imageType = (ImageEntityType)type;
            string          path;

            switch (imageType)
            {
            // 1
            case ImageEntityType.AniDB_Cover:
                SVR_AniDB_Anime anime = Repo.Instance.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 = Repo.Instance.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 = Repo.Instance.AniDB_Anime.GetAll()
                              .Where(a => a != null && !a.GetAllTags().Contains("18 restricted"))
                              .SelectMany(a => a.GetAnimeCharacters())
                              .SelectMany(a => Repo.Instance.AniDB_Character_Seiyuu.GetByCharID(a.CharID))
                              .Select(a => Repo.Instance.AniDB_Seiyuu.GetByID(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 = Repo.Instance.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 = Repo.Instance.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 = Repo.Instance.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 = Repo.Instance.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 = Repo.Instance.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 = Repo.Instance.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 = Repo.Instance.AniDB_Anime.GetAll()
                                .Where(a => a != null && !a.GetAllTags().Contains("18 restricted"))
                                .SelectMany(a => Repo.Instance.CrossRef_Anime_Staff.GetByAnimeID(a.AnimeID))
                                .Where(a => a.RoleType == (int)StaffRoleType.Seiyuu && a.RoleID.HasValue)
                                .Select(a => Repo.Instance.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 = Repo.Instance.AniDB_Anime.GetAll()
                            .Where(a => a != null && !a.GetAllTags().Contains("18 restricted"))
                            .SelectMany(a => Repo.Instance.CrossRef_Anime_Staff.GetByAnimeID(a.AnimeID))
                            .Select(a => Repo.Instance.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);
        }
        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 (System.IO.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 (System.IO.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 (System.IO.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 (System.IO.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 (System.IO.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 (System.IO.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 (System.IO.File.Exists(fanart.GetFullThumbnailPath()))
                    {
                        return(fanart.GetFullThumbnailPath());
                    }

                    logger.Trace("Could not find TvDB_FanArt image: {0}", fanart.GetFullThumbnailPath());
                    return(string.Empty);
                }
                else
                {
                    if (System.IO.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 = 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 (System.IO.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 (System.IO.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);
            }
        }
Example #3
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 = Repo.Instance.AniDB_Anime.GetByID(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 = Repo.Instance.AniDB_Character.GetByID(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 = Repo.Instance.AniDB_Seiyuu.GetByID(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 = Repo.Instance.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 = Repo.Instance.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 = Repo.Instance.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 = Repo.Instance.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 = 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 (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 = 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 (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 = Repo.Instance.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 = Repo.Instance.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);
        }
        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();
        }
Example #5
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);
                        }
                    }
                }
            }
        }
Example #6
0
        public static string GetImagePath(ImageEntityType type, int id)
        {
            string path;

            switch (type)
            {
            // 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;
                }
                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;
                }
                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;
                }
                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;
                }
                break;

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

                path = string.Empty;
                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;
                }
                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;
                }
                break;

            case ImageEntityType.Character:
                AnimeCharacter character = RepoFactory.AnimeCharacter.GetByID(id);
                if (character == null)
                {
                    return(null);
                }
                path = ImageUtils.GetBaseAniDBCharacterImagesPath() + System.IO.Path.DirectorySeparatorChar + character.ImagePath;
                if (System.IO.File.Exists(path))
                {
                    return(path);
                }
                else
                {
                    path = string.Empty;
                }
                break;

            case ImageEntityType.Staff:
                var staff = RepoFactory.AnimeStaff.GetByID(id);
                if (staff == null)
                {
                    return(null);
                }
                path = ImageUtils.GetBaseAniDBCreatorImagesPath() + System.IO.Path.DirectorySeparatorChar + staff.ImagePath;
                if (System.IO.File.Exists(path))
                {
                    return(path);
                }
                else
                {
                    path = string.Empty;
                }
                break;

            default:
                path = string.Empty;
                break;
            }

            return(path);
        }
Example #7
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("");
            }
        }