/// <summary> /// Makes sure that the movie posters are downloaded locally. (This is so the URL referenced isn't used a TON.) /// Whether the file was downloaded or not, the ImageUrl is updated to the local file (provided it exists). /// /// </summary> /// <returns>A flag to update the image URL</returns> public bool DownloadMoviePosters(string localFilePrefix) { var imageUtil = new ImageUtility(); var miner = Miners[FML_INDEX]; var result = FileUtility.DownloadFiles(miner.Movies.Select(movie => movie.ImageUrlSource), localFilePrefix); var multiDayCount = miner.Movies.Where(item => item.Day.HasValue).Count(); foreach (var movie in miner.Movies) { var localFileName = FileUtility.LocalFile(movie.ImageUrlSource, localFilePrefix); if (File.Exists(localFileName)) { // If the file was actually downloaded then use the local file. if (result) { imageUtil.AdjustSize(localFileName, 200, 300); // Shrink image a bit. } if (movie.Day.HasValue) { var multiDay = (multiDayCount == 2) ? (movie.Day.Value == DayOfWeek.Friday ? "-Saturday" : "-Monday") : string.Empty; var maskedFileName = $"{Path.GetFileNameWithoutExtension(localFileName)}-{movie.Day.Value}{multiDay}.jpg"; if (!File.Exists(Path.Combine(Path.GetDirectoryName(localFileName), maskedFileName))) { imageUtil.MaskImage(localFileName, $"{movie.Day.Value}{multiDay}-mask.png", maskedFileName); } movie.ImageUrl = $"/Images/{maskedFileName}"; } else { movie.ImageUrl = $"/Images/{Path.GetFileName(localFileName)}"; } } else { movie.ImageUrl = movie.ImageUrlSource; } } result |= !_postersDownloaded; // Only download ONCE per instance. (Meaning only update the ImageUrl once per instance since there is a lock() used to do this.) _postersDownloaded = true; return(result); }