mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-04-23 18:11:37 +08:00
Merge remote-tracking branch 'origin/main'
# Conflicts: # auto_bangumi/api.py # auto_bangumi/parser/analyser/raw_parser.py
This commit is contained in:
23
auto_bangumi/ab_decorator/__init__.py
Normal file
23
auto_bangumi/ab_decorator/__init__.py
Normal file
@@ -0,0 +1,23 @@
|
||||
import logging
|
||||
import time
|
||||
|
||||
import requests
|
||||
|
||||
from conf import settings
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def qb_connect_failed_wait(func):
|
||||
def wrapper(*args, **kwargs):
|
||||
times = 0
|
||||
while times < 5:
|
||||
try:
|
||||
return func(*args, **kwargs)
|
||||
except Exception as e:
|
||||
logger.debug(f"URL: {args[0]}")
|
||||
logger.warning("Cannot connect to qBittorrent. Wait 5 min and retry...")
|
||||
time.sleep(3)
|
||||
times += 1
|
||||
return wrapper
|
||||
@@ -5,12 +5,14 @@ from qbittorrentapi import Client, LoginFailed
|
||||
from qbittorrentapi.exceptions import Conflict409Error
|
||||
|
||||
from conf import settings
|
||||
from ab_decorator import qb_connect_failed_wait
|
||||
|
||||
from downloader.exceptions import ConflictError
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@qb_connect_failed_wait
|
||||
class QbDownloader:
|
||||
def __init__(self, host, username, password):
|
||||
self._client = Client(
|
||||
|
||||
27
auto_bangumi/parser/analyser/bangumi_api.py
Normal file
27
auto_bangumi/parser/analyser/bangumi_api.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import re
|
||||
import time
|
||||
|
||||
from network import RequestContent
|
||||
from conf import settings
|
||||
|
||||
|
||||
class BangumiAPI:
|
||||
def __init__(self):
|
||||
self.search_url = lambda e: \
|
||||
f"https://api.bgm.tv/search/subject/{e}?type=2"
|
||||
self.info_url = lambda e: \
|
||||
f"https://api.bgm.tv/subject/{e}"
|
||||
self._request = RequestContent()
|
||||
|
||||
def search(self, title):
|
||||
url = self.search_url(title)
|
||||
contents = self._request.get_json(url)["list"]
|
||||
if contents.__len__() == 0:
|
||||
return None
|
||||
return contents[0]["name"], contents[0]["name_cn"]
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
BGM = BangumiAPI()
|
||||
print(BGM.search("辉夜大小姐"))
|
||||
@@ -85,7 +85,7 @@ class DownloadParser:
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
name = "[Nekomoe kissaten][Summer Time Rendering - 11 [1080p][JPTC].mp4"
|
||||
name = "[Nekomoe kissaten][Summer Time Rendering - 11 [1080p][JPTC][9900E95].mp4"
|
||||
rename = DownloadParser()
|
||||
new_name = rename.rename_pn(name, 1)
|
||||
print(new_name)
|
||||
Reference in New Issue
Block a user