From 331a1b715b132ec93b6fddcc0f492220196f2a17 Mon Sep 17 00:00:00 2001 From: Bugale Bugalit Date: Thu, 13 Jul 2023 21:05:12 +0300 Subject: [PATCH 1/2] feat: support more namings and subtitles --- .gitignore | 3 +- buganime/buganime.py | 2 + buganime/transcode.py | 2 +- tests/data/6.json | 806 +++++++++++++++++++++++++++++++++++++++++ tests/test_buganime.py | 1 + 5 files changed, 812 insertions(+), 2 deletions(-) create mode 100644 tests/data/6.json diff --git a/.gitignore b/.gitignore index f2ef546..bf12024 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -**\__pycache__ +**/__pycache__ +.vscode/launch.json diff --git a/buganime/buganime.py b/buganime/buganime.py index 061faa6..32a2144 100644 --- a/buganime/buganime.py +++ b/buganime/buganime.py @@ -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] diff --git a/buganime/transcode.py b/buganime/transcode.py index 555e64b..b5a541d 100644 --- a/buganime/transcode.py +++ b/buganime/transcode.py @@ -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() diff --git a/tests/data/6.json b/tests/data/6.json new file mode 100644 index 0000000..7e96f41 --- /dev/null +++ b/tests/data/6.json @@ -0,0 +1,806 @@ +{ + "streams": [ + { + "index": 0, + "codec_name": "h264", + "codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10", + "profile": "High", + "codec_type": "video", + "codec_tag_string": "[0][0][0][0]", + "codec_tag": "0x0000", + "width": 1920, + "height": 1080, + "coded_width": 1920, + "coded_height": 1080, + "closed_captions": 0, + "film_grain": 0, + "has_b_frames": 1, + "sample_aspect_ratio": "1:1", + "display_aspect_ratio": "16:9", + "pix_fmt": "yuv420p", + "level": 40, + "color_range": "tv", + "color_space": "bt709", + "color_transfer": "bt709", + "color_primaries": "bt709", + "chroma_location": "left", + "field_order": "progressive", + "refs": 1, + "is_avc": "true", + "nal_length_size": "4", + "r_frame_rate": "30/1", + "avg_frame_rate": "30/1", + "time_base": "1/1000", + "start_pts": 0, + "start_time": "0.000000", + "bits_per_raw_sample": "8", + "extradata_size": 45, + "disposition": { + "default": 1, + "dub": 0, + "original": 0, + "comment": 0, + "lyrics": 0, + "karaoke": 0, + "forced": 0, + "hearing_impaired": 0, + "visual_impaired": 0, + "clean_effects": 0, + "attached_pic": 0, + "timed_thumbnails": 0, + "captions": 0, + "descriptions": 0, + "metadata": 0, + "dependent": 0, + "still_image": 0 + }, + "tags": { + "BPS": "1280150", + "DURATION": "00:04:07.500000000", + "NUMBER_OF_FRAMES": "7425", + "NUMBER_OF_BYTES": "39604651", + "_STATISTICS_WRITING_APP": "mkvmerge v78.0 ('Running') 64-bit", + "_STATISTICS_WRITING_DATE_UTC": "2024-01-10 15:38:09", + "_STATISTICS_TAGS": "BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES" + } + }, + { + "index": 1, + "codec_name": "aac", + "codec_long_name": "AAC (Advanced Audio Coding)", + "profile": "LC", + "codec_type": "audio", + "codec_tag_string": "[0][0][0][0]", + "codec_tag": "0x0000", + "sample_fmt": "fltp", + "sample_rate": "44100", + "channels": 2, + "channel_layout": "stereo", + "bits_per_sample": 0, + "r_frame_rate": "0/0", + "avg_frame_rate": "0/0", + "time_base": "1/1000", + "start_pts": 0, + "start_time": "0.000000", + "extradata_size": 16, + "disposition": { + "default": 1, + "dub": 0, + "original": 0, + "comment": 0, + "lyrics": 0, + "karaoke": 0, + "forced": 0, + "hearing_impaired": 0, + "visual_impaired": 0, + "clean_effects": 0, + "attached_pic": 0, + "timed_thumbnails": 0, + "captions": 0, + "descriptions": 0, + "metadata": 0, + "dependent": 0, + "still_image": 0 + }, + "tags": { + "language": "jpn", + "BPS": "128016", + "DURATION": "00:04:07.548000000", + "NUMBER_OF_FRAMES": "10661", + "NUMBER_OF_BYTES": "3961275", + "_STATISTICS_WRITING_APP": "mkvmerge v78.0 ('Running') 64-bit", + "_STATISTICS_WRITING_DATE_UTC": "2024-01-10 15:38:09", + "_STATISTICS_TAGS": "BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES" + } + }, + { + "index": 2, + "codec_name": "ass", + "codec_long_name": "ASS (Advanced SSA) subtitle", + "codec_type": "subtitle", + "codec_tag_string": "[0][0][0][0]", + "codec_tag": "0x0000", + "r_frame_rate": "0/0", + "avg_frame_rate": "0/0", + "time_base": "1/1000", + "start_pts": 4010, + "start_time": "4.010000", + "extradata_size": 2070, + "disposition": { + "default": 1, + "dub": 0, + "original": 0, + "comment": 0, + "lyrics": 0, + "karaoke": 0, + "forced": 0, + "hearing_impaired": 0, + "visual_impaired": 0, + "clean_effects": 0, + "attached_pic": 0, + "timed_thumbnails": 0, + "captions": 0, + "descriptions": 0, + "metadata": 0, + "dependent": 0, + "still_image": 0 + }, + "tags": { + "language": "jpn", + "BPS": "324", + "DURATION": "00:03:55.940000000", + "NUMBER_OF_FRAMES": "97", + "NUMBER_OF_BYTES": "9577", + "_STATISTICS_WRITING_APP": "mkvmerge v78.0 ('Running') 64-bit", + "_STATISTICS_WRITING_DATE_UTC": "2024-01-10 15:38:09", + "_STATISTICS_TAGS": "BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES" + } + }, + { + "index": 3, + "codec_type": "attachment", + "codec_tag_string": "[0][0][0][0]", + "codec_tag": "0x0000", + "r_frame_rate": "0/0", + "avg_frame_rate": "0/0", + "time_base": "1/90000", + "start_pts": 0, + "start_time": "0.000000", + "duration_ts": 22279320, + "duration": "247.548000", + "extradata_size": 29932, + "disposition": { + "default": 0, + "dub": 0, + "original": 0, + "comment": 0, + "lyrics": 0, + "karaoke": 0, + "forced": 0, + "hearing_impaired": 0, + "visual_impaired": 0, + "clean_effects": 0, + "attached_pic": 0, + "timed_thumbnails": 0, + "captions": 0, + "descriptions": 0, + "metadata": 0, + "dependent": 0, + "still_image": 0 + }, + "tags": { + "filename": "Blambot Pro Lite.ttf", + "mimetype": "font/ttf" + } + }, + { + "index": 4, + "codec_type": "attachment", + "codec_tag_string": "[0][0][0][0]", + "codec_tag": "0x0000", + "r_frame_rate": "0/0", + "avg_frame_rate": "0/0", + "time_base": "1/90000", + "start_pts": 0, + "start_time": "0.000000", + "duration_ts": 22279320, + "duration": "247.548000", + "extradata_size": 62188, + "disposition": { + "default": 0, + "dub": 0, + "original": 0, + "comment": 0, + "lyrics": 0, + "karaoke": 0, + "forced": 0, + "hearing_impaired": 0, + "visual_impaired": 0, + "clean_effects": 0, + "attached_pic": 0, + "timed_thumbnails": 0, + "captions": 0, + "descriptions": 0, + "metadata": 0, + "dependent": 0, + "still_image": 0 + }, + "tags": { + "filename": "Cabin-PL-Bold.ttf", + "mimetype": "font/ttf" + } + }, + { + "index": 5, + "codec_type": "attachment", + "codec_tag_string": "[0][0][0][0]", + "codec_tag": "0x0000", + "r_frame_rate": "0/0", + "avg_frame_rate": "0/0", + "time_base": "1/90000", + "start_pts": 0, + "start_time": "0.000000", + "duration_ts": 22279320, + "duration": "247.548000", + "extradata_size": 60880, + "disposition": { + "default": 0, + "dub": 0, + "original": 0, + "comment": 0, + "lyrics": 0, + "karaoke": 0, + "forced": 0, + "hearing_impaired": 0, + "visual_impaired": 0, + "clean_effects": 0, + "attached_pic": 0, + "timed_thumbnails": 0, + "captions": 0, + "descriptions": 0, + "metadata": 0, + "dependent": 0, + "still_image": 0 + }, + "tags": { + "filename": "Cabin-PL-BoldItalic.ttf", + "mimetype": "font/ttf" + } + }, + { + "index": 6, + "codec_type": "attachment", + "codec_tag_string": "[0][0][0][0]", + "codec_tag": "0x0000", + "r_frame_rate": "0/0", + "avg_frame_rate": "0/0", + "time_base": "1/90000", + "start_pts": 0, + "start_time": "0.000000", + "duration_ts": 22279320, + "duration": "247.548000", + "extradata_size": 43752, + "disposition": { + "default": 0, + "dub": 0, + "original": 0, + "comment": 0, + "lyrics": 0, + "karaoke": 0, + "forced": 0, + "hearing_impaired": 0, + "visual_impaired": 0, + "clean_effects": 0, + "attached_pic": 0, + "timed_thumbnails": 0, + "captions": 0, + "descriptions": 0, + "metadata": 0, + "dependent": 0, + "still_image": 0 + }, + "tags": { + "filename": "CFGreenMonster-Regular.ttf", + "mimetype": "font/ttf" + } + }, + { + "index": 7, + "codec_type": "attachment", + "codec_tag_string": "[0][0][0][0]", + "codec_tag": "0x0000", + "r_frame_rate": "0/0", + "avg_frame_rate": "0/0", + "time_base": "1/90000", + "start_pts": 0, + "start_time": "0.000000", + "duration_ts": 22279320, + "duration": "247.548000", + "extradata_size": 146268, + "disposition": { + "default": 0, + "dub": 0, + "original": 0, + "comment": 0, + "lyrics": 0, + "karaoke": 0, + "forced": 0, + "hearing_impaired": 0, + "visual_impaired": 0, + "clean_effects": 0, + "attached_pic": 0, + "timed_thumbnails": 0, + "captions": 0, + "descriptions": 0, + "metadata": 0, + "dependent": 0, + "still_image": 0 + }, + "tags": { + "filename": "chalkboardse.ttf", + "mimetype": "font/ttf" + } + }, + { + "index": 8, + "codec_type": "attachment", + "codec_tag_string": "[0][0][0][0]", + "codec_tag": "0x0000", + "r_frame_rate": "0/0", + "avg_frame_rate": "0/0", + "time_base": "1/90000", + "start_pts": 0, + "start_time": "0.000000", + "duration_ts": 22279320, + "duration": "247.548000", + "extradata_size": 71788, + "disposition": { + "default": 0, + "dub": 0, + "original": 0, + "comment": 0, + "lyrics": 0, + "karaoke": 0, + "forced": 0, + "hearing_impaired": 0, + "visual_impaired": 0, + "clean_effects": 0, + "attached_pic": 0, + "timed_thumbnails": 0, + "captions": 0, + "descriptions": 0, + "metadata": 0, + "dependent": 0, + "still_image": 0 + }, + "tags": { + "filename": "FetteMikado.ttf", + "mimetype": "font/ttf" + } + }, + { + "index": 9, + "codec_type": "attachment", + "codec_tag_string": "[0][0][0][0]", + "codec_tag": "0x0000", + "r_frame_rate": "0/0", + "avg_frame_rate": "0/0", + "time_base": "1/90000", + "start_pts": 0, + "start_time": "0.000000", + "duration_ts": 22279320, + "duration": "247.548000", + "extradata_size": 124420, + "disposition": { + "default": 0, + "dub": 0, + "original": 0, + "comment": 0, + "lyrics": 0, + "karaoke": 0, + "forced": 0, + "hearing_impaired": 0, + "visual_impaired": 0, + "clean_effects": 0, + "attached_pic": 0, + "timed_thumbnails": 0, + "captions": 0, + "descriptions": 0, + "metadata": 0, + "dependent": 0, + "still_image": 0 + }, + "tags": { + "filename": "Geometos Rounded.ttf", + "mimetype": "font/ttf" + } + }, + { + "index": 10, + "codec_type": "attachment", + "codec_tag_string": "[0][0][0][0]", + "codec_tag": "0x0000", + "r_frame_rate": "0/0", + "avg_frame_rate": "0/0", + "time_base": "1/90000", + "start_pts": 0, + "start_time": "0.000000", + "duration_ts": 22279320, + "duration": "247.548000", + "extradata_size": 154396, + "disposition": { + "default": 0, + "dub": 0, + "original": 0, + "comment": 0, + "lyrics": 0, + "karaoke": 0, + "forced": 0, + "hearing_impaired": 0, + "visual_impaired": 0, + "clean_effects": 0, + "attached_pic": 0, + "timed_thumbnails": 0, + "captions": 0, + "descriptions": 0, + "metadata": 0, + "dependent": 0, + "still_image": 0 + }, + "tags": { + "filename": "HelveticaNeueLTCom-MdCn.ttf", + "mimetype": "font/ttf" + } + }, + { + "index": 11, + "codec_type": "attachment", + "codec_tag_string": "[0][0][0][0]", + "codec_tag": "0x0000", + "r_frame_rate": "0/0", + "avg_frame_rate": "0/0", + "time_base": "1/90000", + "start_pts": 0, + "start_time": "0.000000", + "duration_ts": 22279320, + "duration": "247.548000", + "extradata_size": 26868, + "disposition": { + "default": 0, + "dub": 0, + "original": 0, + "comment": 0, + "lyrics": 0, + "karaoke": 0, + "forced": 0, + "hearing_impaired": 0, + "visual_impaired": 0, + "clean_effects": 0, + "attached_pic": 0, + "timed_thumbnails": 0, + "captions": 0, + "descriptions": 0, + "metadata": 0, + "dependent": 0, + "still_image": 0 + }, + "tags": { + "filename": "Junction-bold.otf", + "mimetype": "font/otf" + } + }, + { + "index": 12, + "codec_type": "attachment", + "codec_tag_string": "[0][0][0][0]", + "codec_tag": "0x0000", + "r_frame_rate": "0/0", + "avg_frame_rate": "0/0", + "time_base": "1/90000", + "start_pts": 0, + "start_time": "0.000000", + "duration_ts": 22279320, + "duration": "247.548000", + "extradata_size": 28220, + "disposition": { + "default": 0, + "dub": 0, + "original": 0, + "comment": 0, + "lyrics": 0, + "karaoke": 0, + "forced": 0, + "hearing_impaired": 0, + "visual_impaired": 0, + "clean_effects": 0, + "attached_pic": 0, + "timed_thumbnails": 0, + "captions": 0, + "descriptions": 0, + "metadata": 0, + "dependent": 0, + "still_image": 0 + }, + "tags": { + "filename": "KabelLTStd-Black.otf", + "mimetype": "font/otf" + } + }, + { + "index": 13, + "codec_type": "attachment", + "codec_tag_string": "[0][0][0][0]", + "codec_tag": "0x0000", + "r_frame_rate": "0/0", + "avg_frame_rate": "0/0", + "time_base": "1/90000", + "start_pts": 0, + "start_time": "0.000000", + "duration_ts": 22279320, + "duration": "247.548000", + "extradata_size": 45080, + "disposition": { + "default": 0, + "dub": 0, + "original": 0, + "comment": 0, + "lyrics": 0, + "karaoke": 0, + "forced": 0, + "hearing_impaired": 0, + "visual_impaired": 0, + "clean_effects": 0, + "attached_pic": 0, + "timed_thumbnails": 0, + "captions": 0, + "descriptions": 0, + "metadata": 0, + "dependent": 0, + "still_image": 0 + }, + "tags": { + "filename": "KGRedHands.ttf", + "mimetype": "font/ttf" + } + }, + { + "index": 14, + "codec_type": "attachment", + "codec_tag_string": "[0][0][0][0]", + "codec_tag": "0x0000", + "r_frame_rate": "0/0", + "avg_frame_rate": "0/0", + "time_base": "1/90000", + "start_pts": 0, + "start_time": "0.000000", + "duration_ts": 22279320, + "duration": "247.548000", + "extradata_size": 39392, + "disposition": { + "default": 0, + "dub": 0, + "original": 0, + "comment": 0, + "lyrics": 0, + "karaoke": 0, + "forced": 0, + "hearing_impaired": 0, + "visual_impaired": 0, + "clean_effects": 0, + "attached_pic": 0, + "timed_thumbnails": 0, + "captions": 0, + "descriptions": 0, + "metadata": 0, + "dependent": 0, + "still_image": 0 + }, + "tags": { + "filename": "KRONIKA.ttf", + "mimetype": "font/ttf" + } + }, + { + "index": 15, + "codec_type": "attachment", + "codec_tag_string": "[0][0][0][0]", + "codec_tag": "0x0000", + "r_frame_rate": "0/0", + "avg_frame_rate": "0/0", + "time_base": "1/90000", + "start_pts": 0, + "start_time": "0.000000", + "duration_ts": 22279320, + "duration": "247.548000", + "extradata_size": 633240, + "disposition": { + "default": 0, + "dub": 0, + "original": 0, + "comment": 0, + "lyrics": 0, + "karaoke": 0, + "forced": 0, + "hearing_impaired": 0, + "visual_impaired": 0, + "clean_effects": 0, + "attached_pic": 0, + "timed_thumbnails": 0, + "captions": 0, + "descriptions": 0, + "metadata": 0, + "dependent": 0, + "still_image": 0 + }, + "tags": { + "filename": "Lato-Bold.ttf", + "mimetype": "font/ttf" + } + }, + { + "index": 16, + "codec_type": "attachment", + "codec_tag_string": "[0][0][0][0]", + "codec_tag": "0x0000", + "r_frame_rate": "0/0", + "avg_frame_rate": "0/0", + "time_base": "1/90000", + "start_pts": 0, + "start_time": "0.000000", + "duration_ts": 22279320, + "duration": "247.548000", + "extradata_size": 120196, + "disposition": { + "default": 0, + "dub": 0, + "original": 0, + "comment": 0, + "lyrics": 0, + "karaoke": 0, + "forced": 0, + "hearing_impaired": 0, + "visual_impaired": 0, + "clean_effects": 0, + "attached_pic": 0, + "timed_thumbnails": 0, + "captions": 0, + "descriptions": 0, + "metadata": 0, + "dependent": 0, + "still_image": 0 + }, + "tags": { + "filename": "Lato-Reg.ttf", + "mimetype": "font/ttf" + } + }, + { + "index": 17, + "codec_type": "attachment", + "codec_tag_string": "[0][0][0][0]", + "codec_tag": "0x0000", + "r_frame_rate": "0/0", + "avg_frame_rate": "0/0", + "time_base": "1/90000", + "start_pts": 0, + "start_time": "0.000000", + "duration_ts": 22279320, + "duration": "247.548000", + "extradata_size": 58852, + "disposition": { + "default": 0, + "dub": 0, + "original": 0, + "comment": 0, + "lyrics": 0, + "karaoke": 0, + "forced": 0, + "hearing_impaired": 0, + "visual_impaired": 0, + "clean_effects": 0, + "attached_pic": 0, + "timed_thumbnails": 0, + "captions": 0, + "descriptions": 0, + "metadata": 0, + "dependent": 0, + "still_image": 0 + }, + "tags": { + "filename": "Lilly_.ttf", + "mimetype": "font/ttf" + } + }, + { + "index": 18, + "codec_type": "attachment", + "codec_tag_string": "[0][0][0][0]", + "codec_tag": "0x0000", + "r_frame_rate": "0/0", + "avg_frame_rate": "0/0", + "time_base": "1/90000", + "start_pts": 0, + "start_time": "0.000000", + "duration_ts": 22279320, + "duration": "247.548000", + "extradata_size": 627492, + "disposition": { + "default": 0, + "dub": 0, + "original": 0, + "comment": 0, + "lyrics": 0, + "karaoke": 0, + "forced": 0, + "hearing_impaired": 0, + "visual_impaired": 0, + "clean_effects": 0, + "attached_pic": 0, + "timed_thumbnails": 0, + "captions": 0, + "descriptions": 0, + "metadata": 0, + "dependent": 0, + "still_image": 0 + }, + "tags": { + "filename": "MarkerFelt.ttc", + "mimetype": "font/collection" + } + }, + { + "index": 19, + "codec_type": "attachment", + "codec_tag_string": "[0][0][0][0]", + "codec_tag": "0x0000", + "r_frame_rate": "0/0", + "avg_frame_rate": "0/0", + "time_base": "1/90000", + "start_pts": 0, + "start_time": "0.000000", + "duration_ts": 22279320, + "duration": "247.548000", + "extradata_size": 29592, + "disposition": { + "default": 0, + "dub": 0, + "original": 0, + "comment": 0, + "lyrics": 0, + "karaoke": 0, + "forced": 0, + "hearing_impaired": 0, + "visual_impaired": 0, + "clean_effects": 0, + "attached_pic": 0, + "timed_thumbnails": 0, + "captions": 0, + "descriptions": 0, + "metadata": 0, + "dependent": 0, + "still_image": 0 + }, + "tags": { + "filename": "Prototype.ttf", + "mimetype": "font/ttf" + } + } + ], + "format": { + "filename": "C:\\Temp\\Torrents\\Chou Futsuu Ken Chiba Densetsu - 01.mkv", + "nb_streams": 20, + "nb_programs": 0, + "format_name": "matroska,webm", + "format_long_name": "Matroska / WebM", + "start_time": "0.000000", + "duration": "247.548000", + "size": "45966869", + "bit_rate": "1485509", + "probe_score": 100, + "tags": { + "encoder": "libebml v1.4.4 + libmatroska v1.7.1", + "creation_time": "2024-01-10T15:38:09.000000Z", + "MOVIE/ENCODER": "Lavf58.19.102" + } + } +} \ No newline at end of file diff --git a/tests/test_buganime.py b/tests/test_buganime.py index 59554e5..3eb22a3 100644 --- a/tests/test_buganime.py +++ b/tests/test_buganime.py @@ -62,6 +62,7 @@ ('3.json', transcode.VideoInfo(audio_index=1, subtitle_index=0, width=1920, height=1080, fps='24000/1001', frames=34045)), ('4.json', transcode.VideoInfo(audio_index=2, subtitle_index=1, width=1920, height=1080, fps='24000/1001', frames=34047)), ('5.json', transcode.VideoInfo(audio_index=2, subtitle_index=1, width=1920, height=1080, fps='24000/1001', frames=35638)), + ('6.json', transcode.VideoInfo(audio_index=1, subtitle_index=0, width=1920, height=1080, fps='30/1', frames=7425)), ] From 66d985ca9a5a04a2faeae5b06ff603042a0b3380 Mon Sep 17 00:00:00 2001 From: Bugale Bugalit Date: Sat, 27 Jan 2024 19:33:29 +0200 Subject: [PATCH 2/2] ci: upgrade linter system to use Bugalint --- .github/dependabot.yml | 16 +++++++++ .github/workflows/check-code.yml | 53 +++++++++++++++++++++++++++++ .github/workflows/check-docs.yml | 33 ++++++++++++++++++ .github/workflows/check-general.yml | 41 ++++++++++++++++++++++ .github/workflows/check-yml.yml | 27 +++++++++++++++ .github/workflows/dependabot.yml | 18 ++++++++++ .github/workflows/lint.yml | 37 -------------------- .github/workflows/test.yml | 23 ------------- .mdl.yml | 5 +++ .yamllint.yml | 10 ++++++ README.md | 1 + buganime/buganime.py | 2 +- buganime/transcode.py | 4 +-- commitlint.config.js | 6 ++++ dev-requirements.txt | 1 + 15 files changed, 214 insertions(+), 63 deletions(-) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/check-code.yml create mode 100644 .github/workflows/check-docs.yml create mode 100644 .github/workflows/check-general.yml create mode 100644 .github/workflows/check-yml.yml create mode 100644 .github/workflows/dependabot.yml delete mode 100644 .github/workflows/lint.yml delete mode 100644 .github/workflows/test.yml create mode 100644 .mdl.yml create mode 100644 .yamllint.yml create mode 100644 commitlint.config.js diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..5f362fc --- /dev/null +++ b/.github/dependabot.yml @@ -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' diff --git a/.github/workflows/check-code.yml b/.github/workflows/check-code.yml new file mode 100644 index 0000000..4011ced --- /dev/null +++ b/.github/workflows/check-code.yml @@ -0,0 +1,53 @@ +--- +name: Checks +on: + 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 .)'}, + ] + 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 diff --git a/.github/workflows/check-docs.yml b/.github/workflows/check-docs.yml new file mode 100644 index 0000000..a266ab1 --- /dev/null +++ b/.github/workflows/check-docs.yml @@ -0,0 +1,33 @@ +--- +name: Checks +on: + 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 diff --git a/.github/workflows/check-general.yml b/.github/workflows/check-general.yml new file mode 100644 index 0000000..9cb72b7 --- /dev/null +++ b/.github/workflows/check-general.yml @@ -0,0 +1,41 @@ +--- +name: Checks +on: + - 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 + - name: Get Base + id: get-base + run: |- + count=$(gh api "/repos/${{ github.repository }}/pulls/${{ github.event.number }}/commits" --jq "length") + 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 }} diff --git a/.github/workflows/check-yml.yml b/.github/workflows/check-yml.yml new file mode 100644 index 0000000..58c4dd7 --- /dev/null +++ b/.github/workflows/check-yml.yml @@ -0,0 +1,27 @@ +--- +name: Checks +on: + 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 diff --git a/.github/workflows/dependabot.yml b/.github/workflows/dependabot.yml new file mode 100644 index 0000000..1855519 --- /dev/null +++ b/.github/workflows/dependabot.yml @@ -0,0 +1,18 @@ +--- +name: Dependabot +on: + - 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}}" + env: + GH_TOKEN: ${{ github.token }} diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index 233d5ef..0000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: Lint - -on: - pull_request: - branches: [ main ] - -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-json", "cwd": ".", "cmd": "pylint --load-plugins pylint_pytest $(Get-ChildItem -Filter *.py -Recurse .)"}, - ] - 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: | - py -3.11 -m pip install --upgrade pip - py -3.11 -m pip install -r dev-requirements.txt - py -3.11 -m pip install git+https://github.com/bugale/Bugalintly.git@bugalintly - - name: Lint - run: | - cd ${{ matrix.linter.cwd }} - ${{ matrix.linter.cmd }} > lint.log - $exitcode = $LASTEXITCODE - type lint.log | Lintly --log --no-request-changes --no-review-body --base-dir . --format=${{ matrix.linter.format }} --comment-tag=${{ matrix.linter.name }} - exit $exitcode - env: - LINTLY_API_KEY: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 74f1fc4..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: Test - -on: - pull_request: - branches: [ main ] - -jobs: - 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: | - py -3.11 -m pip install --upgrade pip - py -3.11 -m pip install -r dev-requirements.txt - - name: Test - run: | - pytest tests diff --git a/.mdl.yml b/.mdl.yml new file mode 100644 index 0000000..9121d63 --- /dev/null +++ b/.mdl.yml @@ -0,0 +1,5 @@ +--- +# MD013/line-length - Line length +MD013: + line_length: 160 + ignore_code_blocks: true diff --git a/.yamllint.yml b/.yamllint.yml new file mode 100644 index 0000000..4db652a --- /dev/null +++ b/.yamllint.yml @@ -0,0 +1,10 @@ +--- +extends: default +ignore: + - 'node_modules/**' +rules: + new-lines: disable + truthy: + check-keys: false + line-length: + max: 160 diff --git a/README.md b/README.md index 1af0a00..b79d71c 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/buganime/buganime.py b/buganime/buganime.py index 32a2144..8d5fea0 100644 --- a/buganime/buganime.py +++ b/buganime/buganime.py @@ -157,7 +157,7 @@ def process_path(input_path: str) -> None: def main(args: list[str]) -> int: if len(args) != 1: - print("Usage: buganime.py ") + print('Usage: buganime.py ') return 1 input_path = args[0] diff --git a/buganime/transcode.py b/buganime/transcode.py index b5a541d..a50a925 100644 --- a/buganime/transcode.py +++ b/buganime/transcode.py @@ -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: diff --git a/commitlint.config.js b/commitlint.config.js new file mode 100644 index 0000000..42226d6 --- /dev/null +++ b/commitlint.config.js @@ -0,0 +1,6 @@ +module.exports = { + extends: ['@commitlint/config-conventional'], + rules: { + 'body-max-line-length': [0, 'always', 10000] + } +} diff --git a/dev-requirements.txt b/dev-requirements.txt index de29a6c..0469855 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -2,6 +2,7 @@ pytest pylint pylint-pytest flake8 +flake8-quotes mypy tqdm-stubs types-retry