-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
81 lines (79 loc) · 3.19 KB
/
Program.cs
File metadata and controls
81 lines (79 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System;
using System.Net;
using System.Net.Http;
using System.IO;
namespace Imgur_Downloader
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter Keywords");
Console.WriteLine();
string read = Console.ReadLine();
Search(read);
}
public static void Search(string input)
{
int pics = 0;
int videos = 0;
int total = 0;
int gifs = 0;
Directory.CreateDirectory(input);
string keywords = "";
foreach (string word in input.Split(' '))
{
keywords += word + "+";
}
using (WebClient client = new WebClient())
{
string result = client.DownloadString("https://imgur.com/search?q=" + keywords);
foreach (string line in result.Split('\n'))
{
if (line.Contains("i.imgur.com/"))
{
total += 1;
string code = line.Replace("<img alt=\"\" src=\"//", "").Replace("\" />", "").Replace(" ", "");
string url = "https://" + code.Remove(code.LastIndexOf('b'), 1);
string file = code.Replace("i.imgur.com/", "");
string filename = file.Remove(file.LastIndexOf('.'));
string dir = input + "\\" + filename;
using (HttpClient http = new HttpClient())
{
string req = http.GetAsync(url, HttpCompletionOption.ResponseContentRead).Result.ToString();
if (req.Contains("Content-Type: image/jpeg"))
{
client.DownloadFile(url, dir + ".png");
pics += 1;
}
else if (req.Contains("Content-Type: image/gif"))
{
client.DownloadFile(url, dir + ".gif");
gifs += 1;
}
else if (req.Contains("Content-Type: video/"))
{
client.DownloadFile(url, dir + ".mp4");
videos += 1;
}
}
}
}
Console.WriteLine("");
Console.WriteLine("=================================");
Console.WriteLine("");
Console.WriteLine("Total Found : " + total);
Console.WriteLine("");
Console.WriteLine("Total Pics : " + pics);
Console.WriteLine("");
Console.WriteLine("Total Gifs : " + gifs);
Console.WriteLine("");
Console.WriteLine("Total Vids : " + videos);
Console.WriteLine("");
Console.WriteLine("=================================");
Console.WriteLine("");
Console.ReadLine();
}
}
}
}