private static void processMovieImageResponses() { // process request response foreach (sdArtworkResponse response in movieImageResponses) { ++processedObjects; reportProgress(); movieStaple = null; // determine which program this belongs to MxfProgram mxfProgram = sdMxf.With[0].getProgram(response.ProgramID); // first choice is return from Schedules Direct if (response.Data != null) { mxfProgram.programImages = getMovieImages(response.Data); } // second choice is from TMDb if allowed and available if (mxfProgram.programImages.Count == 0 && config.TMDbCoverArt && tmdbAPI.isAlive) { mxfProgram.programImages = getMoviePosterId(mxfProgram.Title, mxfProgram.Year, mxfProgram.Language); } // regardless if image is found or not, store the final result in xml file // this avoids hitting the tmdb server every update for every movie missing cover art // do not include the staple image sdImage sdImage = (mxfProgram.programImages.Count > 0) ? mxfProgram.programImages[0] : new sdImage() { Uri = string.Empty }; newImageLibrary.Images.Add(new archiveImage() { Title = mxfProgram.Title, Url = sdImage.Uri, Zap2itId = mxfProgram.tmsId.Substring(0, 10), Height = sdImage.Height, Width = sdImage.Width }); // final choice is the staple return from Schedules Direct if ((mxfProgram.programImages.Count == 0) && (movieStaple != null)) { mxfProgram.programImages.Add(movieStaple); } // if an image is found, insert in the mxf file if (mxfProgram.programImages.Count > 0) { mxfProgram.GuideImage = sdMxf.With[0].getGuideImage(mxfProgram.programImages[0].Uri).Id; } } }
private static IList <sdImage> getMovieImages(IList <sdImage> sdImages) { List <sdImage> ret = new List <sdImage>(); var images = sdImages.Where(arg => !string.IsNullOrEmpty(arg.Category)) .Where(arg => !string.IsNullOrEmpty(arg.Aspect)).Where(arg => arg.Aspect.ToLower().Equals("2x3")) .Where(arg => !string.IsNullOrEmpty(arg.Size)).Where(arg => arg.Size.ToLower().Equals("md")) .Where(arg => !string.IsNullOrEmpty(arg.Uri)); if (images != null) { // get the aspect ratios available and fix the URI sdImage[] links = new sdImage[3]; foreach (sdImage image in images) { if (!image.Uri.ToLower().StartsWith("http")) { image.Uri = string.Format("{0}{1}image/{2}", sdAPI.jsonBaseUrl, sdAPI.jsonApi, image.Uri.ToLower()); } switch (image.Category.ToLower()) { case "box art": // DVD box art, for movies only if (links[0] == null) { links[0] = image; } break; case "vod art": // undocumented, but looks like box art for video on demand if (links[1] == null) { links[1] = image; } break; case "poster art": // theatrical movie poster, standard sizes if (links[2] == null) { links[2] = image; } break; case "staple": // the staple image is intended to cover programs which do not have a unique banner image if (movieStaple == null) { movieStaple = image; } break; default: break; } } foreach (sdImage link in links) { if (link != null) { ret.Add(link); break; } } } return(ret); }
private static IList <sdImage> getSeriesImages(IList <sdImage> sdImages) { List <sdImage> ret = new List <sdImage>(); var images = sdImages.Where(arg => !string.IsNullOrEmpty(arg.Category)) .Where(arg => !string.IsNullOrEmpty(arg.Aspect)) .Where(arg => !string.IsNullOrEmpty(arg.Size)).Where(arg => arg.Size.ToLower().Equals("md")) .Where(arg => !string.IsNullOrEmpty(arg.Uri)) .Where(arg => string.IsNullOrEmpty(arg.Tier) || arg.Tier.ToLower().Equals("series") || arg.Tier.ToLower().Equals("sport") || arg.Tier.ToLower().Equals("sport event")); if (images != null) { // get the aspect ratios available and fix the URI HashSet <string> aspects = new HashSet <string>(); foreach (sdImage image in images) { aspects.Add(image.Aspect); if (!image.Uri.ToLower().StartsWith("http")) { image.Uri = string.Format("{0}{1}image/{2}", sdAPI.jsonBaseUrl, sdAPI.jsonApi, image.Uri.ToLower()); } } // determine which image to return with each aspect foreach (string aspect in aspects) { var imgAspects = images.Where(arg => arg.Aspect.ToLower().Equals(aspect)); sdImage[] links = new sdImage[8]; foreach (sdImage image in imgAspects) { switch (image.Category.ToLower()) { case "banner": // source-provided image, usually shows cast ensemble with source-provided text if (links[0] == null) { links[0] = image; } break; case "banner-l1": // same as Banner if (links[1] == null) { links[1] = image; } break; case "banner-l2": // source-provided image with plain text if (links[2] == null) { links[2] = image; } break; case "banner-lo": // banner with Logo Only if (links[3] == null) { links[3] = image; } break; case "logo": // official logo for program, sports organization, sports conference, or TV station if (links[4] == null) { links[4] = image; } break; case "banner-l3": // stock photo image with plain text if (links[5] == null) { links[5] = image; } break; case "iconic": // representative series/season/episode image, no text if (links[6] == null) { links[6] = image; } break; case "staple": // the staple image is intended to cover programs which do not have a unique banner image if (links[7] == null) { links[7] = image; } break; default: break; } } foreach (sdImage link in links) { if (link != null) { ret.Add(link); break; } } } } return(ret); }