Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package src.genuinevm.hmoe;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.List;
- import org.jsoup.Connection;
- import org.jsoup.Jsoup;
- import com.google.gson.Gson;
- public class Parser {
- public static void main(String[] args) {
- Parser mo = new Parser();
- mo.parse();
- mo.output();
- }
- List<Connection> cons = Collections.synchronizedList(new ArrayList<>());
- List<String> docs = Collections.synchronizedList(new ArrayList<>());
- List<Video> vids = Collections.synchronizedList(new ArrayList<>());
- Parser() {
- for (int i = 0; i < 31; i++)
- cons.add(Jsoup.connect("http://www.h-moe.com/main/video_greed?page=" + (i + 1)));
- cons.stream().parallel().forEach(this::init);
- }
- void init(Connection connection) {
- try {
- String doc = connection.execute().body();
- synchronized (docs) {
- docs.add(doc);
- }
- }
- catch (IOException e) {
- e.printStackTrace();
- }
- }
- void parse() {
- docs.forEach(doc -> {
- Gson gson = new Gson();
- Page page = gson.fromJson(doc, Page.class);
- synchronized (vids) {
- vids.addAll(page.video);
- }
- });
- Collections.sort(vids, (v1, v2) -> {
- return v1.name.compareToIgnoreCase(v2.name);
- });
- }
- void output() {
- vids.stream().sequential().forEach(System.out::println);
- }
- }
- // Page Structure
- class Page {
- int status;
- int current;
- List<Video> video;
- }
- // Video Structure
- class Video {
- int member;
- String name;
- String thumb;
- String link;
- String description;
- @Override
- public String toString() {
- return name;
- }
- }
Advertisement