Search in sources :

Example 1 with MultifileEventAdapter

use of com.acgist.snail.gui.event.adapter.MultifileEventAdapter in project snail by acgist.

the class GuiContext method registerAdapter.

/**
 * <p>注册GUI事件默认适配器</p>
 */
public static final void registerAdapter() {
    GuiContext.register(new ShowEventAdapter());
    GuiContext.register(new HideEventAdapter());
    GuiContext.register(new ExitEventAdapter());
    GuiContext.register(new BuildEventAdapter());
    GuiContext.register(new AlertEventAdapter());
    GuiContext.register(new NoticeEventAdapter());
    GuiContext.register(new ResponseEventAdapter());
    GuiContext.register(new MultifileEventAdapter());
    GuiContext.register(new RefreshTaskListEventAdapter());
    GuiContext.register(new RefreshTaskStatusEventAdapter());
}
Also used : MultifileEventAdapter(com.acgist.snail.gui.event.adapter.MultifileEventAdapter) RefreshTaskStatusEventAdapter(com.acgist.snail.gui.event.adapter.RefreshTaskStatusEventAdapter) HideEventAdapter(com.acgist.snail.gui.event.adapter.HideEventAdapter) RefreshTaskListEventAdapter(com.acgist.snail.gui.event.adapter.RefreshTaskListEventAdapter) AlertEventAdapter(com.acgist.snail.gui.event.adapter.AlertEventAdapter) ShowEventAdapter(com.acgist.snail.gui.event.adapter.ShowEventAdapter) ResponseEventAdapter(com.acgist.snail.gui.event.adapter.ResponseEventAdapter) BuildEventAdapter(com.acgist.snail.gui.event.adapter.BuildEventAdapter) ExitEventAdapter(com.acgist.snail.gui.event.adapter.ExitEventAdapter) NoticeEventAdapter(com.acgist.snail.gui.event.adapter.NoticeEventAdapter)

Example 2 with MultifileEventAdapter

use of com.acgist.snail.gui.event.adapter.MultifileEventAdapter in project snail by acgist.

the class SnailTest method testTorrent.

@Test
void testTorrent() throws DownloadException {
    final String torrentPath = "E:\\snail\\0B156834B59B0FF64EE0C9305D4D6EDE421196E6.torrent";
    final var snail = SnailBuilder.newBuilder().enableTorrent().buildSync();
    assertNotNull(snail);
    // 解析种子文件
    final var torrent = TorrentContext.loadTorrent(torrentPath);
    // 过滤下载文件
    final var list = torrent.getInfo().files().stream().filter(TorrentFile::notPaddingFile).map(TorrentFile::path).filter(path -> path.endsWith(".mkv")).collect(Collectors.toList());
    // 设置下载文件
    GuiContext.getInstance().files(DescriptionWrapper.newEncoder(list).serialize());
    // 注册文件选择事件
    GuiContext.register(new MultifileEventAdapter());
    // 开始下载
    snail.download(torrentPath);
    snail.lockDownload();
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Socket(java.net.Socket) Performance(com.acgist.snail.utils.Performance) IOException(java.io.IOException) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) GuiContext(com.acgist.snail.context.GuiContext) DownloadException(com.acgist.snail.context.exception.DownloadException) TorrentFile(com.acgist.snail.pojo.bean.TorrentFile) Test(org.junit.jupiter.api.Test) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) SystemConfig(com.acgist.snail.config.SystemConfig) DescriptionWrapper(com.acgist.snail.pojo.wrapper.DescriptionWrapper) SnailBuilder(com.acgist.snail.Snail.SnailBuilder) MultifileEventAdapter(com.acgist.snail.gui.event.adapter.MultifileEventAdapter) TorrentContext(com.acgist.snail.context.TorrentContext) MultifileEventAdapter(com.acgist.snail.gui.event.adapter.MultifileEventAdapter) TorrentFile(com.acgist.snail.pojo.bean.TorrentFile) Test(org.junit.jupiter.api.Test)

Example 3 with MultifileEventAdapter

use of com.acgist.snail.gui.event.adapter.MultifileEventAdapter in project snail by acgist.

the class TorrentDownloaderTest method testTorrentDownloaderBuild.

