Exemplo n.º 1
0
        private async Task Get4chanThreadAsync(_4chanDataCatalog catalog)
        {
            if (catalog.Items.Count != 0)
            {
                return;
            }

            Uri        dataUri = new Uri("http://a.4cdn.org/" + catalog.Board + "/thread/" + catalog.Id.ToString() + ".json");
            HttpClient _client = new HttpClient();
            var        result  = await _client.GetStringAsync(dataUri);

            JsonObject jsonObject = JsonObject.Parse(result);

            JsonArray threads = jsonObject["posts"].GetArray();

            foreach (JsonValue threadValue in threads)
            {
                JsonObject threadObject = threadValue.GetObject();

                if (threadObject.ContainsKey("now") &&
                    threadObject.ContainsKey("name") &&
                    threadObject.ContainsKey("com"))
                {
                    _4chanDataThread thread;

                    if (threadObject.ContainsKey("filename"))
                    {
                        thread = new _4chanDataThread(catalog.Board,
                                                      threadObject["now"].GetString(),
                                                      threadObject["name"].GetString(),
                                                      threadObject["com"].GetString(),
                                                      true,
                                                      threadObject["ext"].GetString(),
                                                      threadObject["tim"].GetNumber());
                    }
                    else
                    {
                        thread = new _4chanDataThread(catalog.Board,
                                                      threadObject["now"].GetString(),
                                                      threadObject["name"].GetString(),
                                                      threadObject["com"].GetString(),
                                                      false);
                    }

                    catalog.Items.Add(thread);
                }
            }
        }
Exemplo n.º 2
0
        private async Task Get4chanCatalogAsync(_4chanDataBoard board)
        {
            if (board.Items.Count != 0)
            {
                return;
            }

            Uri        dataUri = new Uri("http://a.4cdn.org/" + board.Board + "/catalog.json");
            HttpClient _client = new HttpClient();
            var        result  = await _client.GetStringAsync(dataUri);

            JsonArray     pages = JsonArray.Parse(result);
            CatalogsGroup group = new CatalogsGroup();

            foreach (JsonValue pageValue in pages)
            {
                JsonObject page    = pageValue.GetObject();
                JsonArray  threads = page["threads"].GetArray();

                foreach (JsonValue threadValue in threads)
                {
                    JsonObject threadObject = threadValue.GetObject();

                    if (threadObject.ContainsKey("tim") &&
                        threadObject.ContainsKey("no") &&
                        threadObject.ContainsKey("now") &&
                        threadObject.ContainsKey("name") &&
                        threadObject.ContainsKey("com") &&
                        threadObject.ContainsKey("ext"))
                    {
                        _4chanDataCatalog catalog = new _4chanDataCatalog(threadObject["no"].GetNumber(),
                                                                          threadObject["tim"].GetNumber(),
                                                                          threadObject["now"].GetString(),
                                                                          threadObject["name"].GetString(),
                                                                          threadObject["com"].GetString(),
                                                                          threadObject["ext"].GetString(),
                                                                          board.Board);

                        group.Items.Add(catalog);
                    }
                }
            }

            board.Items.Add(group);
        }
Exemplo n.º 3
0
        /*******************************************************************************************************/

        public static async Task <IEnumerable <_4chanDataThread> > GetThreadAsync(_4chanDataCatalog catalog)
        {
            await _4chanDataSrc.Get4chanThreadAsync(catalog);

            return(catalog.Items);
        }