更新
This commit is contained in:
parent
6f53d6e5c1
commit
5856864f52
26
main.py
26
main.py
@ -4,7 +4,7 @@ from functools import wraps
|
||||
import logging
|
||||
import threading
|
||||
import colorlog
|
||||
from pikpakFs import PKFs, IsDir, IsFile
|
||||
from pikpakFs import PKFs, IsDir, IsFile, PKTaskStatus
|
||||
import os
|
||||
|
||||
def setup_logging():
|
||||
@ -122,8 +122,8 @@ class Console(cmd2.Cmd):
|
||||
logging.info("Debug mode disabled")
|
||||
|
||||
login_parser = cmd2.Cmd2ArgumentParser()
|
||||
login_parser.add_argument("username", help="username")
|
||||
login_parser.add_argument("password", help="password")
|
||||
login_parser.add_argument("username", help="username", nargs="?")
|
||||
login_parser.add_argument("password", help="password", nargs="?")
|
||||
@RunSync
|
||||
@cmd2.with_argparser(login_parser)
|
||||
async def do_login(self, args):
|
||||
@ -260,12 +260,20 @@ class Console(cmd2.Cmd):
|
||||
if not IsDir(node):
|
||||
await self.AsyncPrint("Invalid directory")
|
||||
return
|
||||
await Client.Download(args.url, node)
|
||||
|
||||
async def ani(self):
|
||||
while True:
|
||||
await asyncio.sleep(1)
|
||||
await self.AsyncPrint("ani")
|
||||
task = await Client.Download(args.url, node)
|
||||
await self.AsyncPrint(f"Task {task.id} created")
|
||||
|
||||
query_parser = cmd2.Cmd2ArgumentParser()
|
||||
query_parser.add_argument("-f", "--filter", help="filter", nargs="?", choices=[member.value for member in PKTaskStatus])
|
||||
@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():
|
||||
global MainLoop, Client
|
||||
|
22
pikpakFs.py
22
pikpakFs.py
@ -19,8 +19,8 @@ class PKTaskStatus(Enum):
|
||||
class PkTask:
|
||||
id = 0
|
||||
def __init__(self, torrent : str, toDirId : str, status : PKTaskStatus = PKTaskStatus.pending):
|
||||
id += 1
|
||||
self.taskId = id
|
||||
PkTask.id += 1
|
||||
self.taskId = PkTask.id
|
||||
self.status = status
|
||||
|
||||
self.runningTask : asyncio.Task = None
|
||||
@ -86,8 +86,24 @@ class PkToken:
|
||||
return cls(**data)
|
||||
|
||||
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):
|
||||
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):
|
||||
self.tasks.append(task)
|
||||
|
Loading…
x
Reference in New Issue
Block a user