Created
September 9, 2015 21:12
-
-
Save aveao/f8506a385bf7f59ab7a9 to your computer and use it in GitHub Desktop.
Social Media Downloader C# (dirty code, hobby project)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static List<string> GetLinks(string message) | |
{ | |
List<string> list = new List<string>(); | |
Regex urlRx = new Regex(@"((https?|ftp|file)\://|www.)[A-Za-z0-9\.\-]+(/[A-Za-z0-9\?\&\=;\+!'\(\)\*\-\._~%]*)*", RegexOptions.IgnoreCase); | |
MatchCollection matches = urlRx.Matches(message); | |
foreach (Match match in matches) | |
{ | |
list.Add(match.Value); | |
} | |
return list; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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