Skip to content

Commit

Permalink
Merge pull request #362 from EstrellaXD/3.0-dev
Browse files Browse the repository at this point in the history
3.0.9
  • Loading branch information
EstrellaXD authored Jun 30, 2023
2 parents 06684a0 + a287b58 commit daeb040
Show file tree
Hide file tree
Showing 107 changed files with 272 additions and 131 deletions.
8 changes: 4 additions & 4 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ coverage.xml
../.pytest_cache
.hypothesis

src/module/tests
src/module/conf/const_dev.py
backend/src/module/tests
backend/src/module/conf/const_dev.py
config/bangumi.json/config/bangumi.json
/docs
/.github
Expand All @@ -33,8 +33,8 @@ config/bangumi.json/config/bangumi.json
dist.zip
data
config
/src/config
/src/data
/backend/src/config
/backend/src/data
.pytest_cache
test
.env
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: 问题反馈
description: File a bug report
title: "[错误报告] 请在此处简单描述你的问题"
title: "[错误报告]请在此处简单描述你的问题"
labels: ["bug"]
body:
- type: markdown
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/discussion.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: 项目讨论
description: discussion
title: "[Discussion]: "
title: "[Discussion] "
labels: ["discussion"]
body:
- type: markdown
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature_request.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: 功能改进
description: Feature Request
title: "[Feature Request]: "
title: "[Feature Request]"
labels: ["feature request"]
body:
- type: markdown
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/rfc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

name: 功能提案
description: Request for Comments
title: "[RFC]: "
title: "[RFC]"
labels: ["RFC"]
body:
- type: markdown
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pip install pytest
- name: Test
working-directory: ./src
working-directory: ./backend/src
run: |
mkdir -p config
pytest
Expand All @@ -35,7 +35,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v3
- name: Create Version info
working-directory: ./src
working-directory: ./backend/src
run: |
echo "VERSION = '$GITHUB_REF_NAME'" > module/__version__.py
Expand Down
20 changes: 10 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,18 @@ cython_debug/
#.idea/

# Custom
/src/test.py
/backend/src/test.py

/src/module/run_debug.sh
/src/module/debug_run.sh
/src/module/__version__.py
/src/data/
/backend/src/module/run_debug.sh
/backend/src/module/debug_run.sh
/backend/src/module/__version__.py
/backend/src/data/

/src/module/conf/config_dev.ini
/backend/src/module/conf/config_dev.ini

