private static FileInfoBase GetBannerCacheFile(TvdbBanner banner, Boolean thumbnail=false) { // Initalise empty filename.. String fileName = ""; // Add pre-fix based on if thumb or not. if(banner.GetType()==typeof(TvdbBannerWithThumb)) { fileName += "thumb_"; } else { fileName += "img_"; } // Handle different BannerPath conversion for different banner types. if(banner.GetType() == typeof(TvdbFanartBanner)) { fileName += "fan_" + fileSystem.FileInfo.FromFileName(banner.BannerPath).Name; } else { fileName += banner.BannerPath.Replace("/", "_"); } // Return file. var innerPath = fileSystem.Path.Combine(banner.SeriesId.ToString(), fileName); return fileSystem.FileInfo.FromFileName(fileSystem.Path.Combine(CacheDirectory.FullName, innerPath)); }
/// <summary> /// Set the new banner image /// </summary> /// <param name="_value"></param> private void SetBannerImage(TvdbBanner _value) { Thread imageLoader = new Thread(new ParameterizedThreadStart(DoBannerLoad)); m_latestLoadingThread = imageLoader; imageLoader.Priority = ThreadPriority.Lowest; imageLoader.Name = "Imageloader_" + _value.BannerPath; imageLoader.Start(_value); }
/// <summary> /// Update the series with the banner /// </summary> /// <param name="_series"></param> /// <param name="_banner"></param> /// <returns>true, if the banner was updated successfully, false otherwise</returns> private bool UpdateBanner(TvdbSeries _series, TvdbBanner _banner) { if (!_series.BannersLoaded) {//banners for this series havn't been loaded -> don't update banners return false; } foreach (TvdbBanner b in _series.Banners) { if (_banner.GetType() == b.GetType() && _banner.BannerPath.Equals(b.BannerPath)) {//banner was found if (b.LastUpdated < _banner.LastUpdated) {//update time of local banner is longer ago than update time of current update b.LastUpdated = _banner.LastUpdated; if (_banner.GetType() == typeof(TvdbFanartBanner)) {//update fanart specific content TvdbFanartBanner fanart = (TvdbFanartBanner)b; fanart.Resolution = ((TvdbFanartBanner)_banner).Resolution; if (fanart.IsThumbLoaded) { fanart.LoadThumb(null); } if (fanart.IsVignetteLoaded) { fanart.LoadVignette(null); } } if (b.IsLoaded) {//the banner was previously loaded and is updated -> discard the previous image b.LoadBanner(null); b.UnloadBanner(false); } Log.Info("Replacing banner " + _banner.Id); return true; } else { Log.Debug("Not replacing banner " + _banner.Id + " because it's not newer than current image"); return false; } } } //banner not found -> add it to bannerlist Log.Info("Adding banner " + _banner.Id); _series.Banners.Add(_banner); return true; }
private TvdbBanner GetLoadedBanner(TvdbDownloader downloader, int sId, int season, int episode, TvdbBanner fallback) { TvdbBanner result = GetEpisodeBanner(downloader, sId, season, episode); if (result != null && TryLoadBanner(result)) return result; var bannerHits = downloader.DownloadBanners(sId); result = GetSeasonBanner(bannerHits, season); if (result != null && TryLoadBanner(result)) return result; result = GetSeriesBanner(bannerHits); if (result != null && TryLoadBanner(result)) return result; if (fallback != null && TryLoadBanner(fallback)) return fallback; return null; }
private bool TryLoadBanner(TvdbBanner banner) { if (banner.IsLoaded) return true; try { banner.LoadBanner(); while (banner.BannerLoading) Thread.Sleep(10); return true; } catch (Exception ex) { return false; } }
private void FillBannerDetails(TvdbBanner _before, TvdbBanner _after, TvdbBanner _current) { lvSeriesDetails.Items.Clear(); //id lvSeriesDetails.Items.Add(CreateItem("Id", _before != null ? _before.Id.ToString() : "", _after != null ? _after.Id.ToString() : "", _current != null ? _current.Id.ToString() : "")); //BannerPath lvSeriesDetails.Items.Add(CreateItem("BannerPath", _before != null ? _before.BannerPath.ToString() : "", _after != null ? _after.BannerPath.ToString() : "", _current != null ? _current.BannerPath.ToString() : "")); //Type lvSeriesDetails.Items.Add(CreateItem("Type", _before != null ? _before.GetType().ToString() : "", _after != null ? _after.GetType().ToString() : "", _current != null ? _current.GetType().ToString() : "")); if ((_before != null && _after != null && _before.GetType() == _after.GetType()) || (_before != null && _current != null && _before.GetType() == _current.GetType()) || (_after != null && _current != null && _after.GetType() == _current.GetType()) || (_before != null && _current != null && _before.GetType() == _current.GetType()) || (_before != null && _after != null && _current != null && _before.GetType() == _current.GetType() && _before.GetType() == _after.GetType())) {//all banners have the same type if ((_before != null && _before.GetType() == typeof(TvdbSeriesBanner)) || (_after != null && _after.GetType() == typeof(TvdbSeriesBanner)) || (_current != null && _current.GetType() == typeof(TvdbSeriesBanner))) {//TvdbSeriesBanner } if ((_before != null && _before.GetType() == typeof(TvdbSeasonBanner)) || (_after != null && _after.GetType() == typeof(TvdbSeasonBanner)) || (_current != null && _current.GetType() == typeof(TvdbSeasonBanner))) {//TvdbSeasonBanner //Season lvSeriesDetails.Items.Add(CreateItem("Season", _before != null ? ((TvdbSeasonBanner)_before).Season.ToString() : "", _after != null ? ((TvdbSeasonBanner)_after).Season.ToString() : "", _current != null ? ((TvdbSeasonBanner)_current).Season.ToString() : "")); } if ((_before != null && _before.GetType() == typeof(TvdbFanartBanner)) || (_after != null && _after.GetType() == typeof(TvdbFanartBanner)) || (_current != null && _current.GetType() == typeof(TvdbFanartBanner))) {//TvdbFanartBanner //Color1 lvSeriesDetails.Items.Add(CreateItem("Color1", _before != null ? ((TvdbFanartBanner)_before).Color1.ToString() : "", _after != null ? ((TvdbFanartBanner)_after).Color1.ToString() : "", _current != null ? ((TvdbFanartBanner)_current).Color1.ToString() : "")); //Color2 lvSeriesDetails.Items.Add(CreateItem("Color2", _before != null ? ((TvdbFanartBanner)_before).Color2.ToString() : "", _after != null ? ((TvdbFanartBanner)_after).Color2.ToString() : "", _current != null ? ((TvdbFanartBanner)_current).Color2.ToString() : "")); //Color3 lvSeriesDetails.Items.Add(CreateItem("Color3", _before != null ? ((TvdbFanartBanner)_before).Color3.ToString() : "", _after != null ? ((TvdbFanartBanner)_after).Color3.ToString() : "", _current != null ? ((TvdbFanartBanner)_current).Color3.ToString() : "")); //Resolution lvSeriesDetails.Items.Add(CreateItem("Resolution", _before != null ? ((TvdbFanartBanner)_before).Resolution.ToString() : "", _after != null ? ((TvdbFanartBanner)_after).Resolution.ToString() : "", _current != null ? ((TvdbFanartBanner)_current).Resolution.ToString() : "")); //ContainsSeriesName lvSeriesDetails.Items.Add(CreateItem("Resolution", _before != null ? ((TvdbFanartBanner)_before).ContainsSeriesName.ToString() : "", _after != null ? ((TvdbFanartBanner)_after).ContainsSeriesName.ToString() : "", _current != null ? ((TvdbFanartBanner)_current).ContainsSeriesName.ToString() : "")); //VignettePath lvSeriesDetails.Items.Add(CreateItem("VignettePath", _before != null ? ((TvdbFanartBanner)_before).VignettePath.ToString() : "", _after != null ? ((TvdbFanartBanner)_after).VignettePath.ToString() : "", _current != null ? ((TvdbFanartBanner)_current).VignettePath.ToString() : "")); } if ((_before != null && _before.GetType() == typeof(TvdbPosterBanner)) || (_after != null && _after.GetType() == typeof(TvdbPosterBanner)) || (_current != null && _current.GetType() == typeof(TvdbPosterBanner))) {//TvdbPosterBanner //Resolution lvSeriesDetails.Items.Add(CreateItem("Resolution", _before != null ? ((TvdbPosterBanner)_before).Resolution.ToString() : "", _after != null ? ((TvdbPosterBanner)_after).Resolution.ToString() : "", _current != null ? ((TvdbPosterBanner)_current).Resolution.ToString() : "")); } } }
private ItemState CheckBannerChanged(TvdbBanner _before, TvdbBanner _after, TvdbBanner _current) { if (_current != null) { if (_after != null) {//episode has been updated (_before != null) or added (_before == null) if (BannerChanged(_after, _current)) { if (_before == null) { return ItemState.AddedAndInconsistent; } else { return ItemState.UpdatedAndInconsistent; } } else { if (_before == null) {//the item has been added correctly return ItemState.Added; } else {//the item has been updated correctly (after == current) if (BannerChanged(_before, _after)) { return ItemState.UpdatedAndValueChanged; } else { return ItemState.Updated; } } } } //episode is available but hasn't been added to our cache yet if (_before == null && _after == null) return ItemState.AvailableButNotDownloaded; //we have no update for this item if (_after == null) { if (BannerChanged(_before, _current)) { return ItemState.UnchangedAndInconsistent; } else { return ItemState.Unchanged; } } } if (_current == null) {//current version hasn't been loaded, we can't compare if the update was done correctly if (_before != null && _after != null) {//episode has been updated return ItemState.Updated; } else if (_before == null && _after != null) {//episode has been added return ItemState.Added; } else { return ItemState.Unchanged; } } return ItemState.Unchanged; }
private bool BannerChanged(TvdbBanner _banner1, TvdbBanner _banner2) { if (_banner1 == null && _banner2 == null) return false; if (_banner1 == null || _banner2 == null) return true; if (_banner1.GetType() != _banner2.GetType()) return true; bool bannerChanged = false; if (!_banner1.BannerPath.Equals(_banner2.BannerPath)) bannerChanged = true;//shouldn't happen //if (_banner1.LastUpdated != _banner2.LastUpdated) bannerChanged = true; if (_banner1.Id != _banner2.Id) bannerChanged = true; if (_banner1.GetType() == typeof(TvdbSeriesBanner)) { TvdbSeriesBanner banner1 = _banner1 as TvdbSeriesBanner; TvdbSeriesBanner banner2 = _banner2 as TvdbSeriesBanner; } if (_banner1.GetType() == typeof(TvdbSeasonBanner)) { TvdbSeasonBanner banner1 = _banner1 as TvdbSeasonBanner; TvdbSeasonBanner banner2 = _banner2 as TvdbSeasonBanner; if (banner1.Season != banner2.Season) bannerChanged = true; } if (_banner1.GetType() == typeof(TvdbFanartBanner)) { TvdbFanartBanner banner1 = _banner1 as TvdbFanartBanner; TvdbFanartBanner banner2 = _banner2 as TvdbFanartBanner; if (banner1.Color1 != banner2.Color1) bannerChanged = true; if (banner1.Color2 != banner2.Color2) bannerChanged = true; if (banner1.Color3 != banner2.Color3) bannerChanged = true; if (banner1.ContainsSeriesName != banner2.ContainsSeriesName) bannerChanged = true; if (banner1.Resolution != banner2.Resolution) bannerChanged = true; if (banner1.VignettePath != banner2.VignettePath) bannerChanged = true; } if (_banner1.GetType() == typeof(TvdbPosterBanner)) { TvdbPosterBanner banner1 = _banner1 as TvdbPosterBanner; TvdbPosterBanner banner2 = _banner2 as TvdbPosterBanner; if (banner1.Resolution != banner2.Resolution) bannerChanged = true; } return bannerChanged; }
public void SetImage(TvdbBanner _banner, int _position) { if (_position < m_imagePositions.Count) { m_imagePositions[_position].Image = _banner; } }
private string LoadBannerToPath(TvdbBanner banner) { if (banner == null || string.IsNullOrEmpty(banner.BannerPath)) return null; string imageLocalPath = Path.Combine(m_DataStore.GetImageDirectory(), banner.Id.ToString()); imageLocalPath = Path.ChangeExtension(imageLocalPath, "jpg"); if (!File.Exists(imageLocalPath)) { log.DebugFormat("Downloading banner \"{0}\" to \"{1}\"", banner.BannerUri.AbsoluteUri, imageLocalPath); using (var wc = new WebClient()) { try { wc.DownloadFile(banner.BannerUri, imageLocalPath); } catch (Exception ex) { log.Warn("Loading banner failed.", ex); return null; } log.DebugFormat("OK"); } } return imageLocalPath; }