예제 #1
0
 public Torrents(String html) {
   super();
   Matcher mTorrent =
       Pattern.compile(
               "<a href=\"\\?section=INFOS&amp;id=(\\d+)#FTD_MENU\" title=\"([\\w\\._-]+)\">")
           .matcher(html);
   // Matcher mTorrent = Pattern.compile("<li class=\"torrents_category (?:data_alt)?\"><a
   // class=\"categorie cat62 year\"
   // href=\"\\?section=TORRENTS&amp;module=&amp;parent_cat_id=1&amp;year=\\d{4}\">(\\d{4})</a></li>\\s*<li class=\"torrents_name (?:data_alt)\"><a href=\"\\?section=INFOS&amp;id=\\d+#FTD_MENU\" title=\"[\\w\\.-]+\"> ([\\w\\.-]+) </a></li>\\s*<li class=\"imdb_id_imdb_id (?:data_alt)\"><img src=\"themes/images/more_torrents(?:_disabled)?\\.gif\" alt=\"\" /></li>\\s*<li class=\"torrents_calendar (?:data_alt)\"><img src=\"themes/images/calendar(?:_disabled)?\\.gif\" alt=\"\" /></li>\\s*<li class=\"torrents_size (?:data_alt)\">([\\d\\.]+ \\wB)</li>\\s*<li class=\"torrents_seeders (?:data_alt)\">(\\d+)</li>\\s*<li class=\"torrents_leechers (?:data_alt)\">(\\d+)</li>").matcher(html);
   while (mTorrent.find()) {
     Torrent t = new Torrent();
     t.setId(mTorrent.group(1));
     t.setTitle(mTorrent.group(2));
     // t.setYear(mTorrent.group(2));
     // t.setSize(mTorrent.group(3));
     // t.setSeeders(mTorrent.group(4));
     // t.setLeechers(mTorrent.group(5));
     this.add(t);
   }
 }
예제 #2
0
  @SuppressWarnings("unchecked")
  public static void main(String[] args)
      throws IOException, BencodingException, InterruptedException {

    if (args.length != 2) {
      System.out.println("incorrect number of command line arguments");
      return;
    }

    /*
     * Check if we can open the torrent file
     */
    File tf = new File(args[0]);
    if (!tf.canRead()) {
      System.out.println("Can't read torrent file");
    }

    /*
     * Read the torrent file into a byte array and create
     * a TorrentInfo object with it
     */
    byte[] byteFile = new byte[(int) tf.length()];
    DataInputStream file = new DataInputStream(new FileInputStream(tf));
    file.readFully(byteFile);
    file.close();
    TorrentInfo ti = new TorrentInfo(byteFile);
    Torrent tt = new Torrent(ti, args[1]);
    (new Thread(tt)).start();

    Scanner sc = new Scanner(System.in);
    System.out.println("Please type 'q' to quit");
    while (true) {
      if (sc.nextLine().equals("q")) {
        tt.stop();
        return;
      } else continue;
    }
  }