test.*
.run
/src/templates/
/src/config/
/src/debuger.py
/src/dist.zip
/backend/src/templates/
/backend/src/config/
/backend/src/debuger.py
/backend/src/dist.zip
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ RUN apk add --no-cache \
/root/.cache \
/tmp/*

COPY --chmod=755 src/. .
COPY --chmod=755 src/docker /
COPY --chmod=755 backend/src/. .
COPY --chmod=755 backend/src/docker /

ENTRYPOINT [ "/init" ]

Expand Down
8 changes: 8 additions & 0 deletions backend/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
repos:
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
language: python

# TODO: add ruff lint check before committing
63 changes: 63 additions & 0 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
[tool.ruff]
select = [
# pycodestyle(E): https://beta.ruff.rs/docs/rules/#pycodestyle-e-w
"E",
# Pyflakes(F): https://beta.ruff.rs/docs/rules/#pyflakes-f
"F",
# isort(I): https://beta.ruff.rs/docs/rules/#isort-i
"I"
]
ignore = [
# E501: https://beta.ruff.rs/docs/rules/line-too-long/
'E501',
# F401: https://beta.ruff.rs/docs/rules/unused-import/
# avoid unused imports lint in `__init__.py`
'F401',
]

# Allow autofix for all enabled rules (when `--fix`) is provided.
fixable = ["A", "B", "C", "D", "E", "F", "G", "I", "N", "Q", "S", "T", "W", "ANN", "ARG", "BLE", "COM", "DJ", "DTZ", "EM", "ERA", "EXE", "FBT", "ICN", "INP", "ISC", "NPY", "PD", "PGH", "PIE", "PL", "PT", "PTH", "PYI", "RET", "RSE", "RUF", "SIM", "SLF", "TCH", "TID", "TRY", "UP", "YTT"]
unfixable = []

# Exclude a variety of commonly ignored directories.
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".mypy_cache",
".nox",
".pants.d",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"venv",
]
per-file-ignores = {}

# Same as Black.
line-length = 88

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

# Assume Python 3.10.
target-version = "py310"

[tool.ruff.mccabe]
# Unlike Flake8, default to a complexity level of 10.
max-complexity = 10

[tool.black]
line-length = 88
target-version = ['py310', 'py311']
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ def locked(func):
def wrapper(*args, **kwargs):
with lock:
return func(*args, **kwargs)
return wrapper

return wrapper
File renamed without changes.
9 changes: 2 additions & 7 deletions src/module/api/auth.py → backend/src/module/api/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ async def login(form_data: OAuth2PasswordRequestForm = Depends()):
username = form_data.username
password = form_data.password
auth_user(username, password)
token = create_access_token(
data={"sub": username}, expires_delta=timedelta(days=1)
)
token = create_access_token(data={"sub": username}, expires_delta=timedelta(days=1))

return {"access_token": token, "token_type": "bearer", "expire": 86400}

Expand All @@ -32,10 +30,7 @@ async def refresh(current_user: User = Depends(get_current_user)):
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED, detail="invalid token"
)
token = create_access_token(
data = {"sub": current_user.username}

)
token = create_access_token(data={"sub": current_user.username})
return {"access_token": token, "token_type": "bearer", "expire": 86400}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

logger = logging.getLogger(__name__)


@router.get(
"/api/v1/bangumi/getAll", tags=["bangumi"], response_model=list[BangumiData]
)
Expand Down Expand Up @@ -50,7 +51,9 @@ async def update_rule(data: BangumiData, current_user=Depends(get_current_user))


@router.delete("/api/v1/bangumi/deleteRule/{bangumi_id}", tags=["bangumi"])
async def delete_rule(bangumi_id: str, file: bool = False, current_user=Depends(get_current_user)):
async def delete_rule(
bangumi_id: str, file: bool = False, current_user=Depends(get_current_user)
):
if not current_user:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED, detail="invalid token"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def match_poster(self, bangumi_name: str) -> str:
data = self._cursor.execute(
"""
SELECT poster_link FROM bangumi
WHERE INSTR(official_title, :official_title) > 0
WHERE INSTR(:official_title, official_title) > 0
""",
{"official_title": bangumi_name},
).fetchone()
Expand Down Expand Up @@ -160,9 +160,13 @@ def match_list(self, torrent_list: list, rss_link: str) -> list:
if match_data.get("title_raw") in torrent.name:
if rss_link not in match_data.get("rss_link"):
match_data["rss_link"] += f",{rss_link}"
self.update_rss(match_data.get("title_raw"), match_data.get("rss_link"))
self.update_rss(
match_data.get("title_raw"), match_data.get("rss_link")
)
if not match_data.get("poster_link"):
self.update_poster(match_data.get("title_raw"), torrent.poster_link)
self.update_poster(
match_data.get("title_raw"), torrent.poster_link
)
torrent_list.pop(i)
break
else:
Expand Down Expand Up @@ -217,7 +221,7 @@ def __check_list_exist(self, data_list: list[BangumiData]):
return False


if __name__ == '__main__':
if __name__ == "__main__":
with BangumiDatabase() as db:
name = "久保"
print(db.match_poster(name))
name = "久保同学不放过我(2023)"
print(db.match_poster(name))
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,14 @@ def _delete_all(self, table_name: str):

def _delete(self, table_name: str, condition: dict):
condition_sql = " AND ".join([f"{key} = :{key}" for key in condition.keys()])
self._cursor.execute(f"DELETE FROM {table_name} WHERE {condition_sql}", condition)
self._cursor.execute(
f"DELETE FROM {table_name} WHERE {condition_sql}", condition
)
self._conn.commit()

def _search(self, table_name: str, keys: list[str] | None = None, condition: dict = None):
def _search(
self, table_name: str, keys: list[str] | None = None, condition: dict = None
):
if keys is None:
select_sql = "*"
else:
Expand All @@ -112,20 +116,25 @@ def _search(self, table_name: str, keys: list[str] | None = None, condition: dic
self._cursor.execute(f"SELECT {select_sql} FROM {table_name}")
else:
custom_condition = condition.pop("_custom_condition", None)
condition_sql = " AND ".join([f"{key} = :{key}" for key in condition.keys()]) + (
f" AND {custom_condition}" if custom_condition else ""
)
condition_sql = " AND ".join(
[f"{key} = :{key}" for key in condition.keys()]
) + (f" AND {custom_condition}" if custom_condition else "")
self._cursor.execute(
f"SELECT {select_sql} FROM {table_name} WHERE {condition_sql}", condition
f"SELECT {select_sql} FROM {table_name} WHERE {condition_sql}",
condition,
)

def _search_data(self, table_name: str, keys: list[str] | None = None, condition: dict = None) -> dict:
def _search_data(
self, table_name: str, keys: list[str] | None = None, condition: dict = None
) -> dict:
if keys is None:
keys = self.__get_table_columns(table_name)
self._search(table_name, keys, condition)
return dict(zip(keys, self._cursor.fetchone()))

def _search_datas(self, table_name: str, keys: list[str] | None = None, condition: dict = None) -> list[dict]:
def _search_datas(
self, table_name: str, keys: list[str] | None = None, condition: dict = None
) -> list[dict]:
if keys is None:
keys = self.__get_table_columns(table_name)
self._search(table_name, keys, condition)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ def add_category(self, category):

@qb_connect_failed_wait
def torrents_info(self, status_filter, category, tag=None):
return self._client.torrents_info(status_filter=status_filter, category=category, tag=tag)
return self._client.torrents_info(
status_filter=status_filter, category=category, tag=tag
)

def torrents_add(self, urls, save_path, category, torrent_files=None):
resp = self._client.torrents_add(
Expand All @@ -87,7 +89,7 @@ def torrents_add(self, urls, save_path, category, torrent_files=None):
torrent_files=torrent_files,
save_path=save_path,
category=category,
use_auto_torrent_management=False
use_auto_torrent_management=False,
)
return resp == "Ok."

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ def set_rules(self, bangumi_info: list[BangumiData]):
logger.debug("[Downloader] Finished.")

def get_torrent_info(self, category="Bangumi", status_filter="completed", tag=None):
return self.client.torrents_info(status_filter=status_filter, category=category, tag=tag)
return self.client.torrents_info(
status_filter=status_filter, category=category, tag=tag
)

def rename_torrent_file(self, _hash, old_path, new_path) -> bool:
logger.info(f"{old_path} >> {new_path}")
Expand All @@ -116,7 +118,7 @@ def add_torrent(self, torrent: dict):
urls=torrent.get("urls"),
torrent_files=torrent.get("torrent_files"),
save_path=torrent.get("save_path"),
category="Bangumi"
category="Bangumi",
):
logger.debug(f"[Downloader] Add torrent: {torrent.get('save_path')}")
return True
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ def collect_season(self, data: BangumiData, link: str = None, proxy: bool = Fals
torrents = st.get_torrents(link, _filter="|".join(data.filter))
torrent_files = None
if proxy:
torrent_files = [st.get_content(torrent.torrent_link) for torrent in torrents]
return self.add_season_torrents(data=data, torrents=torrents, torrent_files=torrent_files)
torrent_files = [
st.get_content(torrent.torrent_link) for torrent in torrents
]
return self.add_season_torrents(
data=data, torrents=torrents, torrent_files=torrent_files
)

def subscribe_season(self, data: BangumiData):
with BangumiDatabase() as db:
Expand All @@ -57,5 +61,3 @@ def eps_complete():
sc.collect_season(data)
data.eps_collect = True
bd.update_list(datas)


Loading

0 comments on commit daeb040

Please sign in to comment.