public ImageDownloadEventArgs(string status, ImageDownloadRequest req, ImageDownloadEventType eventType) { Status = status; Req = req; EventType = eventType; ImageType = Req.ImageType; ; }
public void DownloadAniDBCover(AniDB_AnimeVM anime, bool forceDownload) { if (string.IsNullOrEmpty(anime.Picname)) return; try { if (anime.AnimeID == 8580) Console.Write(""); 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) { Utils.ShowErrorMessage(ex); } }
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.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); case ImageEntityType.AniDB_Character: AniDB_CharacterVM chr = req.ImageData as AniDB_CharacterVM; return(chr.ImagePathPlain); case ImageEntityType.AniDB_Creator: AniDB_SeiyuuVM cre = req.ImageData as AniDB_SeiyuuVM; return(cre.ImagePathPlain); default: return(""); } }
public void DownloadTvDBPoster(TvDB_ImagePosterVM poster, bool forceDownload) { if (string.IsNullOrEmpty(poster.BannerPath)) return; try { string url = string.Format(Constants.URLS.TvDB_Images, poster.BannerPath); string filename = poster.FullImagePath; ImageDownloadRequest req = new ImageDownloadRequest(ImageEntityType.TvDB_Cover, 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) { Utils.ShowErrorMessage(ex); } }
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) { logger.ErrorException(ex.ToString(), ex); } }
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.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_Friend: Trakt_FriendVM trakFriend = req.ImageData as Trakt_FriendVM; return trakFriend.Trakt_FriendID.ToString(); case ImageEntityType.Trakt_ActivityScrobble: Trakt_ActivityScrobbleVM trakScrobble = req.ImageData as Trakt_ActivityScrobbleVM; return trakScrobble.User.Trakt_FriendID.ToString(); case ImageEntityType.Trakt_ShoutUser: Trakt_ShoutUserVM traktShoutUser = req.ImageData as Trakt_ShoutUserVM; return traktShoutUser.User.Trakt_FriendID.ToString(); case ImageEntityType.Trakt_Episode: Trakt_EpisodeVM trakEp = req.ImageData as Trakt_EpisodeVM; return trakEp.Trakt_EpisodeID.ToString(); case ImageEntityType.Trakt_WatchedEpisode: Trakt_WatchedEpisodeVM trakwEp = req.ImageData as Trakt_WatchedEpisodeVM; return trakwEp.Trakt_EpisodeID.ToString(); default: return ""; } }
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.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_Friend: Trakt_FriendVM trakFriend = req.ImageData as Trakt_FriendVM; return trakFriend.FullImagePathPlain; case ImageEntityType.Trakt_ActivityScrobble: Trakt_ActivityScrobbleVM trakScrobble = req.ImageData as Trakt_ActivityScrobbleVM; return trakScrobble.UserFullImagePathPlain; case ImageEntityType.Trakt_ShoutUser: Trakt_ShoutUserVM trakShoutUser = req.ImageData as Trakt_ShoutUserVM; return trakShoutUser.UserFullImagePathPlain; case ImageEntityType.Trakt_Episode: Trakt_EpisodeVM trakEp = req.ImageData as Trakt_EpisodeVM; return trakEp.FullImagePathPlain; case ImageEntityType.Trakt_WatchedEpisode: Trakt_WatchedEpisodeVM trakwEp = req.ImageData as Trakt_WatchedEpisodeVM; return trakwEp.FullImagePathPlain; default: return ""; } }
public void RefreshTraktFriends(bool traktScrobbles, bool traktShouts) { try { System.Windows.Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (Action)delegate() { TraktActivity.Clear(); }); JMMServerBinary.Contract_Trakt_Activity traktActivity = JMMServerVM.Instance.clientBinaryHTTP.GetTraktFriendInfo(AppSettings.Dash_TraktFriends_Items, AppSettings.Dash_TraktFriends_AnimeOnly, traktShouts, traktScrobbles); List<object> activity = new List<object>(); if (traktActivity.HasTraktAccount) { foreach (JMMServerBinary.Contract_Trakt_FriendFrequest contractFriend in traktActivity.TraktFriendRequests) { Trakt_FriendRequestVM req = new Trakt_FriendRequestVM(contractFriend); activity.Add(req); } foreach (JMMServerBinary.Contract_Trakt_FriendActivity contractAct in traktActivity.TraktFriendActivity) { if (contractAct.ActivityAction == (int)TraktActivityAction.Scrobble) { Trakt_ActivityScrobbleVM scrobble = new Trakt_ActivityScrobbleVM(contractAct); if (!string.IsNullOrEmpty(scrobble.UserFullImagePath) && !File.Exists(scrobble.UserFullImagePath)) { // re-download the friends avatar image try { System.Windows.Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (Action)delegate() { ImageDownloadRequest req = new ImageDownloadRequest(ImageEntityType.Trakt_ActivityScrobble, scrobble, true); MainWindow.imageHelper.DownloadImage(req); }); } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); } } activity.Add(scrobble); } else if (contractAct.ActivityAction == (int)TraktActivityAction.Shout) { if (contractAct.ActivityType == (int)TraktActivityType.Episode) { Trakt_ActivityShoutEpisodeVM shoutEp = new Trakt_ActivityShoutEpisodeVM(contractAct); activity.Add(shoutEp); } else { Trakt_ActivityShoutShowVM shoutShow = new Trakt_ActivityShoutShowVM(contractAct); activity.Add(shoutShow); } } } foreach (JMMServerBinary.Contract_Trakt_Friend contract in traktActivity.TraktFriends) { if (contract.WatchedEpisodes != null && contract.WatchedEpisodes.Count > 0) { Trakt_FriendVM friend = new Trakt_FriendVM(contract); activity.Add(friend); } } } else { Trakt_SignupVM signup = new Trakt_SignupVM(); activity.Add(signup); } System.Windows.Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (Action)delegate() { foreach (object act in activity) TraktActivity.Add(act); ViewTraktActivity.Refresh(); }); } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); } finally { } }
public void DownloadMovieDBFanart(MovieDB_FanartVM fanart, bool forceDownload) { if (string.IsNullOrEmpty(fanart.URL)) return; try { string url = fanart.URL; string filename = fanart.FullImagePath; ImageDownloadRequest req = new ImageDownloadRequest(ImageEntityType.MovieDB_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)) { 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) { Utils.ShowErrorMessage(ex); } }
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.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_Friend: Trakt_FriendVM trakFriend = req.ImageData as Trakt_FriendVM; return(trakFriend.Trakt_FriendID.ToString()); case ImageEntityType.Trakt_ActivityScrobble: Trakt_ActivityScrobbleVM trakScrobble = req.ImageData as Trakt_ActivityScrobbleVM; return(trakScrobble.User.Trakt_FriendID.ToString()); case ImageEntityType.Trakt_ShoutUser: Trakt_ShoutUserVM traktShoutUser = req.ImageData as Trakt_ShoutUserVM; return(traktShoutUser.User.Trakt_FriendID.ToString()); case ImageEntityType.Trakt_Episode: Trakt_EpisodeVM trakEp = req.ImageData as Trakt_EpisodeVM; return(trakEp.Trakt_EpisodeID.ToString()); case ImageEntityType.Trakt_WatchedEpisode: Trakt_WatchedEpisodeVM trakwEp = req.ImageData as Trakt_WatchedEpisodeVM; return(trakwEp.Trakt_EpisodeID.ToString()); default: return(""); } }
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.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_Friend: Trakt_FriendVM trakFriend = req.ImageData as Trakt_FriendVM; return(trakFriend.FullImagePathPlain); case ImageEntityType.Trakt_ActivityScrobble: Trakt_ActivityScrobbleVM trakScrobble = req.ImageData as Trakt_ActivityScrobbleVM; return(trakScrobble.UserFullImagePathPlain); case ImageEntityType.Trakt_ShoutUser: Trakt_ShoutUserVM trakShoutUser = req.ImageData as Trakt_ShoutUserVM; return(trakShoutUser.UserFullImagePathPlain); case ImageEntityType.Trakt_Episode: Trakt_EpisodeVM trakEp = req.ImageData as Trakt_EpisodeVM; return(trakEp.FullImagePathPlain); case ImageEntityType.Trakt_WatchedEpisode: Trakt_WatchedEpisodeVM trakwEp = req.ImageData as Trakt_WatchedEpisodeVM; return(trakwEp.FullImagePathPlain); default: return(""); } }
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.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; case ImageEntityType.AniDB_Character: AniDB_CharacterVM chr = req.ImageData as AniDB_CharacterVM; return chr.ImagePathPlain; case ImageEntityType.AniDB_Creator: AniDB_SeiyuuVM cre = req.ImageData as AniDB_SeiyuuVM; return cre.ImagePathPlain; default: return ""; } }
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.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_CommentUser: Trakt_CommentUserVM traktShoutUser = req.ImageData as Trakt_CommentUserVM; return traktShoutUser.User.Trakt_FriendID.ToString(); case ImageEntityType.Trakt_Episode: Trakt_EpisodeVM trakEp = req.ImageData as Trakt_EpisodeVM; return trakEp.Trakt_EpisodeID.ToString(); case ImageEntityType.AniDB_Character: AniDB_CharacterVM chr = req.ImageData as AniDB_CharacterVM; return chr.AniDB_CharacterID.ToString(); case ImageEntityType.AniDB_Creator: AniDB_SeiyuuVM cre = req.ImageData as AniDB_SeiyuuVM; return cre.AniDB_SeiyuuID.ToString(); default: return ""; } }
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.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_CommentUser: Trakt_CommentUserVM traktShoutUser = req.ImageData as Trakt_CommentUserVM; return(traktShoutUser.User.Trakt_FriendID.ToString()); case ImageEntityType.Trakt_Episode: Trakt_EpisodeVM trakEp = req.ImageData as Trakt_EpisodeVM; return(trakEp.Trakt_EpisodeID.ToString()); case ImageEntityType.AniDB_Character: AniDB_CharacterVM chr = req.ImageData as AniDB_CharacterVM; return(chr.AniDB_CharacterID.ToString()); case ImageEntityType.AniDB_Creator: AniDB_SeiyuuVM cre = req.ImageData as AniDB_SeiyuuVM; return(cre.AniDB_SeiyuuID.ToString()); default: return(""); } }
public void DownloadTraktEpisode(Trakt_EpisodeVM episode, bool forceDownload) { if (string.IsNullOrEmpty(episode.EpisodeImage)) return; try { string url = episode.EpisodeImage; string filename = episode.FullImagePath; ImageDownloadRequest req = new ImageDownloadRequest(ImageEntityType.Trakt_Episode, episode, 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(episode.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) { Utils.ShowErrorMessage(ex); } }
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) { logger.ErrorException(ex.ToString(), ex); } }
void refreshDataWorker_DoWork(object sender, DoWorkEventArgs e) { List<Trakt_ShoutUserVM> tempShouts = new List<Trakt_ShoutUserVM>(); try { AnimeSeriesVM animeSeries = (AnimeSeriesVM)e.Argument; if (animeSeries == null) return; List<JMMServerBinary.Contract_Trakt_ShoutUser> rawShouts = JMMServerVM.Instance.clientBinaryHTTP.GetTraktShoutsForAnime(animeSeries.AniDB_ID); foreach (JMMServerBinary.Contract_Trakt_ShoutUser contract in rawShouts) { Trakt_ShoutUserVM shout = new Trakt_ShoutUserVM(contract); if (!string.IsNullOrEmpty(shout.UserFullImagePath) && !File.Exists(shout.UserFullImagePath)) { // re-download the friends avatar image try { ImageDownloadRequest req = new ImageDownloadRequest(ImageEntityType.Trakt_ShoutUser, shout, false); MainWindow.imageHelper.DownloadImage(req); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } tempShouts.Add(shout); } } catch (Exception ex) { Utils.ShowErrorMessage(ex); } e.Result = tempShouts; }