This commit is contained in:
fengfeng 2024-10-30 19:41:12 +08:00
parent 6f53d6e5c1
commit 5856864f52
3 changed files with 39 additions and 13 deletions

26
main.py
View File

@ -4,7 +4,7 @@ from functools import wraps
import logging import logging
import threading import threading
import colorlog import colorlog
from pikpakFs import PKFs, IsDir, IsFile from pikpakFs import PKFs, IsDir, IsFile, PKTaskStatus
import os import os
def setup_logging(): def setup_logging():
@ -122,8 +122,8 @@ class Console(cmd2.Cmd):
logging.info("Debug mode disabled") logging.info("Debug mode disabled")
login_parser = cmd2.Cmd2ArgumentParser() login_parser = cmd2.Cmd2ArgumentParser()
login_parser.add_argument("username", help="username") login_parser.add_argument("username", help="username", nargs="?")
login_parser.add_argument("password", help="password") login_parser.add_argument("password", help="password", nargs="?")
@RunSync @RunSync
@cmd2.with_argparser(login_parser) @cmd2.with_argparser(login_parser)
async def do_login(self, args): async def do_login(self, args):
@ -260,12 +260,20 @@ class Console(cmd2.Cmd):
if not IsDir(node): if not IsDir(node):
await self.AsyncPrint("Invalid directory") await self.AsyncPrint("Invalid directory")
return return
await Client.Download(args.url, node) task = await Client.Download(args.url, node)
await self.AsyncPrint(f"Task {task.id} created")
async def ani(self):
while True: query_parser = cmd2.Cmd2ArgumentParser()
await asyncio.sleep(1) query_parser.add_argument("-f", "--filter", help="filter", nargs="?", choices=[member.value for member in PKTaskStatus])
await self.AsyncPrint("ani") @RunSync
@cmd2.with_argparser(query_parser)
async def do_query(self, args):
"""
Query All Tasks
"""
tasks = await Client.QueryTasks(PKTaskStatus(args.filter) if args.filter is not None else None)
for task in tasks:
await self.AsyncPrint(f"{task.id}: {task.status.name}")
async def mainLoop(): async def mainLoop():
global MainLoop, Client global MainLoop, Client

View File

@ -19,8 +19,8 @@ class PKTaskStatus(Enum):
class PkTask: class PkTask:
id = 0 id = 0
def __init__(self, torrent : str, toDirId : str, status : PKTaskStatus = PKTaskStatus.pending): def __init__(self, torrent : str, toDirId : str, status : PKTaskStatus = PKTaskStatus.pending):
id += 1 PkTask.id += 1
self.taskId = id self.taskId = PkTask.id
self.status = status self.status = status
self.runningTask : asyncio.Task = None self.runningTask : asyncio.Task = None
@ -86,8 +86,24 @@ class PkToken:
return cls(**data) return cls(**data)
class PKFs: class PKFs:
async def _task_pending(self, task : PkTask):
pkTask = await self.client.offline_download(task.torrent, task.toDirId)
task.pkTaskId = pkTask["task"]["id"]
task.status = PKTaskStatus.offline_downloading
async def _task_offline_downloading(self, task : PkTask):
waitTime = 1
await asyncio.sleep(waitTime)
# status = await self.client.get_task_status(task.pkTaskId)
async def _task_worker(self, task : PkTask): async def _task_worker(self, task : PkTask):
pass while task.status != PKTaskStatus.done and task.status != PKTaskStatus.error:
if task.status == PKTaskStatus.pending:
await self._task_pending(task)
if task.status == PKTaskStatus.offline_downloading:
await self._task_offline_downloading(task)
break
def RunTask(self, task : PkTask): def RunTask(self, task : PkTask):
self.tasks.append(task) self.tasks.append(task)

View File

@ -6,4 +6,6 @@ Todo:
- [x] 实现自定义根路径 - [x] 实现自定义根路径
- [x] 异步输出频率过高会导致卡死,似乎会多创建一个线程 - [x] 异步输出频率过高会导致卡死,似乎会多创建一个线程
- [ ] 实现Task系统自动刷新文件系统 - [ ] 实现Task队列管理
- [ ] 自动刷新文件系统缓存
- [ ] 分析以下方法的返回值offline_file_info、offline_list、offline_task_retry、delete_tasks