Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using RedditSharp;
- using System.Net;
- using RedditSharp.Things;
- namespace reSharp
- {
- class Program
- {
- public static void Main()
- {
- string sub = "/r/";
- string saveDir = @"SAVE_DIRECTORY";
- Console.WriteLine("Subreddit:");
- sub += Console.ReadLine();
- Console.WriteLine("Amount:");
- int amount = Convert.ToInt32(Console.ReadLine());
- amount += 1;
- Console.WriteLine("Time Period");
- string timePer = Console.ReadLine();
- Reddit reddit = new Reddit();
- var subreddit = reddit.GetSubreddit(sub);
- if (timePer == "all")
- {
- foreach (var post in subreddit.GetTop(FromTime.All).Take(amount))
- {
- if (post.IsStickied || post.IsSelfPost || Convert.ToString(post.Url).Contains("reddituploads")) continue;
- string postURL = Convert.ToString(post.Url);
- DownloadImages(postURL, saveDir);
- }
- }
- else
- {
- if (timePer == "hot")
- {
- foreach (var post in subreddit.Hot.Take(amount))
- {
- if (post.IsStickied || post.IsSelfPost || Convert.ToString(post.Url).Contains("reddituploads")) continue;
- string postURL = Convert.ToString(post.Url);
- DownloadImages(postURL, saveDir);
- }
- }
- }
- }
- public static void DownloadImages(string imageURL, string userDir)
- {
- if (imageURL.Contains("gfycat.com"))
- {
- imageURL = imageURL.Replace("gfycat.com", "zippy.gfycat.com") + ".mp4";
- }
- if (imageURL.Contains(".gifv"))
- {
- imageURL = imageURL.Replace(".gifv", ".mp4");
- }
- Console.WriteLine("Downloading {0}", imageURL);
- string[] splitURL = imageURL.Split('/');
- int index = splitURL.Length - 1;
- string fileName = splitURL[index];
- WebClient client = new WebClient();
- try
- {
- client.DownloadFile(imageURL, userDir + fileName);
- }
- catch (Exception)
- {
- Console.WriteLine("[INFO] ERROR DOWNLOADING FILE");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement