package com.frostwire.jlibtorrent.demo; import com.frostwire.jlibtorrent.LibTorrent; import com.frostwire.jlibtorrent.Session; import com.frostwire.jlibtorrent.TorrentAlertAdapter; import com.frostwire.jlibtorrent.TorrentHandle; import com.frostwire.jlibtorrent.alerts.BlockFinishedAlert; import com.frostwire.jlibtorrent.alerts.TorrentFinishedAlert; import java.io.File; import java.util.concurrent.CountDownLatch; /** * @author gubatron * @author aldenml */ public final class DownloadTorrent { public static void main(String[] args) throws Throwable { // comment this line for a real application args = new String[]{"/Users/aldenml/Downloads/Kellee_Maize_The_5th_Element_FrostClick_FrostWire_MP3_April_14_2014.torrent"}; File torrentFile = new File(args[0]); System.out.println("Using libtorrent version: " + LibTorrent.version()); final Session s = new Session(); final TorrentHandle th = s.addTorrent(torrentFile, torrentFile.getParentFile()); final CountDownLatch signal = new CountDownLatch(1); s.addListener(new TorrentAlertAdapter(th) { @Override public void blockFinished(BlockFinishedAlert alert) { int p = (int) (th.getStatus().getProgress() * 100); System.out.println("Progress: " + p); } @Override public void torrentFinished(TorrentFinishedAlert alert) { System.out.print("Torrent finished"); signal.countDown(); } }); th.resume(); signal.await(); } }