예제 #1
0
 public ImageDownloadEventArgs(string status, ImageDownloadRequest req, ImageDownloadEventType eventType)
 {
     Status = status;
     Req = req;
     EventType = eventType;
     ImageType = Req.ImageType;
 }
예제 #2
0
        public void DownloadAniDBCharactersCreatorsSync(AniDB_AnimeVM anime, bool forceDownload)
        {
            try
            {
                foreach (AniDB_CharacterVM chr in anime.Characters)
                {
                    if (!string.IsNullOrEmpty(chr.PicName))
                    {
                        string url = string.Format(Constants.URLS.AniDB_Images, chr.PicName);
                        string filename = chr.PosterPath;

                        ImageDownloadRequest req = new ImageDownloadRequest(ImageEntityType.AniDB_Character, chr, forceDownload);

                        // check if this file has already been downloaded and exists
                        if (!req.ForceDownload)
                        {
                            // check to make sure the file actually exists
                            if (!File.Exists(chr.PosterPath))
                                ProcessImageDownloadRequest(req);

                        }
                        else
                            ProcessImageDownloadRequest(req);

                    }

                    if (chr.Creator == null) continue;

                    if (!string.IsNullOrEmpty(chr.Creator.PicName))
                    {
                        string url = string.Format(Constants.URLS.AniDB_Images, chr.Creator.PicName);
                        string filename = chr.Creator.PosterPath;

                        ImageDownloadRequest req = new ImageDownloadRequest(ImageEntityType.AniDB_Creator, chr.Creator, forceDownload);

                        // check if this file has already been downloaded and exists
                        if (!req.ForceDownload)
                        {
                            // check to make sure the file actually exists
                            if (!File.Exists(chr.Creator.PosterPath))
                                ProcessImageDownloadRequest(req);

                        }
                        else
                            ProcessImageDownloadRequest(req);

                    }
                }

            }
            catch (Exception ex)
            {
                BaseConfig.MyAnimeLog.Write(ex.ToString());
            }
        }
