예제 #1
0
        /// <summary>
        /// This constructor is only used to save dead (from archive) threads
        /// </summary>
        /// <param name="board"></param>
        /// <param name="tc"></param>
        public ThreadWorker(BoardWatcher board, ThreadContainer tc, bool thumbOnly)
        {
            this.ID = tc.Instance.ID;
            this.Board = board;
            this.LastUpdated = tc.Instance.Time;
            this.AddedAutomatically = false;
            this.IsStatic = true;
            this.worker = new BackgroundWorker();
            this.ThumbOnly = thumbOnly;
            this.ThreadTitle = tc.Title;

            save_thread_container(tc);
        }
예제 #2
0
        public ThreadContainer GetThreadData(string board, int id)
        {
            APIResponse response = LoadAPI(string.Format("{0}://a.4cdn.org/{1}/thread/{2}.json", Common.HttpPrefix, board, id));

            switch (response.Error)
            {
                case APIResponse.ErrorType.NoError:
                    ThreadContainer tc = null;

                    JsonObject list = JsonConvert.Import<JsonObject>(response.Data);

                    //if (list == null)
                    //{
                    //    FlushAPI(string.Format("http://a.4cdn.org/{0}/thread/{1}.json", board, id));
                    //    return GetThreadData(board, id);
                    //}

                    if (list.Names.Cast<string>().Contains("posts"))
                    {
                        JsonArray data = list["posts"] as JsonArray;

                        tc = new ThreadContainer(ParseThread((JsonObject)data.First(), board));

                        for (int index = 1; index < data.Count; index++)
                        {
                            tc.AddReply(ParseReply((JsonObject)data[index], board));
                        }
                    }

                    return tc;

                case APIResponse.ErrorType.NotFound:
                    throw new Exception("404");

                case APIResponse.ErrorType.Other:
                    throw new Exception(response.Data);

                default:
                    return null;
            }
        }
예제 #3
0
 public void AddStaticThread(ThreadContainer tc, bool thumbOnly)
 {
     if (this.watched_threads.ContainsKey(tc.Instance.ID))
     {
         // do nothing
         return;
     }
     else
     {
         this.watched_threads.Add(tc.Instance.ID, new ThreadWorker(this, tc, thumbOnly));
     }
 }
예제 #4
0
        private void save_thread_container(ThreadContainer tc)
        {
            string thread_folder = Path.Combine(Program.post_files_dir, this.Board.Board, this.ID.ToString());

            Directory.CreateDirectory(thread_folder);

            string op = Path.Combine(thread_folder, "op.json");

            if (!File.Exists(op))
            {
                string post_data = get_post_string(tc.Instance);
                File.WriteAllText(op, post_data);
            }

            if (tc.Instance.File != null) { Program.dump_files(tc.Instance.File, this.ThumbOnly); }

            int count = tc.Replies.Count();

            int with_image = 0;

            for (int i = 0; i < count; i++)
            {
                string item_path = Path.Combine(thread_folder, tc.Replies[i].ID.ToString() + ".json");

                if (!File.Exists(item_path))
                {
                    string post_data = get_post_string(tc.Replies[i]);
                    File.WriteAllText(item_path, post_data);
                }

                if (tc.Replies[i].File != null)
                {
                    with_image++;
                    Program.dump_files(tc.Replies[i].File, this.ThumbOnly);
                }
            }

            log(new LogEntry()
            {
                Level = LogEntry.LogLevel.Success,
                Message = string.Format("Static thread {0} was saved successfully.", this.ID),
                Sender = "ThreadWorker",
                Title = string.Format("/{0}/ - {1}", this.Board.Board, this.ID)
            });

            log(new LogEntry() { Level = LogEntry.LogLevel.Info, Message = "Optimizing thread data." });

            optimize_thread_file(thread_folder);

            log(new LogEntry() { Level = LogEntry.LogLevel.Success, Message = "Optimisation done." });
        }
예제 #5
0
        private static ThreadContainer parse_ffuuka_json(FoolFuukaParserData ffp_data)
        {
            ThreadContainer tc = null;

            string data = fetch_api(ffp_data);

            JsonObject response = JsonConvert.Import<JsonObject>(data);

            JsonObject threadObject = (JsonObject)response[ffp_data.ThreadID.ToString()];

            JsonObject opPost = (JsonObject)threadObject["op"];

            tc = new ThreadContainer(parse_thread(opPost, ffp_data));

            JsonObject postsObject = (JsonObject)threadObject["posts"];

            foreach (string reply_id in postsObject.Names.Cast<string>())
            {
                JsonObject replyObject = (JsonObject)postsObject[reply_id];
                GenericPost reply = parse_reply(replyObject, ffp_data);
                tc.AddReply(reply);
                continue;
            }

            return tc;
        }