Skip to content

Instantly share code, notes, and snippets.

@aveao
Created September 9, 2015 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aveao/f8506a385bf7f59ab7a9 to your computer and use it in GitHub Desktop.
Save aveao/f8506a385bf7f59ab7a9 to your computer and use it in GitHub Desktop.
Social Media Downloader C# (dirty code, hobby project)
public static void gfycat(string link)
{
WebClient wc = new WebClient();
string fileName = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\rarepepes\" + (link.Replace(link.Substring(0, link.IndexOf(@".com/") + 5), "") + ".gif");
WriteLine("Downloading... " + link, 1);
if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\rarepepes\"))
{
WriteLine("Directory doesn't exist", 3);
Directory.CreateDirectory((Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\rarepepes\"));
WriteLine("Created", 1);
}
wc.DownloadFile((link.Replace(@"http://gfycat", @"http://fat.gfycat").Replace(@"https://gfycat", @"https://fat.gfycat").Replace(@"http://www.gfycat", @"http://fat.gfycat").Replace(@"https://www.gfycat", @"https://fat.gfycat") + @".gif"), fileName);
}
public static void imgur(string link)
{
WebClient wc = new WebClient();
if (link.StartsWith(@"http://i.imgur") || link.StartsWith(@"https://i.imgur"))
{
string fileName = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\rarepepes\" + (link.Replace(link.Substring(0, (link.IndexOf(".com/") + 5)), ""));
if (!File.Exists(fileName))
{
WriteLine("Downloading... " + link, 1);
if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\rarepepes\"))
{
WriteLine("Directory doesn't exist", 3);
Directory.CreateDirectory((Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\rarepepes\"));
WriteLine("Created", 1);
}
wc.DownloadFile(link, fileName);
}
}
else
{
WebClient wchtml = new WebClient();
string htmlString = wchtml.DownloadString(link);
int mastercount = 0;
foreach (string str in GetLinks(htmlString))
{
if (str.Contains(@"/i.imgur"))
{
string fileName = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\rarepepes\" + (str.Replace(str.Substring(0, (str.IndexOf(".com/") + 5)), ""));
if (!File.Exists(fileName))
{
try
{
WriteLine("Downloading... " + str, 1);
mastercount++;
if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\rarepepes\"))
{
WriteLine("Directory doesn't exist", 3);
Directory.CreateDirectory((Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\rarepepes\"));
WriteLine("Created", 1);
}
wc.DownloadFile(str, fileName);
Thread.Sleep(1000);
}
catch (Exception ex)
{
WriteLine(ex.Message + " | " + ex.HResult, 38808); //error in 1337
}
}
else
{
WriteLine("Already exists.", 2);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment