diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml index 70dda3cc..371e4779 100644 --- a/.github/release-drafter.yml +++ b/.github/release-drafter.yml @@ -1,44 +1,32 @@ -# Configuration for Release Drafter: https://github.com/toolmantim/release-drafter -name-template: 'v$NEXT_PATCH_VERSION 🌈' -tag-template: 'v$NEXT_PATCH_VERSION' -version-template: $MAJOR.$MINOR.$PATCH -# Emoji reference: https://gitmoji.carloscuesta.me/ +name-template: 'v$RESOLVED_VERSION 🌈' +tag-template: 'v$RESOLVED_VERSION' categories: - title: '🚀 Features' labels: - 'feature' - 'enhancement' - - 'kind/feature' + - 'new' - title: '🐛 Bug Fixes' labels: - 'fix' - 'bugfix' - 'bug' - - 'regression' - - 'kind/bug' - - title: 📝 Documentation updates + - title: '🧰 Maintenance' + label: 'chore' +change-template: '- $TITLE @$AUTHOR (#$NUMBER)' +change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks. +version-resolver: + major: labels: - - documentation - - 'kind/doc' - - title: 👻 Maintenance + - 'major' + minor: labels: - - chore - - dependencies - - 'kind/chore' - - 'kind/dep' - - title: 🚦 Tests + - 'minor' + patch: labels: - - test - - tests -exclude-labels: - - reverted - - no-changelog - - skip-changelog - - invalid -change-template: '* $TITLE (#$NUMBER) @$AUTHOR' + - 'patch' + default: patch template: | - ## What’s Changed - $CHANGES -Terms -Privacy -Security \ No newline at end of file + ## Changes + + $CHANGES \ No newline at end of file diff --git a/.github/workflows/dev-latest.yml b/.github/workflows/dev-latest.yml index aa9d8b25..3206e8d3 100644 --- a/.github/workflows/dev-latest.yml +++ b/.github/workflows/dev-latest.yml @@ -6,8 +6,27 @@ on: - '\d+\.\d+\.\d+-beta(?:\d+)?' jobs: - latest: + test: runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Python 3.11 + uses: actions/setup-python@v3 + with: + python-version: "3.11" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + pip install pytest + - name: Test + working-directory: ./src + run: | + pytest + + dev-latest: + runs-on: ubuntu-latest + needs: [test] steps: - name: Checkout uses: actions/checkout@v3 diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 17fd295d..516d235a 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -26,7 +26,7 @@ jobs: pytest - docker: + build: runs-on: ubuntu-latest needs: [test] steps: diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml deleted file mode 100644 index e92b1304..00000000 --- a/.github/workflows/release-drafter.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Release Drafter - -on: - pull_request: - - -permissions: - contents: read - - -jobs: - update_release_draft: - permissions: - contents: write # for release-drafter/release-drafter to create a github release - pull-requests: write # for release-drafter/release-drafter to add label to PR - runs-on: ubuntu-latest - steps: - - uses: release-drafter/release-drafter@v5 - env: - GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..536c8ea7 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,26 @@ +name: Generate Release Draft + +on: + pull_request: + types: + - closed + branches: + - main + +jobs: + generate_release_draft: + runs-on: ubuntu-latest + if: github.event.pull_request.merged == true + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Generate Release Draft + uses: actions/create-release@v1 + with: + tag_name: ${{ github.event.pull_request.title }} + release_name: ${{ github.event.pull_request.title }}🌟 + body: ${{ github.event.pull_request.body }} + draft: false + prerelease: false + env: + GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/telegram-bot.yml b/.github/workflows/telegram-bot.yml new file mode 100644 index 00000000..771d2eb1 --- /dev/null +++ b/.github/workflows/telegram-bot.yml @@ -0,0 +1,17 @@ +name: telegram message +on: + - release +jobs: + + build: + name: Build + runs-on: ubuntu-latest + steps: + - name: send telegram message on push + uses: appleboy/telegram-action@master + with: + to: ${{ secrets.TELEGRAM_TO }} + token: ${{ secrets.TELEGRAM_TOKEN }} + message: | + New release: ${{ github.event.release.tag_name }} + Link: ${{ github.event.release.html_url }} \ No newline at end of file diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml deleted file mode 100644 index 93f9a94c..00000000 --- a/.github/workflows/unittest.yml +++ /dev/null @@ -1,32 +0,0 @@ -# This workflow will install Python dependencies, run tests and lint with a single version of Python -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions - -name: unittest - -on: - push: - pull_request: - -permissions: - contents: read - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - name: Set up Python 3.11 - uses: actions/setup-python@v3 - with: - python-version: "3.11" - - name: Install dependencies - run: | - python -m pip install --upgrade pip - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - pip install pytest - - name: Test - working-directory: ./src - run: | - pytest \ No newline at end of file diff --git a/src/main.py b/src/main.py index 435389d2..bcb2b773 100644 --- a/src/main.py +++ b/src/main.py @@ -19,6 +19,19 @@ logger = logging.getLogger(__name__) main_process = multiprocessing.Process(target=app.run, args=(settings,)) +@router.on_event("startup") +async def startup(): + global main_process + main_process.start() + + +@router.on_event("shutdown") +async def shutdown(): + global main_process + if main_process.is_alive(): + os.kill(main_process.pid, signal.SIGTERM) + + @router.get("/api/v1/restart", tags=["program"]) async def restart(): global main_process @@ -85,6 +98,5 @@ else: if __name__ == "__main__": log_config = uvicorn.config.LOGGING_CONFIG log_config["formatters"]["default"]["fmt"] = "[%(asctime)s] %(levelname)-8s %(message)s" - main_process.start() uvicorn.run(router, host="0.0.0.0", port=settings.program.webui_port, log_config=log_config) diff --git a/src/module/api.py b/src/module/api.py index 48c66129..9d80015c 100644 --- a/src/module/api.py +++ b/src/module/api.py @@ -15,15 +15,6 @@ router = FastAPI() api_func = APIProcess(settings) -@router.on_event("startup") -async def startup_event(): - logger = logging.getLogger("uvicorn.access") - handler = logging.StreamHandler() - handler.setLevel(logging.INFO) - handler.setFormatter(logging.Formatter("[%(asctime)s] %(levelname)-8s %(message)s")) - logger.addHandler(handler) - - @router.get("/api/v1/data", tags=["info"]) async def get_data(): try: diff --git a/src/module/manager/renamer.py b/src/module/manager/renamer.py index 04f68936..c5dedc12 100644 --- a/src/module/manager/renamer.py +++ b/src/module/manager/renamer.py @@ -57,7 +57,7 @@ class Renamer: if compare_name != new_path: try: self._client.rename_torrent_file(_hash=info.hash, old_path=media_path, new_path=new_path) - self._notification.send_msg(bangumi_name, "最新剧集已经更新,已自动重命名。") + self._notification.send_msg(bangumi_name, f"{new_path}已经更新,已自动重命名。") except Exception as e: logger.warning(f"{torrent_name} rename failed") logger.warning(f"Season name: {bangumi_name}, Season: {season}, Suffix: {suffix}") @@ -72,7 +72,7 @@ class Renamer: if path_len <= 2: suffix = os.path.splitext(media_path)[-1] torrent_name = self.get_file_name(media_path) - new_name = self._renamer.torrent_parser( + new_name, episode = self._renamer.torrent_parser( torrent_name=torrent_name, bangumi_name=bangumi_name, season=season, diff --git a/src/module/parser/analyser/raw_parser.py b/src/module/parser/analyser/raw_parser.py index 68b8eb8f..af89cfe5 100644 --- a/src/module/parser/analyser/raw_parser.py +++ b/src/module/parser/analyser/raw_parser.py @@ -7,7 +7,7 @@ logger = logging.getLogger(__name__) EPISODE_RE = re.compile(r"\d+") TITLE_RE = re.compile( - r"(.*|\[.*])( -? \d+|\[\d+]|\[\d+.?[vV]\d]|[ 第]?\d+[话話集]|\[\d+.?END]|[Ee][Pp]?\d+)(.*)" + r"(.*|\[.*])( -? \d+|\[\d+]|\[\d+.?[vV]\d]|第\d+[话話集]|\[第?\d+[话話集]]|\[\d+.?END]|[Ee][Pp]?\d+)(.*)" ) RESOLUTION_RE = re.compile(r"1080|720|2160|4K") SOURCE_RE = re.compile(r"B-Global|[Bb]aha|[Bb]ilibili|AT-X|Web") @@ -41,6 +41,10 @@ def prefix_process(raw: str, group: str) -> str: raw = re.sub(f".{group}.", "", raw) raw_process = PREFIX_RE.sub("/", raw) arg_group = raw_process.split("/") + while "" in arg_group: + arg_group.remove("") + if len(arg_group) == 1: + arg_group = arg_group[0].split(" ") for arg in arg_group: if re.search(r"新番|月?番", arg) and len(arg) <= 5: raw = re.sub(f".{arg}.", "", raw) @@ -123,6 +127,7 @@ def clean_sub(sub: str | None) -> str | None: return sub return re.sub(r"_MP4|_MKV", "", sub) + def process(raw_title: str): raw_title = raw_title.strip() content_title = pre_process(raw_title) @@ -163,5 +168,9 @@ def raw_parser(raw: str) -> Episode | None: return Episode(name_en, name_zh, name_jp, season, sr, episode, sub, group, dpi, source) +if __name__ == '__main__': + title = "【幻樱字幕组】【4月新番】【古见同学有交流障碍症 第二季 Komi-san wa, Komyushou Desu. S02】【22】【GB_MP4】【1920X1080】" + ep = raw_parser(title) + print(ep) diff --git a/src/module/parser/analyser/torrent_parser.py b/src/module/parser/analyser/torrent_parser.py index 0b96b7dd..e6a05165 100644 --- a/src/module/parser/analyser/torrent_parser.py +++ b/src/module/parser/analyser/torrent_parser.py @@ -44,8 +44,9 @@ def rename_normal(info: DownloadInfo): for rule in RULES: match_obj = re.match(rule, info.name, re.I) if match_obj is not None: + episode = match_obj.group(2) title = re.sub(r"([Ss]|Season )\d{1,3}", "", match_obj.group(1)).strip() - new_name = f"{title} S{info.season}E{match_obj.group(2)}{match_obj.group(3)}" + new_name = f"{title} S{info.season}E{episode}{match_obj.group(3)}" return new_name @@ -55,10 +56,11 @@ def rename_pn(info: DownloadInfo): if match_obj is not None: title = re.sub(r"([Ss]|Season )\d{1,3}", "", match_obj.group(1)).strip() title = title if title != "" else info.folder_name + episode = match_obj.group(2) new_name = re.sub( r"[\[\]]", "", - f"{title} S{info.season}E{match_obj.group(2)}{info.suffix}", + f"{title} S{info.season}E{episode}{info.suffix}", ) return new_name @@ -67,10 +69,11 @@ def rename_advance(info: DownloadInfo): for rule in RULES: match_obj = re.match(rule, info.file_name, re.I) if match_obj is not None: + episode = match_obj.group(2) new_name = re.sub( r"[\[\]]", "", - f"{info.folder_name} S{info.season}E{match_obj.group(2)}{info.suffix}", + f"{info.folder_name} S{info.season}E{episode}{info.suffix}", ) return new_name @@ -80,10 +83,11 @@ def rename_no_season_pn(info: DownloadInfo): match_obj = re.match(rule, info.file_name, re.I) if match_obj is not None: title = match_obj.group(1).strip() + episode = match_obj.group(2) new_name = re.sub( r"[\[\]]", "", - f"{title} E{match_obj.group(2)}{info.suffix}", + f"{title} E{episode}{info.suffix}", ) return new_name diff --git a/src/test/test_raw_parser.py b/src/test/test_raw_parser.py index 2d619df1..b4c3b446 100644 --- a/src/test/test_raw_parser.py +++ b/src/test/test_raw_parser.py @@ -46,7 +46,8 @@ def test_raw_parser(): content = "[织梦字幕组][尼尔:机械纪元 NieR Automata Ver1.1a][02集][1080P][AVC][简日双语]" info = raw_parser(content) assert info.group == "织梦字幕组" - assert info.title_zh == "尼尔:机械纪元 NieR Automata Ver1.1a" + assert info.title_zh == "尼尔:机械纪元" + assert info.title_en == "NieR Automata Ver1.1a" assert info.resolution == "1080P" assert info.episode == 2 assert info.season == 1 @@ -59,3 +60,12 @@ def test_raw_parser(): assert info.resolution == "1080p" assert info.episode == 33 assert info.season == 1 + + content = "【极影字幕社】★4月新番 天国大魔境 Tengoku Daimakyou 第05话 GB 720P MP4(字幕社招人内详)" + info = raw_parser(content) + assert info.group == "极影字幕社" + assert info.title_zh == "天国大魔境" + assert info.title_en == "Tengoku Daimakyou" + assert info.resolution == "720P" + assert info.episode == 5 + assert info.season == 1 diff --git a/src/test/test_torrent_parser.py b/src/test/test_torrent_parser.py index aa710e41..a61c96dd 100644 --- a/src/test/test_torrent_parser.py +++ b/src/test/test_torrent_parser.py @@ -10,7 +10,6 @@ def test_torrent_parser(): assert torrent_parser(file_name, folder_name, season, suffix, "advance") == "我内心的糟糕念头(2023) S01E01.mp4" assert torrent_parser(file_name, folder_name, season, suffix, "none") == "[Lilith-Raws] Boku no Kokoro no Yabai Yatsu - 01 [Baha][WEB-DL][1080p][AVC AAC][CHT][MP4].mp4" - file_name = "[Sakurato] Tonikaku Kawaii S2 [01][AVC-8bit 1080p AAC][CHS].mp4" folder_name = "总之就是非常可爱(2021)" season = 2 @@ -44,4 +43,4 @@ def test_torrent_parser(): season = 1 suffix = ".mp4" assert torrent_parser(file_name, folder_name, season, suffix, "pn") == "海盗战记 S01E01.mp4" - assert torrent_parser(file_name, folder_name, season, suffix, "advance") == "海盗战记(2021) S01E01.mp4" \ No newline at end of file + assert torrent_parser(file_name, folder_name, season, suffix, "advance") == "海盗战记(2021) S01E01.mp4"