Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using RedditSharp;
  4. using System.Net;
  5. using RedditSharp.Things;
  6.  
  7. namespace reSharp
  8. {
  9. class Program
  10. {
  11. public static void Main()
  12. {
  13. string sub = "/r/";
  14. string saveDir = @"SAVE_DIRECTORY";
  15. Console.WriteLine("Subreddit:");
  16. sub += Console.ReadLine();
  17.  
  18. Console.WriteLine("Amount:");
  19. int amount = Convert.ToInt32(Console.ReadLine());
  20. amount += 1;
  21.  
  22. Console.WriteLine("Time Period");
  23. string timePer = Console.ReadLine();
  24.  
  25. Reddit reddit = new Reddit();
  26. var subreddit = reddit.GetSubreddit(sub);
  27. if (timePer == "all")
  28. {
  29. foreach (var post in subreddit.GetTop(FromTime.All).Take(amount))
  30. {
  31. if (post.IsStickied || post.IsSelfPost || Convert.ToString(post.Url).Contains("reddituploads")) continue;
  32. string postURL = Convert.ToString(post.Url);
  33. DownloadImages(postURL, saveDir);
  34.  
  35. }
  36. }
  37. else
  38. {
  39. if (timePer == "hot")
  40. {
  41. foreach (var post in subreddit.Hot.Take(amount))
  42. {
  43. if (post.IsStickied || post.IsSelfPost || Convert.ToString(post.Url).Contains("reddituploads")) continue;
  44. string postURL = Convert.ToString(post.Url);
  45. DownloadImages(postURL, saveDir);
  46.  
  47. }
  48. }
  49. }
  50.  
  51. }
  52.  
  53. public static void DownloadImages(string imageURL, string userDir)
  54. {
  55.  
  56. if (imageURL.Contains("gfycat.com"))
  57. {
  58. imageURL = imageURL.Replace("gfycat.com", "zippy.gfycat.com") + ".mp4";
  59. }
  60.  
  61. if (imageURL.Contains(".gifv"))
  62. {
  63. imageURL = imageURL.Replace(".gifv", ".mp4");
  64. }
  65.  
  66. Console.WriteLine("Downloading {0}", imageURL);
  67. string[] splitURL = imageURL.Split('/');
  68. int index = splitURL.Length - 1;
  69. string fileName = splitURL[index];
  70. WebClient client = new WebClient();
  71. try
  72. {
  73. client.DownloadFile(imageURL, userDir + fileName);
  74. }
  75. catch (Exception)
  76. {
  77. Console.WriteLine("[INFO] ERROR DOWNLOADING FILE");
  78. }
  79. }
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement