Search in sources :

Example 1 with ITaskSession

use of com.acgist.snail.pojo.ITaskSession in project snail by acgist.

the class TaskTableCell method updateItem.

@Override
public void updateItem(String value, boolean empty) {
    super.updateItem(value, empty);
    final HBox box = new HBox();
    final ITaskSession taskSession = this.getTableRow().getItem();
    if (taskSession != null) {
        final Text name = new Text(value);
        if (this.pos != null) {
            box.setAlignment(this.pos);
        }
        if (this.icon) {
            final FileType fileType = taskSession.getFileType();
            final Label fileLabel = Fonts.fileTypeIconLabel(fileType);
            box.getChildren().add(fileLabel);
        }
        if (this.tooltip) {
            this.setTooltip(Tooltips.newTooltip(value));
        }
        box.getChildren().add(name);
    }
    this.setGraphic(box);
}
Also used : HBox(javafx.scene.layout.HBox) ITaskSession(com.acgist.snail.pojo.ITaskSession) FileType(com.acgist.snail.pojo.ITaskSession.FileType) Label(javafx.scene.control.Label) Text(javafx.scene.text.Text)

Example 2 with ITaskSession

use of com.acgist.snail.pojo.ITaskSession in project snail by acgist.

the class HlsContextTest method testHlsContext.

@Test
void testHlsContext() throws DownloadException {
    final String id = UUID.randomUUID().toString();
    final TaskEntity task = new TaskEntity();
    task.setId(id);
    task.setName("acgist");
    final ITaskSession session = TaskSession.newInstance(task);
    assertDoesNotThrow(() -> {
        HlsContext.getInstance().m3u8(id, new M3u8(Type.FILE, null, List.of()));
        HlsContext.getInstance().hlsSession(session);
        HlsContext.getInstance().remove(session);
    });
}
Also used : TaskEntity(com.acgist.snail.pojo.entity.TaskEntity) ITaskSession(com.acgist.snail.pojo.ITaskSession) M3u8(com.acgist.snail.pojo.bean.M3u8) Test(org.junit.jupiter.api.Test)

Example 3 with ITaskSession

use of com.acgist.snail.pojo.ITaskSession in project snail by acgist.

the class ProtocolContextTest method testBuildTaskSession.

@Test
void testBuildTaskSession() throws DownloadException {
    SnailBuilder.newBuilder().enableAllProtocol().buildSync();
    ITaskSession result;
    result = ProtocolContext.getInstance().buildTaskSession("https://www.acgist.com");
    assertNotNull(result);
    this.log(result);
// result = ProtocolContext.getInstance().buildTaskSession("641000d9be79ad8947701c338c06211ba69e1b09");
// assertNotNull(result);
// this.log(result);
// result = ProtocolContext.getInstance().buildTaskSession(Base32Utils.encode(StringUtils.unhex("641000d9be79ad8947701c338c06211ba69e1b09")));
// assertNotNull(result);
// this.log(result);
// result = ProtocolContext.getInstance().buildTaskSession("thunder://QUFodHRwOi8vdXBvcy1oei1taXJyb3Jic3l1LmFjZ3ZpZGVvLmNvbS91cGdjeGNvZGUvMjIvNjkvMTI0NDY5MjIvMTI0NDY5MjItMS02NC5mbHY/ZT1pZzhldXhaTTJyTmNOYmhIaGJVVmhvTXpuV05CaHdkRXRvOGc1WDEwdWdOY1hCQl8mZGVhZGxpbmU9MTU2MTAyMTI1NCZnZW49cGxheXVybCZuYnM9MSZvaT0xNzAzMTc4Nzk0Jm9zPWJzeXUmcGxhdGZvcm09aHRtbDUmdHJpZD1kZWIzMTdkMjI0NDc0ZDg5YWI4YmI1ZDgzNWMzMGY3MyZ1aXBrPTUmdXBzaWc9YWY3NmExOTUyYjFlNjZhYmQ0NzBiNmRmOWYyNTA2MWImdXBhcmFtcz1lLGRlYWRsaW5lLGdlbixuYnMsb2ksb3MscGxhdGZvcm0sdHJpZCx1aXBrJm1pZD00NTU5MjY3Wlo==");
// assertNotNull(result);
// this.log(result);
// result = ProtocolContext.getInstance().buildTaskSession("E:/snail/b3e9dcb123b80078aa5ace79323f925e8f755a6a.torrent");
// assertNotNull(result);
// this.log(result);
}
Also used : ITaskSession(com.acgist.snail.pojo.ITaskSession) Test(org.junit.jupiter.api.Test)

