FaviconFetcher 1.0.1
Tools to scan a webpage for possible favicons (Scanner) and download the perfect one (Fetcher). Resources are prioritized and downloaded on demand, and caching is supported.
Install-Package FaviconFetcher -Version 1.0.1
dotnet add package FaviconFetcher --version 1.0.1
<PackageReference Include="FaviconFetcher" Version="1.0.1" />
paket add FaviconFetcher --version 1.0.1
Favicon Fetcher
FaviconFetcher contains tools for scanning a webpage for possible favicons (Scanner) and downloading the perfect one (Fetcher).
This library is perfect for non-browsers that need to download a favicon for a webpage.
Features
Favicon fetcher was built to include all needed functionality with ease of use and efficiency in mind.
- Resources are prioritized and downloaded on demand.
- Cache shared with other applications (off by default).
- Supports manifest.json and browserconfig.xml, if linked from the HTML.
- Easy to use.
Installation
Method 1 (Easy)
- Use Nuget Package Manager to install "FaviconFetcher".
Method 2 (Hard)
- Download the source code.
- Compile it. If compiling as "Release", ignore the errors in the FaviconFetcher.Tests project.
- Copy the library file to where you want it.
- Add a reference to it from your own project.
How to Use
Common uses are listed below. The full documentation is at <https://github.com/ComputerGhost/FaviconFetcher/tree/master/doc>. In places where the code differs from the documentation, the documentation is correct.
Fetcher - Find the Best Match
The fetcher will scan a webpage for favicons and download the one that best matches the given constraints.
var fetcher = new Fetcher();
var image = fetcher.FetchClosest(uri, new Size(16, 16));
// Don't forget to dispose of the image when no longer needed.
Other methods include FetchExact
and Fetch
. See the documentation for the full list and how to use them.
Scanner - Get a List of Favicons
To get a list of possible favicons without downloading any, use the scanner.
var scanner = new Scanner();
foreach (var result in scanner.Scan(uri))
{
var expectedSize = result.ExpectedSize;
var absoluteUri = result.Location;
// do something with it.
}
Keep in mind that an icon may not exist, may be invalid, may be a different size than the one reported, or may be a duplicate. Unlike the fetcher, the scanner does not verify that its results are correct.
HttpSource - Caching
Caching is supported by both the fetcher and the scanner, but it is off by default. To enable caching, pass a configured HttpSource
to the constructor.
var source = new HttpSource() {
CachePolicy = new RequestCachePolicy(RequestCacheLevel.CacheIfAvailable)
};
var fetcher = new Fetcher(source);
var image = fetcher.FetchClosest(uri, new Size(16, 16));
// Don't forget to dispose of the image when no longer needed.
Bug Reports
Please use the Issues tab on our GitHub page to file bug reports. Or, you may contact me directly if you know my contact information.
Credits
External libraries:
- The fetcher uses ConcurrentPriorityQueue by dshulepov to prioritize scanned icons.
Favicon Fetcher
FaviconFetcher contains tools for scanning a webpage for possible favicons (Scanner) and downloading the perfect one (Fetcher).
This library is perfect for non-browsers that need to download a favicon for a webpage.
Features
Favicon fetcher was built to include all needed functionality with ease of use and efficiency in mind.
- Resources are prioritized and downloaded on demand.
- Cache shared with other applications (off by default).
- Supports manifest.json and browserconfig.xml, if linked from the HTML.
- Easy to use.
Installation
Method 1 (Easy)
- Use Nuget Package Manager to install "FaviconFetcher".
Method 2 (Hard)
- Download the source code.
- Compile it. If compiling as "Release", ignore the errors in the FaviconFetcher.Tests project.
- Copy the library file to where you want it.
- Add a reference to it from your own project.
How to Use
Common uses are listed below. The full documentation is at <https://github.com/ComputerGhost/FaviconFetcher/tree/master/doc>. In places where the code differs from the documentation, the documentation is correct.
Fetcher - Find the Best Match
The fetcher will scan a webpage for favicons and download the one that best matches the given constraints.
var fetcher = new Fetcher();
var image = fetcher.FetchClosest(uri, new Size(16, 16));
// Don't forget to dispose of the image when no longer needed.
Other methods include FetchExact
and Fetch
. See the documentation for the full list and how to use them.
Scanner - Get a List of Favicons
To get a list of possible favicons without downloading any, use the scanner.
var scanner = new Scanner();
foreach (var result in scanner.Scan(uri))
{
var expectedSize = result.ExpectedSize;
var absoluteUri = result.Location;
// do something with it.
}
Keep in mind that an icon may not exist, may be invalid, may be a different size than the one reported, or may be a duplicate. Unlike the fetcher, the scanner does not verify that its results are correct.
HttpSource - Caching
Caching is supported by both the fetcher and the scanner, but it is off by default. To enable caching, pass a configured HttpSource
to the constructor.
var source = new HttpSource() {
CachePolicy = new RequestCachePolicy(RequestCacheLevel.CacheIfAvailable)
};
var fetcher = new Fetcher(source);
var image = fetcher.FetchClosest(uri, new Size(16, 16));
// Don't forget to dispose of the image when no longer needed.
Bug Reports
Please use the Issues tab on our GitHub page to file bug reports. Or, you may contact me directly if you know my contact information.
Credits
External libraries:
- The fetcher uses ConcurrentPriorityQueue by dshulepov to prioritize scanned icons.
Release Notes
Invalid ico files no longer throw an exception and are instead skipped.
Dependencies
-
.NETStandard 2.0
- PriorityQueue (>= 0.1.0)
- System.Drawing.Common (>= 4.5.1)
Used By
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.