Skip to content

Commit

Permalink
Fix BingProvider image URI regex pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
goodtrailer committed May 10, 2021
1 parent 9d302be commit bed8f45
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions DailyDesktop.Core.Providers.Bing/BingProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ namespace DailyDesktop.Core.Providers.Bing
{
public class BingProvider : IProvider
{
private const string RESOLUTION_PATTERN = "(?<=(_))([0-9x]*)(?=(\\.))";
private const string RESOLUTION_REPLACEMENT = "1920x1080";
private const string IMAGE_URI_PATTERN = "(?<=(<a href=\"))(/th\\?id=)(.*?)(?=(&))";
private const string IMAGE_RELATIVE_URI_PATTERN = "(/th\\?id=)([^\"/>]*?)1920x1080.[a-z]*";
private const string AUTHOR_PATTERN = "(?<=(<div class=\"copyright\" id=\"copyright\">))(.*?)(?=(</div>))";
private const string TITLE_PATTERN = "(?<=(<div class=\"vs_bs_title\">))(.*?)(?=(</div>))";
private const string TITLE_URI_PATTERN = "(?<=(<a href=\"/))search(.*?)(?=(\"(.*?)class=\"learn_more\">))";
Expand All @@ -28,11 +26,10 @@ public WallpaperInfo GetWallpaperInfo()
{
pageHtml = client.DownloadString(SourceUri);
}
Match imageRelativeUriMatch = Regex.Match(pageHtml, IMAGE_URI_PATTERN);
Match imageRelativeUriMatch = Regex.Match(pageHtml, IMAGE_RELATIVE_URI_PATTERN);
string imageRelativeUri = imageRelativeUriMatch.Value;
if (string.IsNullOrWhiteSpace(imageRelativeUri))
throw new ProviderException("Didn't find a relative image URI.");
imageRelativeUri = Regex.Replace(imageRelativeUri, RESOLUTION_PATTERN, RESOLUTION_REPLACEMENT);
string imageUri = SourceUri + imageRelativeUri;

Match authorMatch = Regex.Match(pageHtml, AUTHOR_PATTERN);
Expand Down

0 comments on commit bed8f45

Please sign in to comment.