public void DownloadTvDBEpisode(TvDB_Episode episode, bool forceDownload) { if (string.IsNullOrEmpty(episode.Filename)) { return; } try { ImageDownloadRequest req = new ImageDownloadRequest(ImageEntityType.TvDB_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.GetFullImagePath())) { imagesToDownload.Add(req); OnQueueUpdateEvent(new QueueUpdateEventArgs(QueueCount)); return; } // the file exists so don't download it again return; } imagesToDownload.Add(req); OnQueueUpdateEvent(new QueueUpdateEventArgs(QueueCount)); } catch (Exception ex) { BaseConfig.MyAnimeLog.Write(ex.ToString()); } }
private string GetFileName(ImageDownloadRequest req, bool thumbNailOnly) { switch (req.ImageType) { case ImageEntityType.AniDB_Cover: SVR_AniDB_Anime anime = req.ImageData as SVR_AniDB_Anime; return(anime.PosterPath); case ImageEntityType.TvDB_Episode: TvDB_Episode ep = req.ImageData as TvDB_Episode; return(ep.GetFullImagePath()); case ImageEntityType.TvDB_FanArt: TvDB_ImageFanart fanart = req.ImageData as TvDB_ImageFanart; if (thumbNailOnly) { return(fanart.GetFullThumbnailPath()); } else { return(fanart.GetFullImagePath()); } case ImageEntityType.TvDB_Cover: TvDB_ImagePoster poster = req.ImageData as TvDB_ImagePoster; return(poster.GetFullImagePath()); case ImageEntityType.TvDB_Banner: TvDB_ImageWideBanner wideBanner = req.ImageData as TvDB_ImageWideBanner; return(wideBanner.GetFullImagePath()); case ImageEntityType.MovieDB_Poster: MovieDB_Poster moviePoster = req.ImageData as MovieDB_Poster; return(moviePoster.GetFullImagePath()); case ImageEntityType.MovieDB_FanArt: MovieDB_Fanart movieFanart = req.ImageData as MovieDB_Fanart; return(movieFanart.GetFullImagePath()); case ImageEntityType.AniDB_Character: AniDB_Character chr = req.ImageData as AniDB_Character; return(chr.GetPosterPath()); case ImageEntityType.AniDB_Creator: AniDB_Seiyuu creator = req.ImageData as AniDB_Seiyuu; return(creator.GetPosterPath()); default: return(string.Empty); } }
internal static Episode GenerateFromAnimeEpisode(NancyContext ctx, SVR_AnimeEpisode aep, int uid, int level) { Episode ep = new Episode { id = aep.AnimeEpisodeID, eptype = aep.EpisodeTypeEnum.ToString(), art = new ArtCollection() }; var userrating = aep.UserRating; if (userrating > 0) { ep.userrating = userrating.ToString(CultureInfo.InvariantCulture); } if (double.TryParse(ep.rating, out double rating)) { // 0.1 should be the absolute lowest rating if (rating > 10) { ep.rating = (rating / 100).ToString(CultureInfo.InvariantCulture); } } CL_AnimeEpisode_User cae = aep.GetUserContract(uid); if (cae != null) { ep.name = cae.AniDB_EnglishName; ep.summary = cae.Description; ep.year = cae.AniDB_AirDate?.Year.ToString(CultureInfo.InvariantCulture); ep.air = cae.AniDB_AirDate?.ToPlexDate(); ep.votes = cae.AniDB_Votes; ep.rating = cae.AniDB_Rating; ep.view = cae.IsWatched() ? 1 : 0; ep.epnumber = cae.EpisodeNumber; } TvDB_Episode tvep = aep.TvDBEpisode; if (tvep != null) { if (!string.IsNullOrEmpty(tvep.EpisodeName)) { ep.name = tvep.EpisodeName; } if (Misc.IsImageValid(tvep.GetFullImagePath())) { ep.art.thumb.Add(new Art { index = 0, url = APIHelper.ConstructImageLinkFromTypeAndId(ctx, (int)ImageEntityType.TvDB_Episode, tvep.TvDB_EpisodeID) }); } var fanarts = aep.GetAnimeSeries()?.GetAnime()?.Contract?.AniDBAnime?.Fanarts; if (fanarts != null && fanarts.Count > 0) { var cont_image = fanarts[new Random().Next(fanarts.Count)]; ep.art.fanart.Add(new Art() { url = APIHelper.ConstructImageLinkFromTypeAndId(ctx, cont_image.ImageType, cont_image.AniDB_Anime_DefaultImageID), index = 0 }); } else { ep.art.fanart.Add(new Art { index = 0, url = APIHelper.ConstructImageLinkFromTypeAndId(ctx, (int)ImageEntityType.TvDB_Episode, tvep.TvDB_EpisodeID) }); } if (!string.IsNullOrEmpty(tvep.Overview)) { ep.summary = tvep.Overview; } int zeroPadding = tvep.EpisodeNumber.ToString().Length; string episodeNumber = tvep.EpisodeNumber.ToString().PadLeft(zeroPadding, '0'); zeroPadding = tvep.SeasonNumber.ToString().Length; string seasonNumber = tvep.SeasonNumber.ToString().PadLeft(zeroPadding, '0'); ep.season = $"{seasonNumber}x{episodeNumber}"; var airdate = tvep.AirDate; if (airdate != null) { ep.air = airdate.Value.ToPlexDate(); ep.year = airdate.Value.Year.ToString(CultureInfo.InvariantCulture); } } if (string.IsNullOrEmpty(ep.summary)) { ep.summary = string.Intern("Episode Overview not Available"); } if (ep.art.thumb.Count == 0) { ep.art.thumb.Add( new Art { index = 0, url = APIHelper.ConstructSupportImageLink(ctx, "plex_404.png") }); ep.art.fanart.Add(new Art { index = 0, url = APIHelper.ConstructSupportImageLink(ctx, "plex_404.png") }); } if (string.IsNullOrEmpty(ep.year)) { ep.year = aep.GetAnimeSeries().AirDate.Year.ToString(CultureInfo.InvariantCulture); } if (level > 0) { List <SVR_VideoLocal> vls = aep.GetVideoLocals(); if (vls.Count > 0) { ep.files = new List <RawFile>(); foreach (SVR_VideoLocal vl in vls) { RawFile file = new RawFile(ctx, vl, (level - 1), uid); ep.files.Add(file); } } } return(ep); }
public static string GetImagePath(ImageEntityType type, int id) { string path; switch (type) { // 1 case ImageEntityType.AniDB_Cover: SVR_AniDB_Anime anime = Repo.Instance.AniDB_Anime.GetByID(id); if (anime == null) { return(null); } path = anime.PosterPath; if (File.Exists(path)) { return(path); } else { path = string.Empty; } break; // 4 case ImageEntityType.TvDB_Banner: TvDB_ImageWideBanner wideBanner = Repo.Instance.TvDB_ImageWideBanner.GetByID(id); if (wideBanner == null) { return(null); } path = wideBanner.GetFullImagePath(); if (File.Exists(path)) { return(path); } else { path = string.Empty; } break; // 5 case ImageEntityType.TvDB_Cover: TvDB_ImagePoster poster = Repo.Instance.TvDB_ImagePoster.GetByID(id); if (poster == null) { return(null); } path = poster.GetFullImagePath(); if (File.Exists(path)) { return(path); } else { path = string.Empty; } break; // 6 case ImageEntityType.TvDB_Episode: TvDB_Episode ep = Repo.Instance.TvDB_Episode.GetByID(id); if (ep == null) { return(null); } path = ep.GetFullImagePath(); if (File.Exists(path)) { return(path); } else { path = string.Empty; } break; // 7 case ImageEntityType.TvDB_FanArt: TvDB_ImageFanart fanart = Repo.Instance.TvDB_ImageFanart.GetByID(id); if (fanart == null) { return(null); } path = fanart.GetFullImagePath(); if (File.Exists(path)) { return(path); } path = string.Empty; break; // 8 case ImageEntityType.MovieDB_FanArt: MovieDB_Fanart mFanart = Repo.Instance.MovieDB_Fanart.GetByID(id); if (mFanart == null) { return(null); } mFanart = Repo.Instance.MovieDB_Fanart.GetByOnlineID(mFanart.URL); if (mFanart == null) { return(null); } path = mFanart.GetFullImagePath(); if (File.Exists(path)) { return(path); } else { path = string.Empty; } break; // 9 case ImageEntityType.MovieDB_Poster: MovieDB_Poster mPoster = Repo.Instance.MovieDB_Poster.GetByID(id); if (mPoster == null) { return(null); } mPoster = Repo.Instance.MovieDB_Poster.GetByOnlineID(mPoster.URL); if (mPoster == null) { return(null); } path = mPoster.GetFullImagePath(); if (File.Exists(path)) { return(path); } else { path = string.Empty; } break; case ImageEntityType.Character: AnimeCharacter character = Repo.Instance.AnimeCharacter.GetByID(id); if (character == null) { return(null); } path = ImageUtils.GetBaseAniDBCharacterImagesPath() + Path.DirectorySeparatorChar + character.ImagePath; if (File.Exists(path)) { return(path); } else { path = string.Empty; } break; case ImageEntityType.Staff: var staff = Repo.Instance.AnimeStaff.GetByID(id); if (staff == null) { return(null); } path = ImageUtils.GetBaseAniDBCreatorImagesPath() + Path.DirectorySeparatorChar + staff.ImagePath; if (File.Exists(path)) { return(path); } else { path = string.Empty; } break; default: path = string.Empty; break; } return(path); }
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(); }
/// <summary> /// Internal function that return valid image file path on server that exist /// </summary> /// <param name="id">image id</param> /// <param name="type">image type</param> /// <param name="thumb">thumb mode</param> /// <returns>string</returns> internal string ReturnImagePath(int type, int id, bool thumb) { JMMImageType imageType = (JMMImageType)type; string path = ""; switch (imageType) { // 1 case JMMImageType.AniDB_Cover: SVR_AniDB_Anime anime = RepoFactory.AniDB_Anime.GetByAnimeID(id); if (anime == null) { return(null); } path = anime.PosterPath; if (Pri.LongPath.File.Exists(path)) { return(path); } else { path = ""; logger.Trace("Could not find AniDB_Cover image: {0}", anime.PosterPath); } break; // 2 case JMMImageType.AniDB_Character: AniDB_Character chr = RepoFactory.AniDB_Character.GetByCharID(id); if (chr == null) { return(null); } path = chr.GetPosterPath(); if (Pri.LongPath.File.Exists(path)) { return(path); } else { path = ""; logger.Trace("Could not find AniDB_Character image: {0}", chr.GetPosterPath()); } break; // 3 case JMMImageType.AniDB_Creator: AniDB_Seiyuu creator = RepoFactory.AniDB_Seiyuu.GetBySeiyuuID(id); if (creator == null) { return(null); } path = creator.GetPosterPath(); if (Pri.LongPath.File.Exists(path)) { return(path); } else { path = ""; logger.Trace("Could not find AniDB_Creator image: {0}", creator.GetPosterPath()); } break; // 4 case JMMImageType.TvDB_Banner: TvDB_ImageWideBanner wideBanner = RepoFactory.TvDB_ImageWideBanner.GetByID(id); if (wideBanner == null) { return(null); } path = wideBanner.GetFullImagePath(); if (Pri.LongPath.File.Exists(path)) { return(path); } else { path = ""; logger.Trace("Could not find TvDB_Banner image: {0}", wideBanner.GetFullImagePath()); } break; // 5 case JMMImageType.TvDB_Cover: TvDB_ImagePoster poster = RepoFactory.TvDB_ImagePoster.GetByID(id); if (poster == null) { return(null); } path = poster.GetFullImagePath(); if (Pri.LongPath.File.Exists(path)) { return(path); } else { path = ""; logger.Trace("Could not find TvDB_Cover image: {0}", poster.GetFullImagePath()); } break; // 6 case JMMImageType.TvDB_Episode: TvDB_Episode ep = RepoFactory.TvDB_Episode.GetByID(id); if (ep == null) { return(null); } path = ep.GetFullImagePath(); if (Pri.LongPath.File.Exists(path)) { return(path); } else { path = ""; logger.Trace("Could not find TvDB_Episode image: {0}", ep.GetFullImagePath()); } break; // 7 case JMMImageType.TvDB_FanArt: TvDB_ImageFanart fanart = RepoFactory.TvDB_ImageFanart.GetByID(id); if (fanart == null) { return(null); } if (thumb) { //ratio path = fanart.GetFullThumbnailPath(); if (Pri.LongPath.File.Exists(path)) { return(path); } else { path = ""; logger.Trace("Could not find TvDB_FanArt image: {0}", fanart.GetFullThumbnailPath()); } } else { path = fanart.GetFullImagePath(); if (Pri.LongPath.File.Exists(path)) { return(path); } else { path = ""; logger.Trace("Could not find TvDB_FanArt image: {0}", fanart.GetFullImagePath()); } } break; // 8 case JMMImageType.MovieDB_FanArt: MovieDB_Fanart mFanart = RepoFactory.MovieDB_Fanart.GetByID(id); if (mFanart == null) { return(null); } mFanart = RepoFactory.MovieDB_Fanart.GetByOnlineID(mFanart.URL); if (mFanart == null) { return(null); } path = mFanart.GetFullImagePath(); if (Pri.LongPath.File.Exists(path)) { return(path); } else { path = ""; logger.Trace("Could not find MovieDB_FanArt image: {0}", mFanart.GetFullImagePath()); } break; // 9 case JMMImageType.MovieDB_Poster: MovieDB_Poster mPoster = RepoFactory.MovieDB_Poster.GetByID(id); if (mPoster == null) { return(null); } mPoster = RepoFactory.MovieDB_Poster.GetByOnlineID(mPoster.URL); if (mPoster == null) { return(null); } path = mPoster.GetFullImagePath(); if (Pri.LongPath.File.Exists(path)) { return(path); } else { path = ""; logger.Trace("Could not find MovieDB_Poster image: {0}", mPoster.GetFullImagePath()); } break; // 10 case JMMImageType.Trakt_Poster: Trakt_ImagePoster tPoster = RepoFactory.Trakt_ImagePoster.GetByID(id); if (tPoster == null) { return(null); } path = tPoster.GetFullImagePath(); if (Pri.LongPath.File.Exists(path)) { return(path); } else { path = ""; logger.Trace("Could not find Trakt_Poster image: {0}", tPoster.GetFullImagePath()); } break; // 11 case JMMImageType.Trakt_Fanart: Trakt_ImageFanart tFanart = RepoFactory.Trakt_ImageFanart.GetByID(id); if (tFanart == null) { return(null); } path = tFanart.GetFullImagePath(); if (Pri.LongPath.File.Exists(path)) { return(path); } else { path = ""; logger.Trace("Could not find Trakt_Fanart image: {0}", tFanart.GetFullImagePath()); } break; // 12 + 16 case JMMImageType.Trakt_Episode: case JMMImageType.Trakt_WatchedEpisode: Trakt_Episode tEpisode = RepoFactory.Trakt_Episode.GetByID(id); if (tEpisode == null) { return(null); } path = tEpisode.GetFullImagePath(); if (Pri.LongPath.File.Exists(path)) { return(path); } else { path = ""; logger.Trace("Could not find Trakt_Episode image: {0}", tEpisode.GetFullImagePath()); } break; // 0, 13-15, 17+ default: path = ""; break; } return(path); }
public string GetImagePath(int imageId, int imageType, bool?thumnbnailOnly) { ImageEntityType it = (ImageEntityType)imageType; switch (it) { case ImageEntityType.AniDB_Cover: SVR_AniDB_Anime anime = Repo.Instance.AniDB_Anime.GetByID(imageId); if (anime == null) { return(null); } if (File.Exists(anime.PosterPath)) { return(anime.PosterPath); } else { logger.Trace("Could not find AniDB_Cover image: {0}", anime.PosterPath); return(string.Empty); } case ImageEntityType.AniDB_Character: AniDB_Character chr = Repo.Instance.AniDB_Character.GetByID(imageId); if (chr == null) { return(null); } if (File.Exists(chr.GetPosterPath())) { return(chr.GetPosterPath()); } else { logger.Trace("Could not find AniDB_Character image: {0}", chr.GetPosterPath()); return(string.Empty); } case ImageEntityType.AniDB_Creator: AniDB_Seiyuu creator = Repo.Instance.AniDB_Seiyuu.GetByID(imageId); if (creator == null) { return(string.Empty); } if (File.Exists(creator.GetPosterPath())) { return(creator.GetPosterPath()); } else { logger.Trace("Could not find AniDB_Creator image: {0}", creator.GetPosterPath()); return(string.Empty); } case ImageEntityType.TvDB_Cover: TvDB_ImagePoster poster = Repo.Instance.TvDB_ImagePoster.GetByID(imageId); if (poster == null) { return(null); } if (File.Exists(poster.GetFullImagePath())) { return(poster.GetFullImagePath()); } else { logger.Trace("Could not find TvDB_Cover image: {0}", poster.GetFullImagePath()); return(string.Empty); } case ImageEntityType.TvDB_Banner: TvDB_ImageWideBanner wideBanner = Repo.Instance.TvDB_ImageWideBanner.GetByID(imageId); if (wideBanner == null) { return(null); } if (File.Exists(wideBanner.GetFullImagePath())) { return(wideBanner.GetFullImagePath()); } else { logger.Trace("Could not find TvDB_Banner image: {0}", wideBanner.GetFullImagePath()); return(string.Empty); } case ImageEntityType.TvDB_Episode: TvDB_Episode ep = Repo.Instance.TvDB_Episode.GetByID(imageId); if (ep == null) { return(null); } if (File.Exists(ep.GetFullImagePath())) { return(ep.GetFullImagePath()); } else { logger.Trace("Could not find TvDB_Episode image: {0}", ep.GetFullImagePath()); return(string.Empty); } case ImageEntityType.TvDB_FanArt: TvDB_ImageFanart fanart = Repo.Instance.TvDB_ImageFanart.GetByID(imageId); if (fanart == null) { return(null); } if (thumnbnailOnly.HasValue && thumnbnailOnly.Value) { if (File.Exists(fanart.GetFullThumbnailPath())) { return(fanart.GetFullThumbnailPath()); } logger.Trace("Could not find TvDB_FanArt image: {0}", fanart.GetFullThumbnailPath()); return(string.Empty); } else { if (File.Exists(fanart.GetFullImagePath())) { return(fanart.GetFullImagePath()); } logger.Trace("Could not find TvDB_FanArt image: {0}", fanart.GetFullImagePath()); return(string.Empty); } case ImageEntityType.MovieDB_Poster: MovieDB_Poster mPoster = Repo.Instance.MovieDB_Poster.GetByID(imageId); if (mPoster == null) { return(null); } // now find only the original size mPoster = Repo.Instance.MovieDB_Poster.GetByOnlineID(mPoster.URL); if (mPoster == null) { return(null); } if (File.Exists(mPoster.GetFullImagePath())) { return(mPoster.GetFullImagePath()); } else { logger.Trace("Could not find MovieDB_Poster image: {0}", mPoster.GetFullImagePath()); return(string.Empty); } case ImageEntityType.MovieDB_FanArt: MovieDB_Fanart mFanart = Repo.Instance.MovieDB_Fanart.GetByID(imageId); if (mFanart == null) { return(null); } mFanart = Repo.Instance.MovieDB_Fanart.GetByOnlineID(mFanart.URL); if (mFanart == null) { return(null); } if (File.Exists(mFanart.GetFullImagePath())) { return(mFanart.GetFullImagePath()); } else { logger.Trace("Could not find MovieDB_FanArt image: {0}", mFanart.GetFullImagePath()); return(string.Empty); } default: return(string.Empty); } }
public static async Task <TvDB_Episode> QueueEpisodeImageDownloadAsync(int tvDBEpisodeID, bool downloadImages, bool forceRefresh) { try { TvDB_Episode ep = Repo.Instance.TvDB_Episode.GetByTvDBID(tvDBEpisodeID); if (ep == null || forceRefresh) { EpisodeRecord episode = await GetEpisodeDetailsAsync(tvDBEpisodeID); if (episode == null) { return(null); } using (var eup = Repo.Instance.TvDB_Episode.BeginAddOrUpdate(() => Repo.Instance.TvDB_Episode.GetByTvDBID(tvDBEpisodeID))) { eup.Entity.Populate(episode); ep = eup.Commit(); } } if (downloadImages) { if (!string.IsNullOrEmpty(ep.Filename)) { bool fileExists = File.Exists(ep.GetFullImagePath()); if (!fileExists || forceRefresh) { CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(ep.TvDB_EpisodeID, ImageEntityType.TvDB_Episode, forceRefresh); cmd.Save(); } } } return(ep); } catch (TvDbServerException exception) { if (exception.StatusCode == (int)HttpStatusCode.Unauthorized) { client.Authentication.Token = null; await CheckAuthorizationAsync(); if (!string.IsNullOrEmpty(client.Authentication.Token)) { return(await QueueEpisodeImageDownloadAsync(tvDBEpisodeID, downloadImages, forceRefresh)); } // suppress 404 and move on } else if (exception.StatusCode == (int)HttpStatusCode.NotFound) { return(null); } logger.Error(exception, $"TvDB returned an error code: {exception.StatusCode}\n {exception.Message}"); } catch (Exception ex) { logger.Error(ex, $"Error in TVDBHelper.GetEpisodes: {ex}"); } return(null); }
private string GetRandomImagePath(int type) { ImageEntityType imageType = (ImageEntityType)type; string path; switch (imageType) { // 1 case ImageEntityType.AniDB_Cover: SVR_AniDB_Anime anime = RepoFactory.AniDB_Anime.GetAll() .Where(a => a?.PosterPath != null && !a.GetAllTags().Contains("18 restricted")) .GetRandomElement(); if (anime == null) { return(null); } path = anime.PosterPath; if (System.IO.File.Exists(path)) { return(path); } else { path = string.Empty; logger.Trace("Could not find AniDB_Cover image: {0}", anime.PosterPath); } break; // 2 case ImageEntityType.AniDB_Character: var chr = RepoFactory.AniDB_Anime.GetAll() .Where(a => a != null && !a.GetAllTags().Contains("18 restricted")) .SelectMany(a => a.GetAnimeCharacters()).Select(a => a.GetCharacter()).Where(a => a != null) .GetRandomElement(); if (chr == null) { return(null); } path = chr.GetPosterPath(); if (System.IO.File.Exists(path)) { return(path); } else { path = string.Empty; logger.Trace("Could not find AniDB_Character image: {0}", chr.GetPosterPath()); } break; // 3 -- this will likely be slow case ImageEntityType.AniDB_Creator: var creator = RepoFactory.AniDB_Anime.GetAll() .Where(a => a != null && !a.GetAllTags().Contains("18 restricted")) .SelectMany(a => a.GetAnimeCharacters()) .SelectMany(a => RepoFactory.AniDB_Character_Seiyuu.GetByCharID(a.CharID)) .Select(a => RepoFactory.AniDB_Seiyuu.GetBySeiyuuID(a.SeiyuuID)).Where(a => a != null) .GetRandomElement(); if (creator == null) { return(null); } path = creator.GetPosterPath(); if (System.IO.File.Exists(path)) { return(path); } else { path = string.Empty; logger.Trace("Could not find AniDB_Creator image: {0}", creator.GetPosterPath()); } break; // 4 case ImageEntityType.TvDB_Banner: // TvDB doesn't allow H content, so we get to skip the check! TvDB_ImageWideBanner wideBanner = RepoFactory.TvDB_ImageWideBanner.GetAll().GetRandomElement(); if (wideBanner == null) { return(null); } path = wideBanner.GetFullImagePath(); if (System.IO.File.Exists(path)) { return(path); } else { path = string.Empty; logger.Trace("Could not find TvDB_Banner image: {0}", wideBanner.GetFullImagePath()); } break; // 5 case ImageEntityType.TvDB_Cover: // TvDB doesn't allow H content, so we get to skip the check! TvDB_ImagePoster poster = RepoFactory.TvDB_ImagePoster.GetAll().GetRandomElement(); if (poster == null) { return(null); } path = poster.GetFullImagePath(); if (System.IO.File.Exists(path)) { return(path); } else { path = string.Empty; logger.Trace("Could not find TvDB_Cover image: {0}", poster.GetFullImagePath()); } break; // 6 case ImageEntityType.TvDB_Episode: // TvDB doesn't allow H content, so we get to skip the check! TvDB_Episode ep = RepoFactory.TvDB_Episode.GetAll().GetRandomElement(); if (ep == null) { return(null); } path = ep.GetFullImagePath(); if (System.IO.File.Exists(path)) { return(path); } else { path = string.Empty; logger.Trace("Could not find TvDB_Episode image: {0}", ep.GetFullImagePath()); } break; // 7 case ImageEntityType.TvDB_FanArt: // TvDB doesn't allow H content, so we get to skip the check! TvDB_ImageFanart fanart = RepoFactory.TvDB_ImageFanart.GetAll().GetRandomElement(); if (fanart == null) { return(null); } path = fanart.GetFullImagePath(); if (System.IO.File.Exists(path)) { return(path); } path = string.Empty; logger.Trace("Could not find TvDB_FanArt image: {0}", fanart.GetFullImagePath()); break; // 8 case ImageEntityType.MovieDB_FanArt: MovieDB_Fanart mFanart = RepoFactory.MovieDB_Fanart.GetAll().GetRandomElement(); if (mFanart == null) { return(null); } path = mFanart.GetFullImagePath(); if (System.IO.File.Exists(path)) { return(path); } else { path = string.Empty; logger.Trace("Could not find MovieDB_FanArt image: {0}", mFanart.GetFullImagePath()); } break; // 9 case ImageEntityType.MovieDB_Poster: MovieDB_Poster mPoster = RepoFactory.MovieDB_Poster.GetAll().GetRandomElement(); if (mPoster == null) { return(null); } path = mPoster.GetFullImagePath(); if (System.IO.File.Exists(path)) { return(path); } else { path = string.Empty; logger.Trace("Could not find MovieDB_Poster image: {0}", mPoster.GetFullImagePath()); } break; case ImageEntityType.Character: var character = RepoFactory.AniDB_Anime.GetAll() .Where(a => a != null && !a.GetAllTags().Contains("18 restricted")) .SelectMany(a => RepoFactory.CrossRef_Anime_Staff.GetByAnimeID(a.AnimeID)) .Where(a => a.RoleType == (int)StaffRoleType.Seiyuu && a.RoleID.HasValue) .Select(a => RepoFactory.AnimeCharacter.GetByID(a.RoleID.Value)).GetRandomElement(); if (character == null) { return(null); } path = ImageUtils.GetBaseAniDBCharacterImagesPath() + Path.DirectorySeparatorChar + character.ImagePath; if (System.IO.File.Exists(path)) { return(path); } else { path = string.Empty; logger.Trace("Could not find Character image: {0}", ImageUtils.GetBaseAniDBCharacterImagesPath() + Path.DirectorySeparatorChar + character.ImagePath); } break; case ImageEntityType.Staff: var staff = RepoFactory.AniDB_Anime.GetAll() .Where(a => a != null && !a.GetAllTags().Contains("18 restricted")) .SelectMany(a => RepoFactory.CrossRef_Anime_Staff.GetByAnimeID(a.AnimeID)) .Select(a => RepoFactory.AnimeStaff.GetByID(a.StaffID)).GetRandomElement(); if (staff == null) { return(null); } path = ImageUtils.GetBaseAniDBCreatorImagesPath() + Path.DirectorySeparatorChar + staff.ImagePath; if (System.IO.File.Exists(path)) { return(path); } else { path = string.Empty; logger.Trace("Could not find Staff image: {0}", ImageUtils.GetBaseAniDBCreatorImagesPath() + Path.DirectorySeparatorChar + staff.ImagePath); } break; default: path = string.Empty; break; } return(path); }
/// <summary> /// Internal function that return valid image file path on server that exist /// </summary> /// <param name="id">image id</param> /// <param name="type">image type</param> /// <param name="thumb">thumb mode</param> /// <returns>string</returns> internal string GetImagePath(int type, int id, bool thumb) { ImageEntityType imageType = (ImageEntityType)type; string path; switch (imageType) { // 1 case ImageEntityType.AniDB_Cover: SVR_AniDB_Anime anime = RepoFactory.AniDB_Anime.GetByAnimeID(id); if (anime == null) { return(null); } path = anime.PosterPath; if (System.IO.File.Exists(path)) { return(path); } else { path = string.Empty; logger.Trace("Could not find AniDB_Cover image: {0}", anime.PosterPath); } break; // 2 case ImageEntityType.AniDB_Character: AniDB_Character chr = RepoFactory.AniDB_Character.GetByCharID(id); if (chr == null) { return(null); } path = chr.GetPosterPath(); if (System.IO.File.Exists(path)) { return(path); } else { path = string.Empty; logger.Trace("Could not find AniDB_Character image: {0}", chr.GetPosterPath()); } break; // 3 case ImageEntityType.AniDB_Creator: AniDB_Seiyuu creator = RepoFactory.AniDB_Seiyuu.GetBySeiyuuID(id); if (creator == null) { return(null); } path = creator.GetPosterPath(); if (System.IO.File.Exists(path)) { return(path); } else { path = string.Empty; logger.Trace("Could not find AniDB_Creator image: {0}", creator.GetPosterPath()); } break; // 4 case ImageEntityType.TvDB_Banner: TvDB_ImageWideBanner wideBanner = RepoFactory.TvDB_ImageWideBanner.GetByID(id); if (wideBanner == null) { return(null); } path = wideBanner.GetFullImagePath(); if (System.IO.File.Exists(path)) { return(path); } else { path = string.Empty; logger.Trace("Could not find TvDB_Banner image: {0}", wideBanner.GetFullImagePath()); } break; // 5 case ImageEntityType.TvDB_Cover: TvDB_ImagePoster poster = RepoFactory.TvDB_ImagePoster.GetByID(id); if (poster == null) { return(null); } path = poster.GetFullImagePath(); if (System.IO.File.Exists(path)) { return(path); } else { path = string.Empty; logger.Trace("Could not find TvDB_Cover image: {0}", poster.GetFullImagePath()); } break; // 6 case ImageEntityType.TvDB_Episode: TvDB_Episode ep = RepoFactory.TvDB_Episode.GetByID(id); if (ep == null) { return(null); } path = ep.GetFullImagePath(); if (System.IO.File.Exists(path)) { return(path); } else { path = string.Empty; logger.Trace("Could not find TvDB_Episode image: {0}", ep.GetFullImagePath()); } break; // 7 case ImageEntityType.TvDB_FanArt: TvDB_ImageFanart fanart = RepoFactory.TvDB_ImageFanart.GetByID(id); if (fanart == null) { return(null); } if (thumb) { //ratio path = fanart.GetFullThumbnailPath(); if (System.IO.File.Exists(path)) { return(path); } path = string.Empty; logger.Trace("Could not find TvDB_FanArt image: {0}", fanart.GetFullThumbnailPath()); } else { path = fanart.GetFullImagePath(); if (System.IO.File.Exists(path)) { return(path); } path = string.Empty; logger.Trace("Could not find TvDB_FanArt image: {0}", fanart.GetFullImagePath()); } break; // 8 case ImageEntityType.MovieDB_FanArt: MovieDB_Fanart mFanart = RepoFactory.MovieDB_Fanart.GetByID(id); if (mFanart == null) { return(null); } mFanart = RepoFactory.MovieDB_Fanart.GetByOnlineID(mFanart.URL); if (mFanart == null) { return(null); } path = mFanart.GetFullImagePath(); if (System.IO.File.Exists(path)) { return(path); } else { path = string.Empty; logger.Trace("Could not find MovieDB_FanArt image: {0}", mFanart.GetFullImagePath()); } break; // 9 case ImageEntityType.MovieDB_Poster: MovieDB_Poster mPoster = RepoFactory.MovieDB_Poster.GetByID(id); if (mPoster == null) { return(null); } mPoster = RepoFactory.MovieDB_Poster.GetByOnlineID(mPoster.URL); if (mPoster == null) { return(null); } path = mPoster.GetFullImagePath(); if (System.IO.File.Exists(path)) { return(path); } else { path = string.Empty; logger.Trace("Could not find MovieDB_Poster image: {0}", mPoster.GetFullImagePath()); } break; case ImageEntityType.Character: AnimeCharacter character = RepoFactory.AnimeCharacter.GetByID(id); if (character == null) { return(null); } path = ImageUtils.GetBaseAniDBCharacterImagesPath() + Path.DirectorySeparatorChar + character.ImagePath; if (System.IO.File.Exists(path)) { return(path); } else { path = string.Empty; logger.Trace("Could not find Character image: {0}", ImageUtils.GetBaseAniDBCharacterImagesPath() + Path.DirectorySeparatorChar + character.ImagePath); } break; case ImageEntityType.Staff: var staff = RepoFactory.AnimeStaff.GetByID(id); if (staff == null) { return(null); } path = ImageUtils.GetBaseAniDBCreatorImagesPath() + Path.DirectorySeparatorChar + staff.ImagePath; if (System.IO.File.Exists(path)) { return(path); } else { path = string.Empty; logger.Trace("Could not find Staff image: {0}", ImageUtils.GetBaseAniDBCreatorImagesPath() + Path.DirectorySeparatorChar + staff.ImagePath); } break; default: path = string.Empty; break; } return(path); }
public void SetTvDBInfo(TvDBSummary tvSummary) { EpisodeOverview = Translation.EpisodeOverviewNA; EpisodeImageLocation = ""; #region episode override // check if this episode has a direct tvdb over-ride if (tvSummary.DictTvDBCrossRefEpisodes.ContainsKey(AniDB_EpisodeID)) { foreach (TvDB_Episode tvep in tvSummary.DictTvDBEpisodes.Values) { if (tvSummary.DictTvDBCrossRefEpisodes[AniDB_EpisodeID] == tvep.Id) { if (string.IsNullOrEmpty(tvep.Overview)) { EpisodeOverview = Translation.EpisodeOverviewNA; } else { EpisodeOverview = tvep.Overview; } if (string.IsNullOrEmpty(tvep.GetFullImagePath()) || !File.Exists(tvep.GetFullImagePath())) { EpisodeImageLocation = string.IsNullOrEmpty(tvep.GetOnlineImagePath()) ? @"/Images/EpisodeThumb_NotFound.png" : tvep.GetOnlineImagePath(); } else { EpisodeImageLocation = tvep.GetFullImagePath(); } if (VM_ShokoServer.Instance.EpisodeTitleSource == DataSourceType.TheTvDB && !string.IsNullOrEmpty(tvep.EpisodeName)) { _epname = tvep.EpisodeName; } return; } } } #endregion #region normal episodes // now do stuff to improve performance if (EpisodeTypeEnum == Shoko.Models.Enums.EpisodeType.Episode) { if (tvSummary.CrossRefTvDBV2 != null && tvSummary.CrossRefTvDBV2.Count > 0) { // find the xref that is right // relies on the xref's being sorted by season number and then episode number (desc) List <CrossRef_AniDB_TvDBV2> tvDBCrossRef = tvSummary.CrossRefTvDBV2.OrderByDescending(a => a.AniDBStartEpisodeNumber).ToList(); bool foundStartingPoint = false; CrossRef_AniDB_TvDBV2 xrefBase = null; foreach (CrossRef_AniDB_TvDBV2 xrefTV in tvDBCrossRef) { if (xrefTV.AniDBStartEpisodeType != (int)Shoko.Models.Enums.EpisodeType.Episode) { continue; } if (EpisodeNumber >= xrefTV.AniDBStartEpisodeNumber) { foundStartingPoint = true; xrefBase = xrefTV; break; } } // we have found the starting epiosde numbder from AniDB // now let's check that the TvDB Season and Episode Number exist if (foundStartingPoint) { Dictionary <int, int> dictTvDBSeasons = null; Dictionary <int, TvDB_Episode> dictTvDBEpisodes = null; foreach (TvDBDetails det in tvSummary.TvDetails.Values) { if (det.TvDBID == xrefBase.TvDBID) { dictTvDBSeasons = det.DictTvDBSeasons; dictTvDBEpisodes = det.DictTvDBEpisodes; break; } } if (dictTvDBEpisodes != null && dictTvDBSeasons != null) { if (dictTvDBSeasons.ContainsKey(xrefBase.TvDBSeasonNumber)) { int episodeNumber = dictTvDBSeasons[xrefBase.TvDBSeasonNumber] + (EpisodeNumber + xrefBase.TvDBStartEpisodeNumber - 2) - (xrefBase.AniDBStartEpisodeNumber - 1); if (dictTvDBEpisodes.ContainsKey(episodeNumber)) { TvDB_Episode tvep = dictTvDBEpisodes[episodeNumber]; if (string.IsNullOrEmpty(tvep.Overview)) { EpisodeOverview = "Episode Overview Not Available"; } else { EpisodeOverview = tvep.Overview; } if (string.IsNullOrEmpty(tvep.GetFullImagePath()) || !File.Exists(tvep.GetFullImagePath())) { if (string.IsNullOrEmpty(tvep.GetOnlineImagePath())) { EpisodeImageLocation = @"/Images/EpisodeThumb_NotFound.png"; } else { EpisodeImageLocation = tvep.GetOnlineImagePath(); } } else { EpisodeImageLocation = tvep.GetFullImagePath(); } if (VM_ShokoServer.Instance.EpisodeTitleSource == DataSourceType.TheTvDB && !string.IsNullOrEmpty(tvep.EpisodeName)) { _epname = tvep.EpisodeName; } } } } } } } #endregion #region special episodes if ((EpisodeTypeEnum == Shoko.Models.Enums.EpisodeType.Special) && tvSummary.CrossRefTvDBV2 != null) { // find the xref that is right // relies on the xref's being sorted by season number and then episode number (desc) List <CrossRef_AniDB_TvDBV2> tvDBCrossRef = tvSummary.CrossRefTvDBV2.OrderByDescending(a => a.AniDBStartEpisodeNumber).ToList(); bool foundStartingPoint = false; CrossRef_AniDB_TvDBV2 xrefBase = null; foreach (CrossRef_AniDB_TvDBV2 xrefTV in tvDBCrossRef) { if (xrefTV.AniDBStartEpisodeType != (int)Shoko.Models.Enums.EpisodeType.Special) { continue; } if (EpisodeNumber >= xrefTV.AniDBStartEpisodeNumber) { foundStartingPoint = true; xrefBase = xrefTV; break; } } if (tvSummary.CrossRefTvDBV2 != null && tvSummary.CrossRefTvDBV2.Count > 0) { if (foundStartingPoint) { Dictionary <int, int> dictTvDBSeasons = null; Dictionary <int, TvDB_Episode> dictTvDBEpisodes = null; foreach (TvDBDetails det in tvSummary.TvDetails.Values) { if (det.TvDBID == xrefBase.TvDBID) { dictTvDBSeasons = det.DictTvDBSeasons; dictTvDBEpisodes = det.DictTvDBEpisodes; break; } } if (dictTvDBEpisodes != null && dictTvDBSeasons != null) { if (dictTvDBSeasons.ContainsKey(xrefBase.TvDBSeasonNumber)) { int episodeNumber = dictTvDBSeasons[xrefBase.TvDBSeasonNumber] + (EpisodeNumber + xrefBase.TvDBStartEpisodeNumber - 2) - (xrefBase.AniDBStartEpisodeNumber - 1); if (dictTvDBEpisodes.ContainsKey(episodeNumber)) { TvDB_Episode tvep = dictTvDBEpisodes[episodeNumber]; EpisodeOverview = tvep.Overview; if (string.IsNullOrEmpty(tvep.GetFullImagePath()) || !File.Exists(tvep.GetFullImagePath())) { if (string.IsNullOrEmpty(tvep.GetOnlineImagePath())) { EpisodeImageLocation = @"/Images/EpisodeThumb_NotFound.png"; } else { EpisodeImageLocation = tvep.GetOnlineImagePath(); } } else { EpisodeImageLocation = tvep.GetFullImagePath(); } if (VM_ShokoServer.Instance.EpisodeTitleSource == DataSourceType.TheTvDB && !string.IsNullOrEmpty(tvep.EpisodeName)) { _epname = tvep.EpisodeName; } } } } } } } #endregion }