示例#1
0
def make_task(url="whatever",
              uuid="whatever",
              submitted_ts="whatever",
              status=0,
              profile="audio") -> YTDLDownloadTask:
    s = SubmittedTaskModel.create(url, uuid, submitted_ts, status, profile)
    return YTDLDownloadTask(s)
示例#2
0
def test_ytdl_args_wrong_status():
    with tempfile.TemporaryDirectory() as tmp:
        c = ConfigManager(ytdl_root=Path(tmp))
        task_processor = TaskProcessor(c)
        task = YTDLDownloadTask(SubmittedTaskModel.create("https://youtube-dl", "uuid", "2019-01-01 09:19:20",
                                                          TaskStatus.Done, None))
        args = task_processor.ytdl_args(task)
        assert isinstance(args, TaskProcessorException)
示例#3
0
def test_ytdl_args():
    with tempfile.TemporaryDirectory() as tmp:
        c = ConfigManager(ytdl_root=Path(tmp))
        task_processor = TaskProcessor(c)
        url = "https://youtube-dl"
        task = YTDLDownloadTask(SubmittedTaskModel.create("https://youtube-dl", "uuid", "2019-01-01 09:19:20",
                                                          TaskStatus.Processing, None))
        args = task_processor.ytdl_args(task)
        assert args is not None
        assert args == ["-m", "youtube_dl", url, "--newline"]
示例#4
0
def test_ytdl_args_with_config():
    with tempfile.TemporaryDirectory() as tmp_dir:
        with tempfile.NamedTemporaryFile(dir=tmp_dir) as tmp_file:
            path = Path(tmp_file.name)
            url = "https://youtube-dl"
            c = ConfigManager(ytdl_root=Path(tmp_dir))
            task_processor = TaskProcessor(c)
            task = YTDLDownloadTask(SubmittedTaskModel.create(url, "uuid", "2019-01-01 09:19:20",
                                                              TaskStatus.Processing, path.name))
            args = task_processor.ytdl_args(task)
            assert args == ["-m", "youtube_dl", url, "--newline", "--ignore-config", "--config-location",
                            str(path.resolve())]
示例#5
0
def test_ytdl_args_with_missing_config():
    with tempfile.TemporaryDirectory() as tmp_dir:
        with tempfile.NamedTemporaryFile(dir=tmp_dir) as tmp_file:
            path = Path(tmp_file.name)
            profile = "fakefakefakefakefakefake"

            assert path.name != profile

            url = "https://youtube-dl"
            c = ConfigManager(ytdl_root=Path(tmp_dir))
            task_processor = TaskProcessor(c)
            task = YTDLDownloadTask(SubmittedTaskModel.create(url, "uuid", "2019-01-01 09:19:20",
                                                              TaskStatus.Processing, profile))
            args = task_processor.ytdl_args(task)
            assert isinstance(args, TaskProcessorException)
示例#6
0
    def _row_to_download_task(
            row: Optional[Mapping]) -> Optional[DownloadTask]:
        if row is not None:
            uuid = row["uuid"]
            url = row["url"]
            task_type = row["type"]
            profile = row["profile"]
            submitted_ts = row["submitted_ts"]
            status = TaskStatus(row["status"])

            submitted_task = SubmittedTaskModel.create(url, uuid, submitted_ts,
                                                       status, profile)

            if task_type == repr(TaskType.YTDL):
                return YTDLDownloadTask(submitted_task)
            else:
                return None
        else:
            return None
示例#7
0
 async def add(self, task: DownloadRequestModel) -> SubmittedTaskModel:
     sub = SubmittedTaskModel.create(task.url, str(uuid.uuid4()), str(datetime.now()), TaskStatus.Created,
                                     task.profile)
     down = YTDLDownloadTask(sub)
     await self.task_queue.add(down)
     return sub