예제 #3
0
        public void DownloadAniDBCharactersCreatorsSync(AniDB_AnimeVM anime, bool forceDownload)
        {
            try
            {
                foreach (AniDB_CharacterVM chr in anime.Characters)
                {
                    if (!string.IsNullOrEmpty(chr.PicName))
                    {
                        string url      = string.Format(Constants.URLS.AniDB_Images, chr.PicName);
                        string filename = chr.PosterPath;

                        ImageDownloadRequest req = new ImageDownloadRequest(ImageEntityType.AniDB_Character, chr, forceDownload);

                        // check if this file has already been downloaded and exists
                        if (!req.ForceDownload)
                        {
                            // check to make sure the file actually exists
                            if (!File.Exists(chr.PosterPath))
                            {
                                ProcessImageDownloadRequest(req);
                            }
                        }
                        else
                        {
                            ProcessImageDownloadRequest(req);
                        }
                    }

                    if (chr.Creator == null)
                    {
                        continue;
                    }

                    if (!string.IsNullOrEmpty(chr.Creator.PicName))
                    {
                        string url      = string.Format(Constants.URLS.AniDB_Images, chr.Creator.PicName);
                        string filename = chr.Creator.PosterPath;

                        ImageDownloadRequest req = new ImageDownloadRequest(ImageEntityType.AniDB_Creator, chr.Creator, forceDownload);

                        // check if this file has already been downloaded and exists
                        if (!req.ForceDownload)
                        {
                            // check to make sure the file actually exists
                            if (!File.Exists(chr.Creator.PosterPath))
                            {
                                ProcessImageDownloadRequest(req);
                            }
                        }
                        else
                        {
                            ProcessImageDownloadRequest(req);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                BaseConfig.MyAnimeLog.Write(ex.ToString());
            }
        }
예제 #4
0
        public void DownloadImage(ImageDownloadRequest req)
        {
            try
            {
                lock (downloadsLock)
                {
                    string fileName      = GetFileName(req, false);
                    string entityID      = GetEntityID(req);
                    bool   downloadImage = true;
                    bool   fileExists    = File.Exists(fileName);

                    if (fileExists)
                    {
                        if (!req.ForceDownload)
                        {
                            downloadImage = false;
                        }
                        else
                        {
                            downloadImage = true;
                        }
                    }
                    else
                    {
                        downloadImage = true;
                    }

                    if (downloadImage)
                    {
                        string tempName = Path.Combine(Utils.GetImagesTempFolder(), Path.GetFileName(fileName));
                        if (File.Exists(tempName))
                        {
                            File.Delete(tempName);
                        }


                        OnImageDownloadEvent(new ImageDownloadEventArgs("", req, ImageDownloadEventType.Started));
                        if (fileExists)
                        {
                            File.Delete(fileName);
                        }

                        byte[] imageArray = null;
                        try
                        {
                            imageArray = JMMServerVM.Instance.imageClient.GetImage(entityID, (int)req.ImageType, false);
                        }
                        catch { }

                        if (imageArray == null)
                        {
                            return;
                        }

                        File.WriteAllBytes(tempName, imageArray);

                        // move the file to it's final location
                        string fullPath = Path.GetDirectoryName(fileName);
                        if (!Directory.Exists(fullPath))
                        {
                            Directory.CreateDirectory(fullPath);
                        }

                        // move the file to it's final location
                        File.Move(tempName, fileName);
                    }


                    // if the file is a tvdb fanart also get the thumbnail
                    if (req.ImageType == ImageEntityType.TvDB_FanArt)
                    {
                        fileName      = GetFileName(req, true);
                        entityID      = GetEntityID(req);
                        downloadImage = true;
                        fileExists    = File.Exists(fileName);

                        if (fileExists)
                        {
                            if (!req.ForceDownload)
                            {
                                downloadImage = false;
                            }
                            else
                            {
                                downloadImage = true;
                            }
                        }
                        else
                        {
                            downloadImage = true;
                        }

                        if (downloadImage)
                        {
                            string tempName = Path.Combine(Utils.GetImagesTempFolder(), Path.GetFileName(fileName));
                            if (File.Exists(tempName))
                            {
                                File.Delete(tempName);
                            }

                            OnImageDownloadEvent(new ImageDownloadEventArgs("", req, ImageDownloadEventType.Started));
                            if (fileExists)
                            {
                                File.Delete(fileName);
                            }

                            byte[] imageArray = null;
                            try
                            {
                                imageArray = JMMServerVM.Instance.imageClient.GetImage(entityID, (int)req.ImageType, true);
                            }
                            catch { }

                            if (imageArray == null)
                            {
                                return;
                            }

                            File.WriteAllBytes(tempName, imageArray);

                            // move the file to it's final location
                            string fullPath = Path.GetDirectoryName(fileName);
                            if (!Directory.Exists(fullPath))
                            {
                                Directory.CreateDirectory(fullPath);
                            }

                            // move the file to it's final location
                            File.Move(tempName, fileName);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                BaseConfig.MyAnimeLog.Write(ex.ToString());
            }
        }
예제 #5
0
        private string GetEntityID(ImageDownloadRequest req)
        {
            switch (req.ImageType)
            {
            case ImageEntityType.AniDB_Cover:

                AniDB_AnimeVM anime = req.ImageData as AniDB_AnimeVM;
                return(anime.AnimeID.ToString());

            case ImageEntityType.AniDB_Character:

                AniDB_CharacterVM chr = req.ImageData as AniDB_CharacterVM;
                return(chr.AniDB_CharacterID.ToString());

            case ImageEntityType.AniDB_Creator:

                AniDB_SeiyuuVM creator = req.ImageData as AniDB_SeiyuuVM;
                return(creator.AniDB_SeiyuuID.ToString());

            case ImageEntityType.TvDB_Cover:

                TvDB_ImagePosterVM poster = req.ImageData as TvDB_ImagePosterVM;
                return(poster.TvDB_ImagePosterID.ToString());

            case ImageEntityType.TvDB_Banner:

                TvDB_ImageWideBannerVM banner = req.ImageData as TvDB_ImageWideBannerVM;
                return(banner.TvDB_ImageWideBannerID.ToString());

            case ImageEntityType.TvDB_Episode:

                TvDB_EpisodeVM episode = req.ImageData as TvDB_EpisodeVM;
                return(episode.TvDB_EpisodeID.ToString());

            case ImageEntityType.TvDB_FanArt:

                TvDB_ImageFanartVM fanart = req.ImageData as TvDB_ImageFanartVM;
                return(fanart.TvDB_ImageFanartID.ToString());

            case ImageEntityType.MovieDB_Poster:

                MovieDB_PosterVM moviePoster = req.ImageData as MovieDB_PosterVM;
                return(moviePoster.MovieDB_PosterID.ToString());

            case ImageEntityType.MovieDB_FanArt:

                MovieDB_FanartVM movieFanart = req.ImageData as MovieDB_FanartVM;
                return(movieFanart.MovieDB_FanartID.ToString());

            case ImageEntityType.Trakt_Poster:

                Trakt_ImagePosterVM traktPoster = req.ImageData as Trakt_ImagePosterVM;
                return(traktPoster.Trakt_ImagePosterID.ToString());

            case ImageEntityType.Trakt_Fanart:

                Trakt_ImageFanartVM trakFanart = req.ImageData as Trakt_ImageFanartVM;
                return(trakFanart.Trakt_ImageFanartID.ToString());

            case ImageEntityType.Trakt_Episode:

                Trakt_EpisodeVM trakEp = req.ImageData as Trakt_EpisodeVM;
                return(trakEp.Trakt_EpisodeID.ToString());

            default:
                return("");
            }
        }
예제 #6
0
        private string GetFileName(ImageDownloadRequest req, bool thumbNailOnly)
        {
            switch (req.ImageType)
            {
            case ImageEntityType.AniDB_Cover:

                AniDB_AnimeVM anime = req.ImageData as AniDB_AnimeVM;
                return(anime.PosterPathNoDefaultPlain);

            case ImageEntityType.AniDB_Character:

                AniDB_CharacterVM chr = req.ImageData as AniDB_CharacterVM;
                return(chr.PosterPathPlain);

            case ImageEntityType.AniDB_Creator:

                AniDB_SeiyuuVM creator = req.ImageData as AniDB_SeiyuuVM;
                return(creator.PosterPathPlain);

            case ImageEntityType.TvDB_Cover:

                TvDB_ImagePosterVM poster = req.ImageData as TvDB_ImagePosterVM;
                return(poster.FullImagePathPlain);

            case ImageEntityType.TvDB_Banner:

                TvDB_ImageWideBannerVM banner = req.ImageData as TvDB_ImageWideBannerVM;
                return(banner.FullImagePathPlain);

            case ImageEntityType.TvDB_Episode:

                TvDB_EpisodeVM episode = req.ImageData as TvDB_EpisodeVM;
                return(episode.FullImagePathPlain);

            case ImageEntityType.TvDB_FanArt:

                TvDB_ImageFanartVM fanart = req.ImageData as TvDB_ImageFanartVM;

                if (thumbNailOnly)
                {
                    return(fanart.FullThumbnailPathPlain);
                }
                else
                {
                    return(fanart.FullImagePathPlain);
                }

            case ImageEntityType.MovieDB_Poster:

                MovieDB_PosterVM moviePoster = req.ImageData as MovieDB_PosterVM;
                return(moviePoster.FullImagePathPlain);

            case ImageEntityType.MovieDB_FanArt:

                MovieDB_FanartVM movieFanart = req.ImageData as MovieDB_FanartVM;
                return(movieFanart.FullImagePathPlain);

            case ImageEntityType.Trakt_Poster:

                Trakt_ImagePosterVM traktPoster = req.ImageData as Trakt_ImagePosterVM;
                return(traktPoster.FullImagePathPlain);

            case ImageEntityType.Trakt_Fanart:

                Trakt_ImageFanartVM trakFanart = req.ImageData as Trakt_ImageFanartVM;
                return(trakFanart.FullImagePathPlain);

            case ImageEntityType.Trakt_Episode:

                Trakt_EpisodeVM trakEp = req.ImageData as Trakt_EpisodeVM;
                return(trakEp.FullImagePathPlain);

            default:
                return("");
            }
        }
예제 #7
0
        private void ProcessImageDownloadRequest(ImageDownloadRequest req)
        {
            try
            {
                string fileName = GetFileName(req, false);
                string entityID = GetEntityID(req);
                bool downloadImage = true;
                bool fileExists = File.Exists(fileName);

                if (fileExists)
                {
                    if (!req.ForceDownload)
                        downloadImage = false;
                    else
                        downloadImage = true;
                }
                else
                    downloadImage = true;

                if (downloadImage)
                {
                    string tempName = Path.Combine(Utils.GetImagesTempFolder(), Path.GetFileName(fileName));
                    if (File.Exists(tempName)) File.Delete(tempName);

                    OnImageDownloadEvent(new ImageDownloadEventArgs("", req, ImageDownloadEventType.Started));
                    if (fileExists) File.Delete(fileName);

                    byte[] imageArray = null;
                    try
                    {
                        imageArray = JMMServerHelper.GetImage(entityID, req.ImageType, false);
                    }
                    catch { }

                    if (imageArray == null)
                    {
                        imagesToDownload.Remove(req);
                        OnQueueUpdateEvent(new QueueUpdateEventArgs(this.QueueCount));
                        return;
                    }

                    File.WriteAllBytes(tempName, imageArray);

                    // move the file to it's final location
                    string fullPath = Path.GetDirectoryName(fileName);
                    if (!Directory.Exists(fullPath))
                        Directory.CreateDirectory(fullPath);

                    // move the file to it's final location
                    File.Move(tempName, fileName);

                }

                OnImageDownloadEvent(new ImageDownloadEventArgs("", req, ImageDownloadEventType.Complete));

                // if the file is a tvdb fanart also get the thumbnail
                if (req.ImageType == ImageEntityType.TvDB_FanArt)
                {
                    fileName = GetFileName(req, true);
                    entityID = GetEntityID(req);
                    downloadImage = true;
                    fileExists = File.Exists(fileName);

                    if (fileExists)
                    {
                        if (!req.ForceDownload)
                            downloadImage = false;
                        else
                            downloadImage = true;
                    }
                    else
                        downloadImage = true;

                    if (downloadImage)
                    {
                        string tempName = Path.Combine(Utils.GetImagesTempFolder(), Path.GetFileName(fileName));
                        if (File.Exists(tempName)) File.Delete(tempName);

                        OnImageDownloadEvent(new ImageDownloadEventArgs("", req, ImageDownloadEventType.Started));
                        if (fileExists) File.Delete(fileName);

                        byte[] imageArray = null;
                        try
                        {
                            imageArray = JMMServerVM.Instance.imageClient.GetImage(entityID, (int)req.ImageType, true);
                        }
                        catch { }

                        if (imageArray == null)
                        {
                            imagesToDownload.Remove(req);
                            OnQueueUpdateEvent(new QueueUpdateEventArgs(this.QueueCount));
                            return;
                        }

                        File.WriteAllBytes(tempName, imageArray);

                        // move the file to it's final location
                        string fullPath = Path.GetDirectoryName(fileName);
                        if (!Directory.Exists(fullPath))
                            Directory.CreateDirectory(fullPath);

                        // move the file to it's final location
                        File.Move(tempName, fileName);
                    }
                }

                imagesToDownload.Remove(req);
                OnQueueUpdateEvent(new QueueUpdateEventArgs(this.QueueCount));

                //OnGotShowInfoEvent(new GotShowInfoEventArgs(req.animeID));
            }
            catch (Exception ex)
            {
                imagesToDownload.Remove(req);
                OnQueueUpdateEvent(new QueueUpdateEventArgs(this.QueueCount));
                BaseConfig.MyAnimeLog.Write(ex.ToString());
            }
        }
예제 #8
0
        private string GetFileName(ImageDownloadRequest req, bool thumbNailOnly)
        {
            switch (req.ImageType)
            {
                case ImageEntityType.AniDB_Cover:

                    AniDB_AnimeVM anime = req.ImageData as AniDB_AnimeVM;
                    return anime.PosterPathNoDefaultPlain;

                case ImageEntityType.AniDB_Character:

                    AniDB_CharacterVM chr = req.ImageData as AniDB_CharacterVM;
                    return chr.PosterPathPlain;

                case ImageEntityType.AniDB_Creator:

                    AniDB_SeiyuuVM creator = req.ImageData as AniDB_SeiyuuVM;
                    return creator.PosterPathPlain;

                case ImageEntityType.TvDB_Cover:

                    TvDB_ImagePosterVM poster = req.ImageData as TvDB_ImagePosterVM;
                    return poster.FullImagePathPlain;

                case ImageEntityType.TvDB_Banner:

                    TvDB_ImageWideBannerVM banner = req.ImageData as TvDB_ImageWideBannerVM;
                    return banner.FullImagePathPlain;

                case ImageEntityType.TvDB_Episode:

                    TvDB_EpisodeVM episode = req.ImageData as TvDB_EpisodeVM;
                    return episode.FullImagePathPlain;

                case ImageEntityType.TvDB_FanArt:

                    TvDB_ImageFanartVM fanart = req.ImageData as TvDB_ImageFanartVM;

                    if (thumbNailOnly)
                        return fanart.FullThumbnailPathPlain;
                    else
                        return fanart.FullImagePathPlain;

                case ImageEntityType.MovieDB_Poster:

                    MovieDB_PosterVM moviePoster = req.ImageData as MovieDB_PosterVM;
                    return moviePoster.FullImagePathPlain;

                case ImageEntityType.MovieDB_FanArt:

                    MovieDB_FanartVM movieFanart = req.ImageData as MovieDB_FanartVM;
                    return movieFanart.FullImagePathPlain;

                case ImageEntityType.Trakt_Poster:

                    Trakt_ImagePosterVM traktPoster = req.ImageData as Trakt_ImagePosterVM;
                    return traktPoster.FullImagePathPlain;

                case ImageEntityType.Trakt_Fanart:

                    Trakt_ImageFanartVM trakFanart = req.ImageData as Trakt_ImageFanartVM;
                    return trakFanart.FullImagePathPlain;

                case ImageEntityType.Trakt_Episode:

                    Trakt_EpisodeVM trakEp = req.ImageData as Trakt_EpisodeVM;
                    return trakEp.FullImagePathPlain;

                default:
                    return "";
            }
        }
예제 #9
0
        private string GetEntityID(ImageDownloadRequest req)
        {
            switch (req.ImageType)
            {
                case ImageEntityType.AniDB_Cover:

                    AniDB_AnimeVM anime = req.ImageData as AniDB_AnimeVM;
                    return anime.AnimeID.ToString();

                case ImageEntityType.AniDB_Character:

                    AniDB_CharacterVM chr = req.ImageData as AniDB_CharacterVM;
                    return chr.AniDB_CharacterID.ToString();

                case ImageEntityType.AniDB_Creator:

                    AniDB_SeiyuuVM creator = req.ImageData as AniDB_SeiyuuVM;
                    return creator.AniDB_SeiyuuID.ToString();

                case ImageEntityType.TvDB_Cover:

                    TvDB_ImagePosterVM poster = req.ImageData as TvDB_ImagePosterVM;
                    return poster.TvDB_ImagePosterID.ToString();

                case ImageEntityType.TvDB_Banner:

                    TvDB_ImageWideBannerVM banner = req.ImageData as TvDB_ImageWideBannerVM;
                    return banner.TvDB_ImageWideBannerID.ToString();

                case ImageEntityType.TvDB_Episode:

                    TvDB_EpisodeVM episode = req.ImageData as TvDB_EpisodeVM;
                    return episode.TvDB_EpisodeID.ToString();

                case ImageEntityType.TvDB_FanArt:

                    TvDB_ImageFanartVM fanart = req.ImageData as TvDB_ImageFanartVM;
                    return fanart.TvDB_ImageFanartID.ToString();

                case ImageEntityType.MovieDB_Poster:

                    MovieDB_PosterVM moviePoster = req.ImageData as MovieDB_PosterVM;
                    return moviePoster.MovieDB_PosterID.ToString();

                case ImageEntityType.MovieDB_FanArt:

                    MovieDB_FanartVM movieFanart = req.ImageData as MovieDB_FanartVM;
                    return movieFanart.MovieDB_FanartID.ToString();

                case ImageEntityType.Trakt_Poster:

                    Trakt_ImagePosterVM traktPoster = req.ImageData as Trakt_ImagePosterVM;
                    return traktPoster.Trakt_ImagePosterID.ToString();

                case ImageEntityType.Trakt_Fanart:

                    Trakt_ImageFanartVM trakFanart = req.ImageData as Trakt_ImageFanartVM;
                    return trakFanart.Trakt_ImageFanartID.ToString();

                case ImageEntityType.Trakt_Episode:

                    Trakt_EpisodeVM trakEp = req.ImageData as Trakt_EpisodeVM;
                    return trakEp.Trakt_EpisodeID.ToString();

                default:
                    return "";
            }
        }
예제 #10
0
        public void DownloadTvDBWideBanner(TvDB_ImageWideBannerVM wideBanner, bool forceDownload)
        {
            if (string.IsNullOrEmpty(wideBanner.BannerPath)) return;

            try
            {
                string url = string.Format(Constants.URLS.TvDB_Images, wideBanner.BannerPath);
                string filename = wideBanner.FullImagePath;

                ImageDownloadRequest req = new ImageDownloadRequest(ImageEntityType.TvDB_Banner, wideBanner, forceDownload);

                // check if this file has already been downloaded and exists
                if (!req.ForceDownload)
                {
                    // check to make sure the file actually exists
                    if (!File.Exists(wideBanner.FullImagePath))
                    {
                        this.imagesToDownload.Add(req);
                        OnQueueUpdateEvent(new QueueUpdateEventArgs(this.QueueCount));
                        return;
                    }

                    // the file exists so don't download it again
                    return;
                }

                this.imagesToDownload.Add(req);
                OnQueueUpdateEvent(new QueueUpdateEventArgs(this.QueueCount));
            }
            catch (Exception ex)
            {
                BaseConfig.MyAnimeLog.Write(ex.ToString());
            }
        }
예제 #11
0
        public void DownloadTraktPoster(Trakt_ImagePosterVM poster, bool forceDownload)
        {
            if (string.IsNullOrEmpty(poster.ImageURL)) return;

            try
            {
                string url = poster.ImageURL;
                string filename = poster.FullImagePath;

                ImageDownloadRequest req = new ImageDownloadRequest(ImageEntityType.Trakt_Poster, poster, forceDownload);

                // check if this file has already been downloaded and exists
                if (!req.ForceDownload)
                {
                    // check to make sure the file actually exists
                    if (!File.Exists(poster.FullImagePath))
                    {
                        this.imagesToDownload.Add(req);
                        OnQueueUpdateEvent(new QueueUpdateEventArgs(this.QueueCount));
                        return;
                    }

                    // the file exists so don't download it again
                    return;
                }

                this.imagesToDownload.Add(req);
                OnQueueUpdateEvent(new QueueUpdateEventArgs(this.QueueCount));
            }
            catch (Exception ex)
            {
                BaseConfig.MyAnimeLog.Write(ex.ToString());
            }
        }
예제 #12
0
        public void DownloadAniDBCover(AniDB_AnimeVM anime, bool forceDownload)
        {
            if (string.IsNullOrEmpty(anime.Picname)) return;

            try
            {
                string url = string.Format(Constants.URLS.AniDB_Images, anime.Picname);
                string filename = anime.PosterPathNoDefault;

                ImageDownloadRequest req = new ImageDownloadRequest(ImageEntityType.AniDB_Cover, anime, forceDownload);

                // check if this file has already been downloaded and exists
                if (!req.ForceDownload)
                {
                    // check to make sure the file actually exists
                    if (!File.Exists(anime.PosterPath))
                    {
                        this.imagesToDownload.Add(req);
                        OnQueueUpdateEvent(new QueueUpdateEventArgs(this.QueueCount));
                        return;
                    }

                    // the file exists so don't download it again
                    return;
                }

                this.imagesToDownload.Add(req);
                OnQueueUpdateEvent(new QueueUpdateEventArgs(this.QueueCount));
            }
            catch (Exception ex)
            {
                BaseConfig.MyAnimeLog.Write(ex.ToString());
            }
        }