Exemplo n.º 1
0
        public void DownloadMovieDBPoster(VM_MovieDB_Poster poster, bool forceDownload)
        {
            if (string.IsNullOrEmpty(poster.URL))
            {
                return;
            }

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

                ImageDownloadRequest req = new ImageDownloadRequest(ImageEntityType.MovieDB_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))
                    {
                        imagesToDownload.Enqueue(req);
                        OnQueueUpdateEvent(new QueueUpdateEventArgs(QueueCount));
                        return;
                    }

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

                imagesToDownload.Enqueue(req);
                OnQueueUpdateEvent(new QueueUpdateEventArgs(QueueCount));
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }
        }
Exemplo n.º 2
0
        public void DownloadTvDBFanart(VM_TvDB_ImageFanart fanart, bool forceDownload)
        {
            if (string.IsNullOrEmpty(fanart.BannerPath))
            {
                return;
            }

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

                ImageDownloadRequest req = new ImageDownloadRequest(ImageEntityType.TvDB_FanArt, fanart, 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(fanart.FullImagePath) || !File.Exists(fanart.FullThumbnailPath))
                    {
                        imagesToDownload.Enqueue(req);
                        OnQueueUpdateEvent(new QueueUpdateEventArgs(QueueCount));
                        return;
                    }

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

                imagesToDownload.Enqueue(req);
                OnQueueUpdateEvent(new QueueUpdateEventArgs(QueueCount));
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }
        }
Exemplo n.º 3
0
        public void DownloadImage(ImageDownloadRequest req)
        {
            try
            {
                lock (downloadsLock)
                {
                    string fileName      = GetFileName(req, false);
                    string entityID      = GetEntityID(req);
                    bool   downloadImage = true;
                    bool   fileExists    = string.IsNullOrEmpty(fileName) || File.Exists(fileName);

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

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


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

                        try
                        {
                            using (Stream img = VM_ShokoServer.Instance.ShokoImages.GetImage(int.Parse(entityID), (int)req.ImageType, false))
                                using (Stream wstream = File.OpenWrite(tempName))
                                {
                                    img.CopyTo(wstream);
                                }
                        }
                        catch
                        {
                            return;
                        }

                        // 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 && !req.ForceDownload)
                        {
                            downloadImage = false;
                        }

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

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

                            try
                            {
                                using (Stream img = VM_ShokoServer.Instance.ShokoImages.GetImage(int.Parse(entityID), (int)req.ImageType, false))
                                    using (Stream wstream = File.OpenWrite(tempName))
                                    {
                                        img.CopyTo(wstream);
                                    }
                            }
                            catch
                            {
                                return;
                            }


                            // 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)
            {
                logger.Error(ex, ex.ToString());
            }
        }
Exemplo n.º 4
0
        private string GetFileName(ImageDownloadRequest req, bool thumbNailOnly)
        {
            switch (req.ImageType)
            {
            case ImageEntityType.AniDB_Cover:

                VM_AniDB_Anime anime = req.ImageData as VM_AniDB_Anime;
                return(anime?.PosterPathNoDefaultPlain);

            case ImageEntityType.TvDB_Cover:

                VM_TvDB_ImagePoster poster = req.ImageData as VM_TvDB_ImagePoster;
                return(poster?.FullImagePathPlain);

            case ImageEntityType.TvDB_Banner:

                VM_TvDB_ImageWideBanner banner = req.ImageData as VM_TvDB_ImageWideBanner;
                return(banner?.FullImagePathPlain);

            case ImageEntityType.TvDB_Episode:

                VM_TvDB_Episode episode = req.ImageData as VM_TvDB_Episode;
                return(episode?.FullImagePathPlain);

            case ImageEntityType.TvDB_FanArt:

                VM_TvDB_ImageFanart fanart = req.ImageData as VM_TvDB_ImageFanart;

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

            case ImageEntityType.MovieDB_Poster:

                VM_MovieDB_Poster moviePoster = req.ImageData as VM_MovieDB_Poster;
                return(moviePoster?.FullImagePathPlain);

            case ImageEntityType.MovieDB_FanArt:

                VM_MovieDB_Fanart movieFanart = req.ImageData as VM_MovieDB_Fanart;
                return(movieFanart?.FullImagePathPlain);

            case ImageEntityType.AniDB_Character:

                VM_AniDB_Character chr = req.ImageData as VM_AniDB_Character;
                return(chr?.ImagePathPlain);

            case ImageEntityType.AniDB_Creator:

                VM_AniDB_Seiyuu cre = req.ImageData as VM_AniDB_Seiyuu;
                return(cre?.ImagePathPlain);

            default:
                return(string.Empty);
            }
        }
Exemplo n.º 5
0
        private string GetEntityID(ImageDownloadRequest req)
        {
            switch (req.ImageType)
            {
            case ImageEntityType.AniDB_Cover:

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

            case ImageEntityType.TvDB_Cover:

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

            case ImageEntityType.TvDB_Banner:

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

            case ImageEntityType.TvDB_Episode:

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

            case ImageEntityType.TvDB_FanArt:

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

            case ImageEntityType.MovieDB_Poster:

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

            case ImageEntityType.MovieDB_FanArt:

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

            case ImageEntityType.Trakt_Poster:

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

            case ImageEntityType.Trakt_Fanart:

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

            case ImageEntityType.Trakt_CommentUser:

                VM_Trakt_CommentUser traktShoutUser = req.ImageData as VM_Trakt_CommentUser;
                return(traktShoutUser.User.Trakt_FriendID.ToString());

            case ImageEntityType.Trakt_Episode:

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

            case ImageEntityType.AniDB_Character:

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

            case ImageEntityType.AniDB_Creator:

                VM_AniDB_Seiyuu cre = req.ImageData as VM_AniDB_Seiyuu;
                return(cre.AniDB_SeiyuuID.ToString());

            default:
                return("");
            }
        }