GenuineSounds

HMoe Java Object Creator

Jun 17th, 2014
378
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.60 KB | None | 0 0
  1. package src.genuinevm.hmoe;
  2.  
  3. import java.io.IOException;
  4. import java.util.ArrayList;
  5. import java.util.Collections;
  6. import java.util.List;
  7.  
  8. import org.jsoup.Connection;
  9. import org.jsoup.Jsoup;
  10.  
  11. import com.google.gson.Gson;
  12.  
  13. public class Parser {
  14.  
  15.     public static void main(String[] args) {
  16.         Parser mo = new Parser();
  17.         mo.parse();
  18.         mo.output();
  19.     }
  20.  
  21.     List<Connection> cons = Collections.synchronizedList(new ArrayList<>());
  22.     List<String> docs = Collections.synchronizedList(new ArrayList<>());
  23.     List<Video> vids = Collections.synchronizedList(new ArrayList<>());
  24.  
  25.     Parser() {
  26.         for (int i = 0; i < 31; i++)
  27.             cons.add(Jsoup.connect("http://www.h-moe.com/main/video_greed?page=" + (i + 1)));
  28.         cons.stream().parallel().forEach(this::init);
  29.     }
  30.  
  31.     void init(Connection connection) {
  32.         try {
  33.             String doc = connection.execute().body();
  34.             synchronized (docs) {
  35.                 docs.add(doc);
  36.             }
  37.         }
  38.         catch (IOException e) {
  39.             e.printStackTrace();
  40.         }
  41.     }
  42.  
  43.     void parse() {
  44.         docs.forEach(doc -> {
  45.             Gson gson = new Gson();
  46.             Page page = gson.fromJson(doc, Page.class);
  47.             synchronized (vids) {
  48.                 vids.addAll(page.video);
  49.             }
  50.         });
  51.         Collections.sort(vids, (v1, v2) -> {
  52.             return v1.name.compareToIgnoreCase(v2.name);
  53.         });
  54.     }
  55.  
  56.     void output() {
  57.         vids.stream().sequential().forEach(System.out::println);
  58.     }
  59. }
  60.  
  61. // Page Structure
  62. class Page {
  63.  
  64.     int status;
  65.     int current;
  66.     List<Video> video;
  67. }
  68.  
  69. // Video Structure
  70. class Video {
  71.  
  72.     int member;
  73.     String name;
  74.     String thumb;
  75.     String link;
  76.     String description;
  77.  
  78.     @Override
  79.     public String toString() {
  80.         return name;
  81.     }
  82. }
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment