-
Notifications
You must be signed in to change notification settings - Fork 0
/
TorrentClient.py
85 lines (68 loc) · 2.08 KB
/
TorrentClient.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python3
from abc import abstractmethod
from typing import List, Union
from typing_extensions import TypedDict
Movie = TypedDict('Movie', {'name': str, 'year': int})
# TorrentStatus = TypedDict(
# "TorrentStatus", {
# "Availabilities": float,
# "downloading": bool,
# "stoped": bool,
# "progress": float,
# "torrent_id": str,
# "name": str,
# "size": int,
# "free_space": int,
# })
class TorrentStatus():
@abstractmethod
def __init__(self, torrent_id: str, torrent_client):
pass
#self.torrent_id: str
# self.availabilities: float
# self.downloading: bool
# self.paused: bool
# self.progress: float
# self.name: str
# self.size: int
# self.free_space: int
@abstractmethod
def refresh(self):
raise NotImplementedError
@abstractmethod
def start(self):
raise NotImplementedError
@abstractmethod
def stop(self):
raise NotImplementedError
class TorrentClient:
def __init__(self, url: str, port: int, user: str, password: str):
self.url = url
self.port = port
self.user = user
self.password = password
@abstractmethod
def connect(self):
raise NotImplementedError
@abstractmethod
def disconnect(self):
raise NotImplementedError
@abstractmethod
def add_torrent(self, file: bytes, paused: bool, path: str = None) -> str:
raise NotImplementedError
@abstractmethod
def del_torrent(self, torrent_id: str):
raise NotImplementedError
@abstractmethod
def get_torrent_status(self, torrent_id: str) -> TorrentStatus:
raise NotImplementedError
@abstractmethod
def get_torrents_status(self,
torrent_id: List[str]) -> List[TorrentStatus]:
raise NotImplementedError
@abstractmethod
def start_torrent(self, torrent_id: str):
raise NotImplementedError
@abstractmethod
def stop_torrent(self, torrent_id: str):
raise NotImplementedError