Skip to content

Commit 0adc34d

Browse files
committed
Fix and Format something
1 parent 1ba3566 commit 0adc34d

File tree

5 files changed

+23
-21
lines changed

5 files changed

+23
-21
lines changed

kubespider/core/webhook_server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ def download_handler():
8282

8383
err = source_manager.source_provider_manager.download_with_source_provider(event)
8484

85-
if err is None or type(err) is dict:
86-
if type(err) is dict and err['Status'] == "Success":
85+
if err is None or isinstance(err, dict):
86+
if isinstance(err, dict) and err['Status'] == "Success":
8787
notification_server.kubespider_notification_server.send_message(
8888
title="[webhook] start download", name=err['Name'], source=source, path=path
8989
)

kubespider/download_provider/xunlei_download_provider/provider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def send_task(self, token: str, file_info: dict, url: str, path: str) -> TypeErr
136136
logging.error("Create tasks error:%s", req.text)
137137
return ValueError("Create task error")
138138
if url.startswith("magnet:?"):
139-
magnet_name = MagnetUrl(url).Resolve()
139+
magnet_name = MagnetUrl(url).resolve()
140140
logging.info("Check MagnetLink Name:%s", magnet_name)
141141
return {"Status":"Success", "Name":magnet_name}
142142
if url.startswith("ed2k://"):

kubespider/notification_provider/dingtalk_notification_provider/provider.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,8 @@ def build_sign(self, secret: str):
7070
# 计算加签后的密钥
7171
timestamp = str(round(time.time() * 1000))
7272
secret_enc = secret.encode('utf-8')
73-
string_to_sign = '{}\n{}'.format(timestamp, secret)
73+
string_to_sign = f"{timestamp}\n{secret}"
7474
string_to_sign_enc = string_to_sign.encode('utf-8')
7575
hmac_code = hmac.new(secret_enc, string_to_sign_enc, digestmod=hashlib.sha256).digest()
7676
sign = urllib.parse.quote_plus(base64.b64encode(hmac_code))
77-
return timestamp, sign
78-
77+
return timestamp, sign

kubespider/notification_provider/feishu_notification_provider/provider.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def format_message(self, title, **kwargs) -> str:
8484
def build_sign(self, secret: str):
8585
# 计算加签后的密钥
8686
timestamp = str(round(time.time()))
87-
string_to_sign = '{}\n{}'.format(timestamp, secret)
87+
string_to_sign = f"{timestamp}\n{secret}"
8888
hmac_code = hmac.new(string_to_sign.encode("utf-8"), digestmod=hashlib.sha256).digest()
8989
sign = base64.b64encode(hmac_code).decode('utf-8')
90-
return timestamp, sign
90+
return timestamp, sign

kubespider/utils/magnet_url.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import re
12
from urllib.parse import urlparse, parse_qs
23

3-
class MagnetUrl(object):
4+
class MagnetUrl:
45
url = None
56
xturn_delimiter = ':'
67

@@ -57,26 +58,22 @@ def data_index(self, fieldname, index=None):
5758
def __hash_type(self, index=None):
5859
xturn = self.data_index('xt', index)
5960
if not xturn:
60-
return
61+
return None
6162
return ' '.join(xturn.split(self.xturn_delimiter)[1:-1])
6263

6364
def __hash(self, index=None):
6465
xturn = self.data_index('xt', index)
6566
if not xturn:
66-
return
67+
return None
6768
return xturn.split(self.xturn_delimiter)[-1]
6869

6970
def __data_size(self, index=None):
7071
return self.data_index('xl', index)
7172

7273
def __file_entry(self, index):
73-
return dict(
74-
display_name=self.__display_name(index),
75-
data_size=self.__data_size(index),
76-
hash_type=self.__hash_type(index),
77-
hash=self.__hash(index))
74+
return {"display_name": self.__display_name(index), "data_size": self.__data_size(index), "hash_type": self.__hash_type(index), "hash": self.__hash(index)}
7875

79-
def Resolve(self):
76+
def resolve(self):
8077
char = ".torrent"
8178
if self.files[0]['display_name'] is not None:
8279
result = self.files[0]['display_name']
@@ -85,9 +82,15 @@ def Resolve(self):
8582
if "dn" in key:
8683
result = self.data[key]
8784
break
88-
else:
89-
result = "No Name Found"
9085
if result.endswith(char):
9186
result = result[:-len(char)]
92-
93-
return result
87+
return result
88+
89+
def ed2k_filename(self):
90+
pattern = r'ed2k://\|file\|(.+)\|(\d+)\|([a-fA-F0-9]+)\|/'
91+
match = re.match(pattern, self.url)
92+
if match:
93+
filename = match.group(1)
94+
return filename
95+
else:
96+
raise ValueError("Invalid ed2k link")

0 commit comments

Comments
 (0)