Use subprocess instead of bash

This commit is contained in:
rany 2021-06-08 20:34:18 +03:00
parent 8f99d916c5
commit 6a1d991dd7
2 changed files with 22 additions and 0 deletions

1
.gitignore vendored
View File

@ -6,6 +6,7 @@
!setup.cfg
!setup.py
!pyproject.toml
!src/
!src/edgeTTS/__init__.py
!src/edgePlayback/
!src/edgePlayback/__init__.py

21
src/edgePlayback/__init__.py Executable file
View File

@ -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()