@@ -204,6 +204,55 @@ public byte[] GetIcon(string url)
204204 // If there is no file available
205205 throw new FaviconDownloaderException ( FaviconDownloaderExceptionStatus . NotFound ) ;
206206 }
207+
208+ public byte [ ] GetIconCustomProvider ( string url )
209+ {
210+ // Get the hostname from the requested URL
211+ var hostname = GetValidHost ( url ) ;
212+
213+ // Custom provider settings
214+ var providerURL = YetAnotherFaviconDownloaderExt . Config . GetCustomDownloadProvider ( ) ;
215+ var iconSize = YetAnotherFaviconDownloaderExt . Config . GetMaximumIconSize ( ) . ToString ( ) ;
216+
217+ // Follows KeePass placeholders convention
218+ // https://keepass.info/help/base/placeholders.html
219+
220+ // Maybe in the future we can give full/proper support, well, not today, for now it's enough
221+ providerURL = Regex . Replace ( providerURL , "{URL:HOST}" , hostname , RegexOptions . IgnoreCase ) ;
222+ providerURL = Regex . Replace ( providerURL , "{YAFD:ICON_SIZE}" , iconSize , RegexOptions . IgnoreCase ) ;
223+
224+ Uri address = new Uri ( providerURL ) ;
225+
226+ Util . Log ( "CustomProvider: {0} => {1}" , url , providerURL ) ;
227+
228+ try
229+ {
230+ // Download file
231+ byte [ ] data = DownloadData ( address ) ;
232+
233+ // Check if the data is a valid image and then try to resize it
234+ if ( ResizeImage ( ref data ) )
235+ {
236+ return data ;
237+ }
238+ }
239+ catch ( WebException ex )
240+ {
241+ HttpWebResponse response = ex . Response as HttpWebResponse ;
242+ if ( response != null && response . StatusCode == HttpStatusCode . NotFound )
243+ {
244+ throw new FaviconDownloaderException ( FaviconDownloaderExceptionStatus . NotFound ) ;
245+ }
246+ else
247+ {
248+ throw new FaviconDownloaderException ( ex ) ;
249+ }
250+ }
251+
252+ // If there is no file available
253+ throw new FaviconDownloaderException ( FaviconDownloaderExceptionStatus . NotFound ) ;
254+ }
255+
207256 public string GetValidHost ( string url )
208257 {
209258 if ( ! httpSchema . IsMatch ( url ) )
0 commit comments