Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support more namings and subtitles #12

Merged
merged 2 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
version: 2
updates:
- package-ecosystem: github-actions
directory: /
labels:
- dependabot
- actions
schedule:
interval: daily
groups:
action-dependencies:
patterns:
- '*'
commit-message:
prefix: 'build'
53 changes: 53 additions & 0 deletions .github/workflows/check-code.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
name: Checks
on:
Fixed Show fixed Hide fixed
pull_request:
paths:
- '**.py*'
- '.github/workflows/check-code.yml'
jobs:
lint:
strategy:
fail-fast: false
matrix:
linter: [
{'name': 'flake8', 'format': 'flake8', 'cwd': '.', 'cmd': 'flake8 .'},
{'name': 'mypy', 'format': 'mypy', 'cwd': '.', 'cmd': 'mypy .'},
{'name': 'pylint', 'format': 'pylint', 'cwd': '.', 'cmd': 'pylint --load-plugins pylint_pytest $(Get-ChildItem -Filter *.py -Recurse .)'},
Fixed Show fixed Hide fixed
]
name: ${{ matrix.linter.name }}
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install Python dependencies
run: python -m pip install -r dev-requirements.txt
- name: Lint
run: cd ${{ matrix.linter.cwd }}; ${{ matrix.linter.cmd }} > lint.log
- name: Convert
uses: bugale/bugalint@v2
if: always()
with:
inputFile: 'lint.log'
toolName: ${{ matrix.linter.name }}
inputFormat: ${{ matrix.linter.format }}
- name: Upload results
uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: sarif.json
test:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.11'
- uses: FedericoCarboni/setup-ffmpeg@v2
id: setup-ffmpeg
- name: Install test dependencies
run: python -m pip install -r dev-requirements.txt
- name: Test
run: pytest tests
33 changes: 33 additions & 0 deletions .github/workflows/check-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
name: Checks
on:
Fixed Show fixed Hide fixed
pull_request:
paths:
- '**.md'
- '**mdl*'
- '.github/workflows/check-docs.yml'
jobs:
markdownlint:
name: markdownlint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Lint
uses: avto-dev/markdown-lint@v1
with:
args: '**/*.md'
output: 'lint.txt'
config: '.mdl.yml'
- name: Convert
uses: bugale/bugalint@v2
if: always()
with:
inputFile: 'lint.txt'
toolName: 'mdl'
inputFormat: 'mdl'
- name: Upload results
uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: sarif.json
41 changes: 41 additions & 0 deletions .github/workflows/check-general.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
name: Checks
on:
Fixed Show fixed Hide fixed
- pull_request
jobs:
required:
name: Required Checks
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: bugale/bugroup-checks@v1
with:
checks: |-
Check .*
.*[lL]int.*
self: Required Checks
check-commits:
name: Check Commits
runs-on: ubuntu-latest
steps:
- name: Install Dependencies
run: npm install -g @commitlint/cli @commitlint/config-conventional conventional-changelog-conventionalcommits
Fixed Show fixed Hide fixed
- name: Get Base
id: get-base
run: |-
count=$(gh api "/repos/${{ github.repository }}/pulls/${{ github.event.number }}/commits" --jq "length")
Fixed Show fixed Hide fixed
req=$(($count + 1))
echo "count: $count, req: $req"
echo "commit-count=$count" >> $GITHUB_OUTPUT
echo "required=$req" >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ github.token }}
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: ${{ steps.get-base.outputs.required }}
ref: ${{ github.event.pull_request.head.sha }}
- name: Check Commits
run: |-
commitlint --from ${{ github.event.pull_request.head.sha }}~${{ steps.get-base.outputs.commit-count }} --to ${{ github.event.pull_request.head.sha }}
27 changes: 27 additions & 0 deletions .github/workflows/check-yml.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
name: Checks
on:
Fixed Show fixed Hide fixed
pull_request:
paths:
- '**.yml'
jobs:
yamllint:
name: yamllint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: yamllint
run: yamllint --strict -f parsable . > lint.txt
- name: Convert
uses: bugale/bugalint@v2
if: always()
with:
inputFile: 'lint.txt'
toolName: 'yamllint'
inputFormat: 'yamllint'
- name: Upload results
uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: sarif.json
18 changes: 18 additions & 0 deletions .github/workflows/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
name: Dependabot
on:
Fixed Show fixed Hide fixed
- pull_request
permissions: write-all
jobs:
auto-merge:
name: Auto-merge
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' }}
steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v1
- name: Enable auto-merge for Dependabot PRs
run: gh pr merge --auto --rebase "${{github.event.pull_request.html_url}}"
Fixed Show fixed Hide fixed
env:
GH_TOKEN: ${{ github.token }}
37 changes: 0 additions & 37 deletions .github/workflows/lint.yml