@Test
void testTorrentDownloaderBuild() throws DownloadException {
    final String url = "E://snail/902FFAA29EE632C8DC966ED9AB573409BA9A518E.torrent";
    ProtocolContext.getInstance().register(TorrentProtocol.getInstance()).available(true);
    final var torrent = TorrentContext.loadTorrent(url);
    final var list = torrent.getInfo().files().stream().filter(TorrentFile::notPaddingFile).map(TorrentFile::path).collect(Collectors.toList());
    GuiContext.register(new MultifileEventAdapter());
    GuiContext.getInstance().files(DescriptionWrapper.newEncoder(list).serialize());
    final var taskSession = TorrentProtocol.getInstance().buildTaskSession(url);
    final var downloader = taskSession.buildDownloader();
    // downloader.run(); // 不下载
    assertNotNull(downloader);
    final var file = new File(taskSession.getFile());
    assertTrue(file.exists());
    FileUtils.delete(taskSession.getFile());
    taskSession.delete();
}
Also used : MultifileEventAdapter(com.acgist.snail.gui.event.adapter.MultifileEventAdapter) TorrentFile(com.acgist.snail.pojo.bean.TorrentFile) File(java.io.File) TorrentFile(com.acgist.snail.pojo.bean.TorrentFile) Test(org.junit.jupiter.api.Test)

Example 4 with MultifileEventAdapter

use of com.acgist.snail.gui.event.adapter.MultifileEventAdapter in project snail by acgist.

the class TorrentDownloaderTest method testTorrentDownloader.

@Test
void testTorrentDownloader() throws DownloadException {
    TorrentInitializer.newInstance().sync();
    final String url = "E://snail/902FFAA29EE632C8DC966ED9AB573409BA9A518E.torrent";
    ProtocolContext.getInstance().register(TorrentProtocol.getInstance()).available(true);
    final var torrent = TorrentContext.loadTorrent(url);
    final var list = torrent.getInfo().files().stream().filter(TorrentFile::notPaddingFile).map(TorrentFile::path).collect(Collectors.toList());
    GuiContext.register(new MultifileEventAdapter());
    GuiContext.getInstance().files(DescriptionWrapper.newEncoder(list).serialize());
    final var taskSession = TorrentProtocol.getInstance().buildTaskSession(url);
    final var downloader = taskSession.buildDownloader();
    downloader.run();
    final var file = new File(taskSession.getFile());
    assertTrue(file.exists());
    assertTrue(ArrayUtils.isNotEmpty(file.list()));
    FileUtils.delete(taskSession.getFile());
    taskSession.delete();
}
Also used : MultifileEventAdapter(com.acgist.snail.gui.event.adapter.MultifileEventAdapter) TorrentFile(com.acgist.snail.pojo.bean.TorrentFile) File(java.io.File) TorrentFile(com.acgist.snail.pojo.bean.TorrentFile) Test(org.junit.jupiter.api.Test)

Aggregations

MultifileEventAdapter (com.acgist.snail.gui.event.adapter.MultifileEventAdapter)4 TorrentFile (com.acgist.snail.pojo.bean.TorrentFile)3 Test (org.junit.jupiter.api.Test)3 File (java.io.File)2 SnailBuilder (com.acgist.snail.Snail.SnailBuilder)1 SystemConfig (com.acgist.snail.config.SystemConfig)1 GuiContext (com.acgist.snail.context.GuiContext)1 TorrentContext (com.acgist.snail.context.TorrentContext)1 DownloadException (com.acgist.snail.context.exception.DownloadException)1 AlertEventAdapter (com.acgist.snail.gui.event.adapter.AlertEventAdapter)1 BuildEventAdapter (com.acgist.snail.gui.event.adapter.BuildEventAdapter)1 ExitEventAdapter (com.acgist.snail.gui.event.adapter.ExitEventAdapter)1 HideEventAdapter (com.acgist.snail.gui.event.adapter.HideEventAdapter)1 NoticeEventAdapter (com.acgist.snail.gui.event.adapter.NoticeEventAdapter)1 RefreshTaskListEventAdapter (com.acgist.snail.gui.event.adapter.RefreshTaskListEventAdapter)1 RefreshTaskStatusEventAdapter (com.acgist.snail.gui.event.adapter.RefreshTaskStatusEventAdapter)1 ResponseEventAdapter (com.acgist.snail.gui.event.adapter.ResponseEventAdapter)1 ShowEventAdapter (com.acgist.snail.gui.event.adapter.ShowEventAdapter)1 DescriptionWrapper (com.acgist.snail.pojo.wrapper.DescriptionWrapper)1 Performance (com.acgist.snail.utils.Performance)1