diff --git a/.gitignore b/.gitignore index 10e73277d..491cdf911 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,9 @@ dist/ .DS_Store MANIFEST *#* -.vscode \ No newline at end of file +.vscode +/.vs/autosub/v15/.suo +/.vs +/autosub.sln +/autosub.pyproj +/.idea diff --git a/autosub/__init__.py b/autosub/__init__.py index 61019464b..0cc7777c0 100644 --- a/autosub/__init__.py +++ b/autosub/__init__.py @@ -61,7 +61,7 @@ def __call__(self, region): start, end = region start = max(0, start - self.include_before) end += self.include_after - temp = tempfile.NamedTemporaryFile(suffix='.flac') + temp = tempfile.NamedTemporaryFile(suffix='.flac', delete=False) command = ["ffmpeg", "-ss", str(start), "-t", str(end - start), "-y", "-i", self.source_path, "-loglevel", "error", temp.name] @@ -99,7 +99,7 @@ def __call__(self, data): line = json.loads(line) line = line['result'][0]['alternative'][0]['transcript'] return line[:1].upper() + line[1:] - except IndexError: + except (ValueError, IndexError): # no result continue @@ -107,7 +107,7 @@ def __call__(self, data): return None -class Translator(object): # pylint: disable=too-few-public-methods +class Translator(object): # pylint: disable=too-few-public-methods """ Class for translating a sentence from a one language to another. """ @@ -163,6 +163,17 @@ def is_exe(file_path): return None +def ffmpeg_check(): + """ + Return the ffmpeg executable name. "null" returned when no executable exists. + """ + if which("ffmpeg"): + return "ffmpeg" + if which("ffmpeg.exe"): + return "ffmpeg.exe" + return None + + def extract_audio(filename, channels=1, rate=16000): """ Extract audio from an input file to a temporary WAV file. @@ -171,10 +182,10 @@ def extract_audio(filename, channels=1, rate=16000): if not os.path.isfile(filename): print("The given file does not exist: {}".format(filename)) raise Exception("Invalid filepath: {}".format(filename)) - if not which("ffmpeg"): + if not ffmpeg_check(): print("ffmpeg: Executable not found on machine.") raise Exception("Dependency not found: ffmpeg") - command = ["ffmpeg", "-y", "-i", filename, + command = [ffmpeg_check(), "-y", "-i", filename, "-ac", str(channels), "-ar", str(rate), "-loglevel", "error", temp.name] use_shell = True if os.name == "nt" else False diff --git a/setup.py b/setup.py index c9ac20c0a..f1b35f179 100644 --- a/setup.py +++ b/setup.py @@ -26,7 +26,7 @@ author='Anastasis Germanidis', author_email='agermanidis@gmail.com', url='https://github.com/agermanidis/autosub', - packages=['autosub'], + packages=[str('autosub')], entry_points={ 'console_scripts': [ 'autosub = autosub:main',