更新
This commit is contained in:
parent
6f53d6e5c1
commit
5856864f52
24
main.py
24
main.py
@ -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):
|
query_parser = cmd2.Cmd2ArgumentParser()
|
||||||
while True:
|
query_parser.add_argument("-f", "--filter", help="filter", nargs="?", choices=[member.value for member in PKTaskStatus])
|
||||||
await asyncio.sleep(1)
|
@RunSync
|
||||||
await self.AsyncPrint("ani")
|
@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
|
||||||
|
22
pikpakFs.py
22
pikpakFs.py
@ -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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user