Merge pull request #524 from EstrellaXD/3.1-dev

3.1.7
This commit is contained in:
Estrella Pan
2023-10-05 15:09:55 +08:00
committed by GitHub
6 changed files with 25 additions and 12 deletions

View File

@@ -78,7 +78,6 @@ class Checker:
@staticmethod
def check_img_cache() -> bool:
img_path = Path("data/posters")
# If poster folder is not empty, return True
if img_path.exists():
return True
else:

View File

@@ -55,7 +55,7 @@ class RequestContent(RequestURL):
def post_data(self, _url, data: dict) -> dict:
return self.post_url(_url, data)
def post_form(self, _url, data: dict, files: dict) -> dict:
def post_files(self, _url, data: dict, files: dict) -> dict:
return self.post_form(_url, data, files)
def get_html(self, _url):

View File

@@ -10,7 +10,8 @@ logger = logging.getLogger(__name__)
class TelegramNotification(RequestContent):
def __init__(self, token, chat_id):
super().__init__()
self.notification_url = f"https://api.telegram.org/bot{token}/sendPhoto"
self.photo_url = f"https://api.telegram.org/bot{token}/sendPhoto"
self.message_url = f"https://api.telegram.org/bot{token}/sendMessage"
self.chat_id = chat_id
@staticmethod
@@ -29,10 +30,10 @@ class TelegramNotification(RequestContent):
}
photo = load_image(notify.poster_path)
if photo:
resp = self.post_form(
self.notification_url, data, files={"photo": photo}
resp = self.post_files(
self.photo_url, data, files={"photo": photo}
)
else:
resp = self.post_data(self.notification_url, data)
resp = self.post_data(self.message_url, data)
logger.debug(f"Telegram notification: {resp.status_code}")
return resp.status_code == 200

View File

@@ -94,10 +94,11 @@ def name_process(name: str):
split = re.split("-", name)
if len(split) == 1:
split_space = split[0].split(" ")
for idx, item in enumerate(split_space):
if re.search(r"^[\u4e00-\u9fa5]{2,}", item) is not None:
split_space.remove(item)
split = [item.strip(), " ".join(split_space).strip()]
for idx in [0, -1]:
if re.search(r"^[\u4e00-\u9fa5]{2,}", split_space[idx]) is not None:
chs = split_space[idx]
split_space.remove(chs)
split = [chs, " ".join(split_space)]
break
for item in split:
if re.search(r"[\u0800-\u4e00]{2,}", item) and not name_jp:

View File

@@ -10,5 +10,8 @@ def save_image(img, suffix):
def load_image(img_path):
with open(f"data/{img_path}", "rb") as f:
return f.read()
if img_path:
with open(f"data/{img_path}", "rb") as f:
return f.read()
else:
return None

View File

@@ -79,4 +79,13 @@ def test_raw_parser():
assert info.episode == 13
assert info.season == 1
content = "[ANi] 16bit 的感动 ANOTHER LAYER - 01 [1080P][Baha][WEB-DL][AAC AVC][CHT][MP4]"
info = raw_parser(content)
assert info.group == "ANi"
assert info.title_zh == "16bit 的感动 ANOTHER LAYER"
assert info.resolution == "1080P"
assert info.episode == 1
assert info.season == 1