Example 4 with ITaskSession

use of com.acgist.snail.pojo.ITaskSession in project snail by acgist.

the class TaskContextTest method testNewTask.

@Test
void testNewTask() throws DownloadException {
    SnailBuilder.newBuilder().buildSync();
    final var taskContext = TaskContext.getInstance();
    var exception = assertThrows(DownloadException.class, () -> taskContext.download("https://www.acgist.com"));
    this.log(exception.getMessage());
    exception = assertThrows(DownloadException.class, () -> taskContext.submit(null));
    this.log(exception.getMessage());
    ProtocolContext.getInstance().register(HttpProtocol.getInstance());
    final ITaskSession taskSession = taskContext.download("https://www.acgist.com");
    assertTrue(taskContext.allTask().size() > 0);
    FileUtils.delete(taskSession.getFile());
    taskSession.delete();
}
Also used : ITaskSession(com.acgist.snail.pojo.ITaskSession) DownloadException(com.acgist.snail.context.exception.DownloadException) Test(org.junit.jupiter.api.Test)

Example 5 with ITaskSession

use of com.acgist.snail.pojo.ITaskSession in project snail by acgist.

the class TaskContextTest method testRestart.

@Test
void testRestart() throws DownloadException {
    SnailBuilder.newBuilder().enableAllProtocol().buildSync();
    final var taskContext = TaskContext.getInstance();
    ITaskSession taskSession = taskContext.download("1234567890123456789012345678901234567890");
    assertNotNull(taskSession);
    assertTrue(taskContext.allTask().size() > 0);
    this.log(taskSession.getClass());
    taskSession.setType(Type.TORRENT);
    taskSession.setStatus(Status.AWAIT);
    assertTrue(taskSession.buildDownloader() instanceof MagnetDownloader);
    taskSession.setTorrent("E://snail/902FFAA29EE632C8DC966ED9AB573409BA9A518E.torrent");
    taskSession.restart();
    assertNotNull(taskSession);
    assertTrue(taskContext.allTask().size() > 0);
    assertTrue(taskSession.buildDownloader() instanceof TorrentDownloader);
    this.log(taskSession.getClass());
    FileUtils.delete(taskSession.getFile());
    taskSession.delete();
}
Also used : MagnetDownloader(com.acgist.snail.downloader.magnet.MagnetDownloader) ITaskSession(com.acgist.snail.pojo.ITaskSession) TorrentDownloader(com.acgist.snail.downloader.torrent.TorrentDownloader) Test(org.junit.jupiter.api.Test)

Aggregations

ITaskSession (com.acgist.snail.pojo.ITaskSession)8 Test (org.junit.jupiter.api.Test)5 DownloadException (com.acgist.snail.context.exception.DownloadException)3 IContext (com.acgist.snail.IContext)1 Snail (com.acgist.snail.Snail)1 IDownloader (com.acgist.snail.downloader.IDownloader)1 MagnetDownloader (com.acgist.snail.downloader.magnet.MagnetDownloader)1 TorrentDownloader (com.acgist.snail.downloader.torrent.TorrentDownloader)1 Logger (com.acgist.snail.logger.Logger)1 LoggerFactory (com.acgist.snail.logger.LoggerFactory)1 FileType (com.acgist.snail.pojo.ITaskSession.FileType)1 M3u8 (com.acgist.snail.pojo.bean.M3u8)1 TaskEntity (com.acgist.snail.pojo.entity.TaskEntity)1 Protocol (com.acgist.snail.protocol.Protocol)1 StringUtils (com.acgist.snail.utils.StringUtils)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Label (javafx.scene.control.Label)1