Exemple #1
0
        public Post ConvertPostFromJson(JToken jsonPost)
        {
            Post newPost = new Post
            {
                ID         = jsonPost["id"].ToString(),
                Title      = jsonPost["title"].ToString(),
                Content    = jsonPost["selftext"].ToString(),
                Permalink  = jsonPost["permalink"].ToString(),
                Link       = jsonPost["url"].ToString(),
                AuthorName = jsonPost["author"].ToString(),
                Likes      = Convert.ToInt32(jsonPost["ups"]),
                Thumbnail  = jsonPost["thumbnail"].ToString(),
                Subreddit  = jsonPost["subreddit"].ToString(),
                NSFW       = Convert.ToBoolean(jsonPost["over_18"])
            };

            newPost.LinkType = LinkChecker.GetLinkType(newPost.Link);
            if (newPost.LinkType == "Youtube")
            {
                newPost.Link = LinkChecker.ConvertYoutubeLink(newPost.Link);
            }

            if (newPost.LinkType == "Streamable")
            {
                newPost.Link     = LinkChecker.ConvertStreamableLink(newPost.Link);
                newPost.LinkType = "Youtube";
            }

            if (newPost.LinkType == "Twitch")
            {
                newPost.Link = LinkChecker.ConvertTwitchLink(newPost.Link);
            }

            // Convert gfycat and gifv to use reddit video
            if (newPost.LinkType == "Gfycat" || newPost.LinkType == "Gifv")
            {
                newPost.Link     = jsonPost["preview"]["reddit_video_preview"]["fallback_url"].ToString();
                newPost.LinkType = "Video";
            }

            // For converting reddit videos
            if (Convert.ToBoolean(jsonPost["is_video"]) == true)
            {
                newPost.Link     = jsonPost["secure_media"]["reddit_video"]["fallback_url"].ToString();
                newPost.LinkType = "Video";
            }
            return(newPost);
        }