Skip to content

Commit

Permalink
Merge pull request agermanidis#144 from jitingcn/fix-1
Browse files Browse the repository at this point in the history
  • Loading branch information
BingLingGroup authored Oct 4, 2020
2 parents ff0f6ba + b34cd5b commit 23dd7a0
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 21 deletions.
94 changes: 94 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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*
8 changes: 0 additions & 8 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion autosub/api_xfyun.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions autosub/cmdline_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion autosub/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions autosub/ffmpeg_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions autosub/sub_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 23dd7a0

Please sign in to comment.