/// <summary> /// Populate the asset list based on tier used later for sorting and returning /// configs based on program type and tier /// </summary> private void UpdateAssetList(string configTier) { if (AssetTier == null) { AssetTier = ApiAssetSortedList.Where(t => t.tier == configTier) .Select(t => t.tier) .Distinct() .ToList(); } //for movies ensure value is "" as the api has no tier but a empty string if (!AssetTier.Any()) { AssetTier.Add(""); } }
public string GetGracenoteImage(string imageTypeRequired, bool isTrackerService = false) { try { if (!isTrackerService) { _log.Info($"Processing Image: {imageTypeRequired}"); } if (ApiAssetList != null) { DownloadImageRequired = true; SortAssets(); int logged; //iterate the db config for images foreach (var category in ConfigImageCategories) { logged = 0; //Iterate each image category based on asset tier foreach (var imageTier in category.ImageTier) { // Populate asset list based on Tier UpdateAssetList(imageTier); UpdateCategoryList(ConfigImageCategories); //iterate each image inside the sorted api asset list foreach (var image in ApiAssetSortedList.Where(i => !i.expiredDateSpecified)) { ImageAspect(image.width, image.height); //validate the image category is a match with the config //and that the image is not flagged as expired on the api if (image.category != category.CategoryName) { continue; } //Check if the images contain identifiers if (image.identifiers.Any()) { logged = 1; //Check the identifiers match the config. if (!MatchIdentifier(image.identifiers, image.assetId, isTrackerService)) { continue; } } else if (logged == 0) { if (!isTrackerService) { _log.Debug($"No Identifier config found for current image Type -" + $" {imageTypeRequired}"); } logged++; } //Validate the current image can be used for ingest. if (!PassesImageLogic(category, image, imageTier, image.tier, IsLandscape)) { continue; } //LogIdentifierLogic(image.identifiers.Count(), image.assetId); if (!isTrackerService) { _log.Info($"Image {image.assetId} for {imageTypeRequired} passed Image logic"); } //check if the image is flagged as a requires trimming in config var requiresTrim = Convert.ToBoolean(category.AllowedAspects.Aspect .Select(r => r.TrimImage).FirstOrDefault()); //if requires trimming then append the trim=true to the image uri var imageUri = requiresTrim ? $"{image.URI}?trim=true" : image.URI; //gets any existing images var gnimages = CurrentMappingData.GN_Images; //IMGA, IMGB etc ImageQualifier = ImageMapping.ImageQualifier; //Is new ingest or update? if (!IsUpdate || gnimages == null) { if (!isTrackerService) { _log.Info($"Updating Database with Image {imageTypeRequired}: {image.URI}"); } SetDbImages(imageTypeRequired, image.URI); if (!isTrackerService) { _log.Info( $"Image URI: {image.URI} for: {imageTypeRequired} and Image Priority: {category.PriorityOrder}"); } return(imageUri); } if (!isTrackerService) { _log.Debug("Retrieved images for update package from db"); } //if this is an update get the db images and validate if the image matches //or has been updated, if there is no match download else return false as the image matches if (!HasAsset(DbImagesForAsset, imageTypeRequired, image.URI)) { var imageExtension = Path.GetExtension(image.URI); Match match = Regex.Match(CurrentMappingData.GN_Images, $"(?m){imageTypeRequired}:.*?{imageExtension}"); //if "" then the image doesnt exist in the db so grab it. if (match.Success || match.Value == "") { //New image required so update the db and set the uri ready for download. string newUri = $"{imageTypeRequired}: {image.URI}"; if (!isTrackerService) { _log.Debug($"Update package detected a new image, updating db for {imageTypeRequired} with {image.URI}"); } //Added this check in to ensure images are updated if missing or changed. CurrentMappingData.GN_Images = match.Value == "" ? (CurrentMappingData.GN_Images != string.Empty ? CurrentMappingData.GN_Images = $"{CurrentMappingData.GN_Images}, {imageTypeRequired}: {image.URI}" : CurrentMappingData.GN_Images = $"{imageTypeRequired}: {image.URI}") : CurrentMappingData.GN_Images = CurrentMappingData.GN_Images.Replace(match.Value, newUri); //update DbImages list, this will be saved by calling class. DbImages = CurrentMappingData.GN_Images; if (!isTrackerService) { _log.Info($"Image URI: {image.URI} for: {imageTypeRequired} and Image Priority: {category.PriorityOrder}"); } } } else { if (!isTrackerService) { _log.Info("Update Package - image is up to date not required for download."); } DownloadImageRequired = false; } return(imageUri); } } } } } catch (Exception ggiEx) { _log.Error($"[GetGracenoteImage] Error Getting Gracenote Image: {ggiEx.Message}"); if (ggiEx.InnerException != null) { _log.Error($"[GetGracenoteImage] Inner Exception: {ggiEx.InnerException.Message}"); } return(null); } if (!isTrackerService) { _log.Warn($"No Matching images found for: {imageTypeRequired}"); } return(null); }