This file was deleted.

23 changes: 0 additions & 23 deletions .github/workflows/test.yml

This file was deleted.

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
**\__pycache__
**/__pycache__
.vscode/launch.json
5 changes: 5 additions & 0 deletions .mdl.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
# MD013/line-length - Line length
MD013:
line_length: 160
ignore_code_blocks: true
10 changes: 10 additions & 0 deletions .yamllint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
extends: default
ignore:
- 'node_modules/**'
rules:
new-lines: disable
truthy:
check-keys: false
line-length:
max: 160
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Buganime

My personal Anime organizer, that upscales your anime to 4K, burns the subtitles, leaves only Japanese audio, and organizes it in a Plex-friendly tree.
4 changes: 3 additions & 1 deletion buganime/buganime.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ def _get_subtitle_stream_index() -> int:
if all(x not in stream['tags'].get('title', '').upper() for x in ('S&S', 'SIGNS', 'FORCED')):
relevant_streams.append((i, stream))
if not relevant_streams:
if len(subtitle_streams) == 1:
return 0
raise RuntimeError('No English subtitle stream found')
if len(relevant_streams) == 1:
return relevant_streams[0][0]
Expand Down Expand Up @@ -155,7 +157,7 @@ def process_path(input_path: str) -> None:

def main(args: list[str]) -> int:
if len(args) != 1:
print("Usage: buganime.py <input_path>")
print('Usage: buganime.py <input_path>')
return 1

input_path = args[0]
Expand Down
6 changes: 3 additions & 3 deletions buganime/transcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __init__(self, input_path: str, output_path: str, height_out: int, video_inf
self.__input_path, self.__output_path = input_path, output_path
self.__video_info = video_info
self.__height_out = height_out
self.__width_out = int(self.__video_info.width * self.__height_out / self.__video_info.height)
self.__width_out = round(self.__video_info.width * self.__height_out / self.__video_info.height)
model = Transcoder.Module(num_in_ch=3, num_out_ch=3, num_feat=64, num_conv=16, upscale=4)
model.load_state_dict(torch.load(MODEL_PATH)['params'], strict=True)
self.__model = model.eval().cuda().half()
Expand Down Expand Up @@ -104,8 +104,8 @@ async def __write_output_frames(self, frames: AsyncIterator[bytes]) -> None:
def __gpu_upscale(self, frame: torch.Tensor) -> torch.Tensor:
with torch.no_grad():
frame_float = frame.cuda().permute(2, 0, 1).half() / 255
frame_upscaled_float = cast(torch.Tensor, self.__model(frame_float.unsqueeze(0)).data).squeeze().clamp_(0, 1)
return (frame_upscaled_float * 255.0).round().byte().permute(1, 2, 0).cpu()
frame_upscaled_float = self.__model(frame_float.unsqueeze(0)).data.squeeze().clamp_(0, 1)
return cast(torch.Tensor, (frame_upscaled_float * 255.0).round().byte().permute(1, 2, 0).cpu())

async def __upscale_frame(self, frame: bytes) -> bytes:
if self.__video_info.height == self.__height_out:
Expand Down
6 changes: 6 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
'body-max-line-length': [0, 'always', 10000]
}
}
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pytest
pylint
pylint-pytest
flake8
flake8-quotes
mypy
tqdm-stubs
types-retry
Expand Down
Loading
Loading