WikiCrawler/Batch/UWash/UWashUploader.cs
/// <summary>
/// Run any additional logic after a successful upload (such as uploading a crop).
/// </summary>
Run any additional logic after a successful upload (such as uploading a crop).
Run any additional logic after a successful upload ( such as uploading a crop ) .
protected override void PostUpload(string key, Dictionary<string, string> metadata, Article article)
		{
			base.PostUpload(key, metadata, article);
			bool allowGeneralCrop = UWashConfig.allowCrop;
			bool allowWatermarkCrop = true;
			if (UWashConfig.filenameSuffix == "MOHAI"
				&& metadata.TryGetValue("Object Type", out string tempValue)
				&& tempValue.Contains("ephemera"))
			{
				allowGeneralCrop = false;
				allowWatermarkCrop = false;
			}
			string imagePath = GetImageCacheFilename(key, metadata);
			string cropPath = GetImageCroppedFilename(key, metadata);
			bool watermarkCrop = false;
			bool otherCrop = false;
			if (allowWatermarkCrop)
			{
				watermarkCrop = ImageUtils.CropUwashWatermark(imagePath, cropPath);
			}
			if (allowGeneralCrop)
			{
				otherCrop = ImageUtils.AutoCropJpg(cropPath, cropPath, 0xffffffff, 0.95f, 16, new CropParams(ImageUtils.Side.Left | ImageUtils.Side.Right, true));
				System.Threading.Thread.Sleep(50);
				if (!File.Exists(cropPath))
				{
					throw new UWashException("crop failed");
				}
			}
			if (watermarkCrop || otherCrop)
			{
				try
				{
					string crops = "";
					if (watermarkCrop)
					{
						crops = StringUtility.Join(", ", crops, "watermark");
					}
					if (otherCrop)
					{
						crops = StringUtility.Join(", ", crops, "horizontal");
					}
					string comment = "Automatic lossless crop (" + crops + ")";
					Article overwriteArticle = new Article(article.title);
					try
					{
						if (!Api.UploadFromLocal(overwriteArticle, cropPath, comment, true))
						{
							throw new UWashException("Crop upload failed");
						}
					}
					catch (DuplicateFileException e)
					{
						if (e.Duplicates.Length == 1 && e.IsSelfDuplicate)
						{
						}
						else if (m_config.succeedManualDupes)
						{
						}
						else
						{
							throw new UWashException(e.Message);
						}
					}
				}
				catch (WikimediaException e)
				{
					throw new UWashException(e.Message);
				}
			}
		}
protected override void PostUpload ( string key , Dictionary < string , string > metadata , Article article ) { base . PostUpload ( key , metadata , article ) ; bool allowGeneralCrop = UWashConfig . allowCrop ; bool allowWatermarkCrop = true ; if ( UWashConfig . filenameSuffix == " " && metadata . TryGetValue ( " " , out string tempValue ) && tempValue . Contains ( " " ) ) { allowGeneralCrop = false ; allowWatermarkCrop = false ; } string imagePath = GetImageCacheFilename ( key , metadata ) ; string cropPath = GetImageCroppedFilename ( key , metadata ) ; bool watermarkCrop = false ; bool otherCrop = false ; if ( allowWatermarkCrop ) { watermarkCrop = ImageUtils . CropUwashWatermark ( imagePath , cropPath ) ; } if ( allowGeneralCrop ) { otherCrop = ImageUtils . AutoCropJpg ( cropPath , cropPath , 0xffffffff , 0.95f , 16 , new CropParams ( ImageUtils . Side . Left | ImageUtils . Side . Right , true ) ) ; System . Threading . Thread . Sleep ( 50 ) ; if ( ! File . Exists ( cropPath ) ) { throw new UWashException ( " " ) ; } } if ( watermarkCrop || otherCrop ) { try { string crops = " " ; if ( watermarkCrop ) { crops = StringUtility . Join ( " " , crops , " " ) ; } if ( otherCrop ) { crops = StringUtility . Join ( " " , crops , " " ) ; } string comment = " " + crops + " " ; Article overwriteArticle = new Article ( article . title ) ; try { if ( ! Api . UploadFromLocal ( overwriteArticle , cropPath , comment , true ) ) { throw new UWashException ( " " ) ; } } catch ( DuplicateFileException e ) { if ( e . Duplicates . Length == 1 && e . IsSelfDuplicate ) { } else if ( m_config . succeedManualDupes ) { } else { throw new UWashException ( e . Message ) ; } } } catch ( WikimediaException e ) { throw new UWashException ( e . Message ) ; } } }
Run any additional logic after a successful upload (such as uploading a crop).
Run any additional logic after a successful upload ( such as uploading a crop ) .
// try to crop the image // overwrite with the crop // It looks like we already did this one, and that's fine
key
string
metadata
Dictionary<string, string>
article
Article