From 6a1d991dd7615e14669e6a74205684280ad969a7 Mon Sep 17 00:00:00 2001 From: rany Date: Tue, 8 Jun 2021 20:34:18 +0300 Subject: [PATCH] Use subprocess instead of bash --- .gitignore | 1 + src/edgePlayback/__init__.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100755 src/edgePlayback/__init__.py diff --git a/.gitignore b/.gitignore index 47a8817..1cdf84d 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ !setup.cfg !setup.py !pyproject.toml +!src/ !src/edgeTTS/__init__.py !src/edgePlayback/ !src/edgePlayback/__init__.py diff --git a/src/edgePlayback/__init__.py b/src/edgePlayback/__init__.py new file mode 100755 index 0000000..9973f04 --- /dev/null +++ b/src/edgePlayback/__init__.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 +import sys +import tempfile +import subprocess +from shutil import which + +def main(): + if which('mpv') and which('edge-tts'): + with tempfile.NamedTemporaryFile() as media: + with tempfile.NamedTemporaryFile() as subtitle: + print ("Media file: %s" % media.name) + print ("Subtitle file: %s" % subtitle.name) + p = subprocess.Popen(['edge-tts', '-w'] + sys.argv[1:], stdout=media, stderr=subtitle) + p.communicate() + p = subprocess.Popen(['mpv', '--keep-open=yes', '--sub-file=' + subtitle.name, media.name]) + p.communicate() + else: + print ("This script requires mpv and edge-tts.") + +if __name__ == "__main__": + main()