Skip to content

Commit

Permalink
v1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
d4n3436 committed Sep 21, 2021
1 parent 35b1e46 commit 1e88dde
Show file tree
Hide file tree
Showing 35 changed files with 2,216 additions and 302 deletions.
2 changes: 1 addition & 1 deletion examples/GScraperExample/GScraperExample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
64 changes: 40 additions & 24 deletions examples/GScraperExample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;
using GScraper;
using GScraper.Google;

namespace GScraperExample
{
Expand All @@ -12,11 +13,14 @@ internal static class Program
private static async Task Main()
{
Console.WriteLine("GScraper Example Program");
var scraper = new GoogleScraper();
using var scraper = new GoogleScraper();
// Other scrapers:
// using var scraper = new GScraper.DuckDuckGo.DuckDuckGoScraper();
// using var scraper = new GScraper.Brave.BraveScraper();

while (true)
{
Console.Write("Query (enter \'e\' to exit): ");
Console.Write("Query (enter 'e' to exit): ");
string text = Console.ReadLine();

if (string.IsNullOrEmpty(text))
Expand All @@ -25,40 +29,52 @@ private static async Task Main()
if (text == "e")
break;

Console.Write("Limit?: ");
if (!int.TryParse(Console.ReadLine(), NumberStyles.Integer, CultureInfo.InvariantCulture, out int limit))
continue;

IReadOnlyList<ImageResult> images;
IEnumerable<IImageResult> images;
try
{
images = await scraper.GetImagesAsync(text, limit).ConfigureAwait(false);
images = await scraper.GetImagesAsync(text);
}
catch (HttpRequestException e)
{
Console.WriteLine(e);
continue;
}
catch (GScraperException e)
catch (Exception e) when (e is HttpRequestException or GScraperException)
{
Console.WriteLine(e);
continue;
}

bool enumerateAll = false;
bool stop = false;
foreach (var image in images)
{
Console.WriteLine($"Title: {image.Title}");
Console.WriteLine($"Link: {image.Link}");
Console.WriteLine($"ThumbnailLink: {image.ThumbnailLink}");
Console.WriteLine($"ContextLink: {image.ContextLink}");
Console.WriteLine($"DisplayLink: {image.DisplayLink}");
Console.WriteLine($"Width: {image.Width}");
Console.WriteLine($"Height: {image.Height}");
Console.WriteLine();
Console.WriteLine(JsonSerializer.Serialize(image, image.GetType(), new JsonSerializerOptions { WriteIndented = true }));
Console.WriteLine();

if (!enumerateAll)
{
Console.Write("Press 'n' to send the next image, 'a' to enumerate all images and 's' to stop: ");
var key = Console.ReadKey().Key;
Console.WriteLine();

switch (key)
{
case ConsoleKey.A:
enumerateAll = true;
break;

case ConsoleKey.S:
stop = true;
break;

default:
break;
}
}

if (stop)
{
break;
}
}
}

scraper.Dispose();
}
}
}
187 changes: 187 additions & 0 deletions src/GScraper/Brave/BraveCountries.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
namespace GScraper.Brave
{
/// <summary>
/// Contains the possible countries in Brave search.
/// </summary>
public static class BraveCountries
{
/// <summary>
/// All regions.
/// </summary>
public const string All = "all";

/// <summary>
/// Argentina.
/// </summary>
public const string Argentina = "ar";

/// <summary>
/// Australia.
/// </summary>
public const string Australia = "au";

/// <summary>
/// Belgium.
/// </summary>
public const string Belgium = "be";

/// <summary>
/// Brazil.
/// </summary>
public const string Brazil = "br";

/// <summary>
/// Canada.
/// </summary>
public const string Canada = "ca";

/// <summary>
/// Chile.
/// </summary>
public const string Chile = "cl";

/// <summary>
/// Denmark.
/// </summary>
public const string Denmark = "dk";

/// <summary>
/// Finland.
/// </summary>
public const string Finland = "fi";

/// <summary>
/// France.
/// </summary>
public const string France = "fr";
/// <summary>
/// Germany.
/// </summary>
public const string Germany = "de";

/// <summary>
/// Hong Kong.
/// </summary>
public const string HongKong = "hk";

/// <summary>
/// India.
/// </summary>
public const string India = "in";

/// <summary>
/// Indonesia.
/// </summary>
public const string Indonesia = "id";

/// <summary>
/// Italy.
/// </summary>
public const string Italy = "it";

/// <summary>
/// Japan.
/// </summary>
public const string Japan = "jp";

/// <summary>
/// Korea.
/// </summary>
public const string Korea = "kr";

/// <summary>
/// Malaysia.
/// </summary>
public const string Malaysia = "my";

/// <summary>
/// Mexico.
/// </summary>
public const string Mexico = "mx";

/// <summary>
/// Netherlands.
/// </summary>
public const string Netherlands = "nl";

/// <summary>
/// New Zealand.
/// </summary>
public const string NewZealand = "nz";

/// <summary>
/// Norway.
/// </summary>
public const string Norway = "no";

/// <summary>
/// China.
/// </summary>
public const string China = "cn";

/// <summary>
/// Poland.
/// </summary>
public const string Poland = "pl";

/// <summary>
/// Portugal.
/// </summary>
public const string Portugal = "pl";

/// <summary>
/// Philippines.
/// </summary>
public const string Philippines = "ph";

/// <summary>
/// Russia.
/// </summary>
public const string Russia = "ru";

/// <summary>
/// Saudi Arabia.
/// </summary>
public const string SaudiArabia = "sa";

/// <summary>
/// South Africa.
/// </summary>
public const string SouthAfrica = "za";

/// <summary>
/// Spain.
/// </summary>
public const string Spain = "es";

/// <summary>
/// Sweden.
/// </summary>
public const string Sweden = "se";

/// <summary>
/// Switzerland.
/// </summary>
public const string Switzerland = "ch";

/// <summary>
/// Taiwan.
/// </summary>
public const string Taiwan = "tw";

/// <summary>
/// Turkey.
/// </summary>
public const string Turkey = "tr";

/// <summary>
/// United Kingdom.
/// </summary>
public const string UnitedKingdom = "gb";

/// <summary>
/// United States.
/// </summary>
public const string UnitedStates = "us";
}
}
69 changes: 69 additions & 0 deletions src/GScraper/Brave/BraveImageColor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
namespace GScraper.Brave
{
/// <summary>
/// Specifies the image colors in Brave search.
/// </summary>
public enum BraveImageColor
{
/// <summary>
/// All colors.
/// </summary>
All,
/// <summary>
/// Black and white.
/// </summary>
Monochrome,
/// <summary>
/// Only colors.
/// </summary>
ColorOnly,
/// <summary>
/// Red color.
/// </summary>
Red,
/// <summary>
/// Orange color.
/// </summary>
Orange,
/// <summary>
/// Yellow color.
/// </summary>
Yellow,
/// <summary>
/// Green color.
/// </summary>
Green,
/// <summary>
/// Blue color.
/// </summary>
Blue,
/// <summary>
/// Purple color.
/// </summary>
Purple,
/// <summary>
/// Pink color.
/// </summary>
Pink,
/// <summary>
/// Brown color.
/// </summary>
Brown,
/// <summary>
/// Black color.
/// </summary>
Black,
/// <summary>
/// Gray color.
/// </summary>
Gray,
/// <summary>
/// Teal color.
/// </summary>
Teal,
/// <summary>
/// White color.
/// </summary>
White
}
}
25 changes: 25 additions & 0 deletions src/GScraper/Brave/BraveImageLayout.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace GScraper.Brave
{
/// <summary>
/// Specifies the image layouts in Brave search.
/// </summary>
public enum BraveImageLayout
{
/// <summary>
/// All layouts
/// </summary>
All,
/// <summary>
/// Square layout.
/// </summary>
Square,
/// <summary>
/// Tall layout.
/// </summary>
Tall,
/// <summary>
/// Wide layout.
/// </summary>
Wide
}
}
Loading

0 comments on commit 1e88dde

Please sign in to comment.