diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..13782d36 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,94 @@ +name: autosub + +on: + push: + branches: + pull_request: + workflow_dispatch: + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.6, 3.7, 3.8] + + steps: + - + name: Checkout + uses: actions/checkout@v2 + + - + name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - + name: build + run: | + set -v + python -m pip install --upgrade pip + pip install . + autosub -h + + test: + + runs-on: ubuntu-latest + needs: build + + steps: + - + name: Checkout + uses: actions/checkout@v2 + + - + name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.8 + + - + name: build + run: | + set -v + python -m pip install --upgrade pip + pip install . + autosub -h + + - + name: pylint check + continue-on-error: true + run: | + set -v + pip install pylint + pylint autosub + + - + name: prepare test environment + run: | + set -v + sudo apt update + sudo apt install -qq -y ffmpeg + pip install -U ffmpeg-normalize langcodes youtube-dl + + - + name: prepare test file + run: | + set -v + youtube-dl --no-progress -f 134+140 FhPI5lbyz-I -o video.mp4 + ffmpeg -hide_banner -loglevel quiet -nostats -ss 00:02:20 -i video.mp4 -to 00:02:00 test.mp4 && rm video.mp4 + + - + name: test autosub + timeout-minutes: 10 + run: | + autosub -i test.mp4 -S en-us -D zh-cn -der -of all + cat 'test.en&zh-cn.srt' + + - + uses: actions/upload-artifact@v2 + with: + name: result + path: test* \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index e42bbef5..00000000 --- a/.travis.yml +++ /dev/null @@ -1,8 +0,0 @@ -language: python -python: - - "3.7" -install: - - pip install . - - pip install pylint -script: - - pylint autosub diff --git a/autosub/api_xfyun.py b/autosub/api_xfyun.py index b33940b3..5972b1a5 100644 --- a/autosub/api_xfyun.py +++ b/autosub/api_xfyun.py @@ -17,8 +17,8 @@ from time import mktime # Import third-party modules -import websocket import _thread +import websocket # Any changes to the path and your own modules from autosub import constants diff --git a/autosub/cmdline_utils.py b/autosub/cmdline_utils.py index 54c0eb85..e015360d 100644 --- a/autosub/cmdline_utils.py +++ b/autosub/cmdline_utils.py @@ -249,10 +249,10 @@ def validate_json_config(config_file): with open(config_file, encoding='utf-8') as config_fp: try: config_dict = json.load(config_fp) - except ValueError: + except ValueError as credential_load_error: raise exceptions.AutosubException( _("Error: Can't decode config file \"{filename}\".").format( - filename=config_file)) + filename=config_file)) from credential_load_error else: raise exceptions.AutosubException( _("Error: Config file \"{filename}\" doesn't exist.").format( diff --git a/autosub/exceptions.py b/autosub/exceptions.py index 8b7b626b..6b406b6b 100644 --- a/autosub/exceptions.py +++ b/autosub/exceptions.py @@ -20,7 +20,7 @@ class AutosubException(Exception): """ def __init__(self, msg): - super(AutosubException, self).__init__(msg) + super().__init__(msg) try: self.msg = str(msg) except UnicodeEncodeError: diff --git a/autosub/ffmpeg_utils.py b/autosub/ffmpeg_utils.py index 9ffe446a..fe7597c5 100644 --- a/autosub/ffmpeg_utils.py +++ b/autosub/ffmpeg_utils.py @@ -93,10 +93,10 @@ def __call__(self, region): except KeyboardInterrupt: return None - except subprocess.CalledProcessError: + except subprocess.CalledProcessError as ffmpeg_exec_error: raise exceptions.AutosubException( _("Error: ffmpeg can't split your file. " - "Check your audio processing options.")) + "Check your audio processing options.")) from ffmpeg_exec_error def ffprobe_get_fps( # pylint: disable=superfluous-parens @@ -134,7 +134,7 @@ def ffprobe_get_fps( # pylint: disable=superfluous-parens try: fps = float(input_str) if fps <= 0.0: - raise ValueError + raise ValueError # pylint: disable=raise-missing-from except ValueError: print(_("Use \".srt\" instead.")) fps = 0.0 diff --git a/autosub/sub_utils.py b/autosub/sub_utils.py index d6d65abb..a6293a2f 100644 --- a/autosub/sub_utils.py +++ b/autosub/sub_utils.py @@ -41,15 +41,20 @@ def str_to_file( if input_m: if not os.path.isdir(os.path.dirname(dest)): - dest = os.getcwd() + os.path.basename(dest) + dest = os.getcwd() + os.sep + os.path.basename(dest) + while os.path.isfile(dest): + old_dest = dest print(_("There is already a file with the same path " "or the path isn't valid: \"{dest_name}\".").format(dest_name=dest)) dest = input_m( _("Input a new path (including directory and file name) for output file.\n")) + if dest == "": + dest = old_dest + continue dest = dest.rstrip("\"").lstrip("\"") if not os.path.isdir(os.path.dirname(dest)): - dest = os.getcwd() + os.path.basename(dest) + dest = os.getcwd() + os.sep + os.path.basename(dest) dest = os.path.splitext(dest)[0] dest = "{base}{ext}".format(base=dest, ext=ext) @@ -627,6 +632,9 @@ def pysubs2_ssa_event_add( # pylint: disable=too-many-branches, too-many-statem # text_list is [text, text, ...] i = 0 length = len(text_list) + if length != src_ssafile.events.__len__(): + text_list = [i for i in text_list if i] + length = len(text_list) if same_event_type == 0: # append text_list to new events if style_name: diff --git a/requirements.txt b/requirements.txt index ecb6aba9..39b95acd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,10 +1,10 @@ requests>=2.3.0 pysubs2>=0.2.4 progressbar2>=3.34.3 -auditok==0.1.5 +auditok>=0.1.5 googletrans>=2.4.0 wcwidth>=0.1.7 -google-cloud-speech>=1.3.1 +google-cloud-speech>=1.3.1,<2.0.0 websocket-client>=0.56.0 fuzzywuzzy>=0.18.0 python-Levenshtein>=0.12.0 diff --git a/setup.py b/setup.py index bfdfa116..d1c9d6be 100644 --- a/setup.py +++ b/setup.py @@ -34,11 +34,11 @@ 'requests>=2.3.0', 'pysubs2>=0.2.4', 'progressbar2>=3.34.3', - 'auditok==0.1.5', + 'auditok>=0.1.5', 'googletrans>=2.4.0', 'wcwidth>=0.1.7', 'fuzzywuzzy>=0.18.0', - 'google-cloud-speech>=1.3.1', + 'google-cloud-speech>=1.3.1,<2.0.0', 'websocket-client>=0.56.0', 'python-docx>=0.8.10', 'send2trash>=1.5.0'