예제 #1
0
        /// <summary>
        /// <inheritdoc />
        /// </summary>
        /// <returns></returns>
        public HttpContent Create()
        {
            Dictionary <string, string> formData = new Dictionary <string, string>();

            if (!string.IsNullOrEmpty(Content))
            {
                formData.Add("content", Content);
            }

            if (!string.IsNullOrEmpty(Title))
            {
                formData.Add("title", Title);
            }

            if (!string.IsNullOrEmpty(Slug))
            {
                formData.Add("slug", Slug);
            }

            if (!string.IsNullOrEmpty(Password))
            {
                formData.Add("password", Password);
            }

            if (AuthorId > 0)
            {
                formData.Add("author", AuthorId.ToString());
            }

            if (!string.IsNullOrEmpty(Excerpt))
            {
                formData.Add("excerpt", Excerpt);
            }

            if (FeaturedImageId > 0)
            {
                formData.Add("featured_media", FeaturedImageId.ToString());
            }

            if (Sticky)
            {
                formData.Add("sticky", "1");
            }

            if (Categories != null && Categories.Length > 0)
            {
                formData.Add("categories", string.Join(',', Categories));
            }

            if (Tags != null && Tags.Length > 0)
            {
                formData.Add("tags", string.Join(',', Tags));
            }

            if (PostDate != DateTime.MinValue)
            {
                formData.Add("date", PostDate.ToString());
            }

            formData.Add("comment_status", CommandStatus.ToString().ToLower());
            formData.Add("ping_status", PingStatus.ToString().ToLower());
            formData.Add("format", Format.ToString().ToLower());
            formData.Add("status", Status.ToString().ToLower());
            return(new FormUrlEncodedContent(formData));
        }
예제 #2
0
 public static string BuildUrl(string subReddit, PostStatus postStatus, int maxPosts = 100)
 {
     return($"https://www.reddit.com/r/{subReddit}/{postStatus.ToString().ToLower()}/.json?limit={maxPosts}");
 }
예제 #3
0
        private async void DownloadBtn_Click(object sender, RoutedEventArgs e)
        {
            string     subRedditName = this.SubredditTBox.Text;
            PostStatus postStatus    = (PostStatus)this.PostStatusComboBox.SelectedItem;
            int        maxPosts      = Int32.Parse(PostCountTBox.Text);

            RedditRipper ripper    = new RedditRipper(subRedditName, postStatus, maxPosts);
            SubReddit    subReddit = await ripper.GetSubReddit();

            foreach (Post post in subReddit.Data.Posts)
            {
                DownloadItem item = new DownloadItem();
                item.Title = post.Data.Title;
                item.Url   = post.Data.Url;

                if (item.Url.Contains("gfycat.com"))
                {
                    item.Url = RedditAPI.utils.Utils.GetImageUrlFromGfycat(item.Url);
                }

                item.FileName = Web.utils.Utils.Instance.GetFileNameFromUrl(item.Url);
                item.FileName = string.IsNullOrEmpty(item.FileName) || string.IsNullOrWhiteSpace(item.FileName)
                    ? $"{item.Title}.png" : item.FileName;

                this.DownloadLogBox.Items.Add(item);

                Downloader downloader = new Downloader($"Downloads\\{subRedditName}\\{postStatus.ToString()}");
                downloader.DownloadAsync(item);
            }
        }