28 Commits

Author SHA1 Message Date
kelciour 424db15167 Minor fixes 2017-11-06 20:42:37 +03:00
kelciour c2c622f0ce Add audio & video export 2017-11-06 20:09:14 +03:00
kelciour 51620fc3a5 Add multiline search 2017-10-14 23:18:50 +03:00
kelciour c6990ad164 Merge branch 'master' of https://github.com/kelciour/playphrase 2017-10-08 19:41:04 +03:00
kelciour e23e8ef947 Search by using non-latin characters in Windows console 2017-10-08 19:40:32 +03:00
kelciour 2f5b419010 Fix typo in README 2017-08-27 01:26:58 +03:00
kelciour 8f878e2e35 Update README 2017-08-27 01:22:21 +03:00
kelciour 5780b614cc Update README 2017-08-26 21:59:26 +03:00
kelciour 9f0c4a6091 Update subtitles background color 2017-08-26 13:00:57 +03:00
kelciour 3db4341ab2 Remove extra quotes in media_dir path 2017-08-26 12:19:37 +03:00
kelciour b477677732 Add bash script to simplify user input 2017-08-25 23:37:43 +03:00
kelciour 70eacd51cc Add 'quit' as exit command 2017-08-25 23:36:59 +03:00
kelciour dab7e2c2ac Add Linux support 2017-08-25 17:56:14 +03:00
kelciour 8b998b2286 Remove drc filter 2017-08-14 19:40:06 +03:00
kelciour 52fe86b1ab Add background to subtitles 2017-08-14 14:54:34 +03:00
kelciour 58a67a1a75 Add drc audio filter for audiobooks 2017-08-14 13:43:02 +03:00
kelciour e1e6008a8f Add drc filter 2017-08-06 12:28:29 +03:00
kelciour 34295dd142 Rename mpv option 2017-08-06 12:27:41 +03:00
kelciour 95c84c0738 Rename script 2017-08-03 19:19:40 +03:00
kelciour 6ec827aa76 Use filename title with audiobooks 2017-08-03 19:17:26 +03:00
kelciour af162b0148 Add bat file to simplify start for audiobooks 2017-08-03 17:26:09 +03:00
kelciour 363e43c87a Add option to determine sentence boundary 2017-08-03 17:21:53 +03:00
kelciour 34082db990 add mp3 extension in movie_extensions list 2017-08-03 16:35:05 +03:00
kelciour 78a1e4af6e add option to pass mpv player options 2017-08-03 16:32:11 +03:00
kelciour 030165875c Add bat file to simplify start 2017-05-06 18:34:28 +03:00
kelciour b6a79d41f7 Decrease limit option to 15 seconds 2017-05-06 18:11:59 +03:00
kelciour 2d913311bb Preserve insertion order in mpv playlist 2017-01-01 12:38:48 +03:00
kelciour bdc5faf491 Don't start ipc-server if mpv is already opened 2016-12-30 18:27:48 +03:00
6 changed files with 315 additions and 68 deletions
+66 -19
View File
@@ -1,31 +1,34 @@
# videogrep
Search for specific words in srt files and watch with mpv.
# PlayPhrase
Search for specific words or phrases in subtitle files and watch video fragments with [mpv](https://mpv.io/).
Inspired by [videogrep](http://lav.io/2014/06/videogrep-automatic-supercuts-with-python/) and [playphrase.me](http://playphrase.me/).
# Download
# Video
* Windows - [https://github.com/kelciour/playphrase/releases](https://github.com/kelciour/playphrase/releases)
* Linux and MacOS - [playphrase-master.zip](https://github.com/kelciour/playphrase/archive/master.zip)
# Requirements
* Python 2.7
* grep
* mpv
[![YouTube: PlayPhrase for Movies](http://i.imgur.com/QZ9QSiO.png)](http://youtu.be/ciMEY3moATU)
# Usage
Run ```python videogrep.py -i <media_dir> _init_``` to generate txt files from srt files that will be used for search (only the first time or when you add new movies in your folder).
Run ```python playphrase.py -i <media_dir> _init_``` to generate txt files from srt files that will be used for search (only the first time or when you add new movies in your folder).
After that use
```python videogrep.py -i <media_dir> <phrase>```
```python playphrase.py -i <media_dir> <phrase>```
Regular expressions can be used in search, for example, \b for word boundary.
### Keyboard Shortcuts
Use ```Enter``` to move to the next clip or ```Shift + <``` and ```Shift + >``` to switch between clips, ```q``` to close player and ```f``` to toggle fullscreen.
More info: [https://mpv.io/manual/master/#keyboard-control](https://mpv.io/manual/master/#keyboard-control)
Use ```Enter``` to move to the next clip or ```Shift + <``` and ```Shift + >``` to switch between clips, ```Ctrl + Left``` and ```Ctrl + Right``` to move to the prev/next subtitle, ```q``` to close video player.
More info: [https://mpv.io/manual/stable/#keyboard-control](https://mpv.io/manual/master/#keyboard-control)
### Batch Scripts
There's ```videogrep.bat``` (Windows) and ```videogrep.sh``` (Linux) files to simplify user input. First time before running edit them and update ```media_dir``` path. Use ```quit```, ```exit``` or ```q```, ```x``` to exit from the batch script.
### Additional Options:
###Additional options:
* ```-ph, --phrases GAP_BETWEEN_PHRASES```
move start time of the clip to the beginning of the current phrase. Value is optional (default=1.75 seconds)
* ```-l, --limit```
@@ -35,13 +38,57 @@ padding in seconds to add to the start and end of each clip (default=0.0 seconds
* ```-e, --ending```
play only matching lines (or phrases)
* ```-r, --randomize```
randomize the clips
randomize clips
* ```-o, --output```
name of the file in which output of \'grep\' command will be written
* ```-d, --demo```
only show grep results
* ```-a, --audio```
create audio fragments
* ```-v, --video```
create video fragments
* ```-s, --video-sub```
create video fragments with subtitles
* ```-m, --mpv-options OPTIONS```
mpv player options
### Optional Configuration Changes
For example, you can modify [mpv.conf](https://mpv.io/manual/stable/#configuration-files)
```
autofit=900
geometry=50%:50%
```
and [input.conf](https://mpv.io/manual/stable/#interactive-control)
```
ENTER playlist-next force
```
More info: [https://mpv.io/manual/](https://mpv.io/manual/)
# Download
See [https://github.com/kelciour/playphrase/releases](https://github.com/kelciour/playphrase/releases/latest)
# Usage with AudioBooks
It's possible to use audiobooks as media input. For that purpose there's ```audiogrep.bat``` and ```audiogrep.sh``` files to simplify user input. But you need to generate subtitles for every audio file. It can be done almost automatically using [aeneas](https://github.com/readbeyond/aeneas). Also [csplit](https://en.wikipedia.org/wiki/Csplit) can be used to split text of the book by chapters and [Pragmatic Segmenter](https://github.com/diasks2/pragmatic_segmenter) to split chapter's content by "sentences".
Here's example video how it looks like (YouTube):
[![YouTube: PlayPhrase for AudioBooks](http://i.imgur.com/gUFXeVI.png)](https://youtu.be/LEyRfy7TsnE)
# Requirements
* python 2.7
* grep
* mpv
# Note
* videogrep requires the subtitle track and the video file to have the exact same name, up to the extension.
* just re-run your command if there was an error with pipe
* playphrase requires the subtitle track and the video file to have the exact same name, up to the extension.
+24
View File
@@ -0,0 +1,24 @@
@echo off
setlocal EnableDelayedExpansion
set media_dir="J:\English AudioBooks"
for /L %%n in (1,0,1) do (
set /p phrase="Phrase: "
if /I "!phrase!"=="q" call :stop
if /I "!phrase!"=="x" call :stop
if /I "!phrase!"=="quit" call :stop
if /I "!phrase!"=="exit" call :stop
rem Disable album cover art and create a window even if there is no album cover art.
rem python playphrase.py --mpv-options "--video=no --force-window=yes --osc=no --title=${filename}" --input %media_dir% "!phrase!"
python playphrase.py --mpv-options "--sub-font-size=37 --sub-back-color=0.05/0.95 --sub-scale-by-window=no --sub-scale-with-window=no --autofit=620 --osc=no --title=${filename}" --input %media_dir% "!phrase!"
)
:stop
call :__stop 2>nul
:__stop
() creates a syntax error, quits the batch
Executable
+22
View File
@@ -0,0 +1,22 @@
#!/bin/bash
media_dir="/media/nickolay/9A043D5E043D3F17/English AudioBooks"
while true
do
read -p "Phrase: " -r phrase
if [ "$phrase" = "q" ]; then
exit 0
elif [ "$phrase" = "x" ]; then
exit 0
elif [ "$phrase" = "quit" ]; then
exit 0
elif [ "$phrase" = "exit" ]; then
exit 0
else
# Disable album cover art and create a window even if there is no album cover art.
# python "playphrase.py" --mpv-options "--video=no --force-window=yes --osc=no --title=${filename}" --input "$media_dir" "$phrase"
python "playphrase.py" --mpv-options "--sub-font-size=37 --sub-back-color=0.05/0.9 --sub-scale-by-window=no --sub-scale-with-window=no --autofit=620 --osc=no --title=${filename}" --input "$media_dir" "$phrase"
fi
done
+163 -49
View File
@@ -7,10 +7,11 @@ import re
import sys
import subprocess
import time
import locale
from collections import OrderedDict
movie_extensions = ['mp4', 'avi', 'mkv']
movie_extensions = ['mp4', 'avi', 'mkv', 'mp3']
srt_encodings = ["utf-8", "cp1251"]
def srt_time_to_seconds(time):
@@ -75,6 +76,7 @@ def convert_into_sentences(en_subs, limit):
prev_sub_content[-1] != ']' and
prev_sub_content[-1] != ')' and
prev_sub_content[-1] != u'' and
prev_sub_content[-1] != u'' and
prev_sub_content[-1] != '"'):
subs[-1] = (prev_sub_start, sub_end, prev_sub_content + " " + sub_content)
@@ -96,61 +98,146 @@ def write_subtitles(filename, subs):
f.close()
def play_clips(clips, ending_mode):
def update_mpv_player_cmd(cmd_options, mpv_options):
for opt in mpv_options.split():
if "=" in opt:
key, value = opt.split("=", 1)
cmd_options[key] = value
else:
cmd_options[opt] = True
cmd = ["mpv"]
for opt in cmd_options:
if cmd_options[opt] == True:
cmd.append(opt)
else:
cmd.append(opt + "=" + cmd_options[opt])
return cmd
def get_fragment_filename(phrase):
s = phrase.strip().replace(' ', '_')
s = s.replace('.*', '...')
max_filename_length = 30
if len(s) > max_filename_length:
s = s[:max_filename_length] + "..."
return re.sub(r'(?u)[^-\w\'\.]', '', s)
def create_fragments(search_phrase, clips, export_mode):
idx = 1
for video_file, clip_start, clip_end in clips:
fragment_filename = get_fragment_filename(search_phrase)
if len(clips) > 1:
fragment_filename += "_" + str(idx).zfill(3)
ss = clip_start
to = clip_end
t = to - ss
t_fade = 0.2
af = "afade=t=in:st=%s:d=%s,afade=t=out:st=%s:d=%s" % (0, t_fade, t - t_fade, t_fade)
video_encoding_mode = "ultrafast"
if export_mode["audio"]:
cmd = " ".join(["ffmpeg", "-y", "-ss", str(ss), "-i", '"' + video_file + '"', "-loglevel", "quiet", "-t", str(t), "-map", "0:a:0", "-af", af, '"' + fragment_filename + ".mp3" + '"'])
p = subprocess.Popen(cmd)
p.wait()
if export_mode["video"]:
cmd = " ".join(["ffmpeg", "-y", "-ss", str(ss), "-i", '"' + video_file + '"', "-strict", "-2", "-loglevel", "quiet", "-t", str(t), "-map", "0:v:0", "-map", "0:a:0", "-c:v", "libx264", "-preset", video_encoding_mode, "-c:a", "aac", "-ac", "2", "-af", af, '"' + fragment_filename + ".mp4" + '"'])
p = subprocess.Popen(cmd)
p.wait()
if export_mode["video-sub"]:
srt_style = "FontName=Arial,FontSize=22"
srt_filename = video_file[:-4] + ".srt"
if srt_filename[1] == ":": # Windows
srt_filename = srt_filename.replace("\\", "\\\\\\\\")
srt_filename = srt_filename.replace(":", "\\\\:")
srt_filename = srt_filename.replace(",", "\\\\\\,")
srt_filename = srt_filename.replace("'", "\\\\\\'")
vf = "\"" + "subtitles=" + srt_filename + ":force_style='" + srt_style + "',setpts=PTS-STARTPTS" + "\""
af = "afade=t=in:st=%s:d=%s,afade=t=out:st=%s:d=%s,asetpts=PTS-STARTPTS" % (ss, t_fade, to - t_fade, t_fade)
cmd = " ".join(["ffmpeg", "-y", "-ss", str(ss), "-i", '"' + video_file + '"', "-strict", "-2", "-loglevel", "quiet", "-t", str(t), "-map", "0:v:0", "-map", "0:a:0", "-c:v", "libx264", "-preset", video_encoding_mode, "-c:a", "aac", "-ac", "2", "-vf", vf, "-af", af, "-copyts", '"' + fragment_filename + ".sub.mp4" + '"'])
p = subprocess.Popen(cmd)
p.wait()
idx += 1
def play_clips(clips, ending_mode, mpv_options):
if len(clips) != 0:
clip_filename, clip_start, clip_end = clips[0]
pipe_name = "\\\\.\pipe\mpv-pipe"
cmd = ["mpv", "--idle=once", "--force-window=no", "--input-ipc-server=%s" % pipe_name]
p = subprocess.Popen(cmd, shell=False)
pipe_name = "mpv-pipe"
time.sleep(0.5) # wait 0.5 seconds for pipe has been created
mpv_default_options = { "--idle":"once", "--no-terminal":True, "--force-window":"no", "--input-file":pipe_name }
cmd = update_mpv_player_cmd(mpv_default_options, mpv_options)
with open(pipe_name, 'w'): # create pipe
pass
p = subprocess.Popen(cmd) # start mpv player in idle mode
if not os.path.isfile(pipe_name):
print "Can't open '%s'" % pipe_name
return
else:
with open(pipe_name, "wb", 0) as f_pipe:
for clip_filename, clip_start, clip_end in clips:
clip_filename = clip_filename.replace("\\","/")
cmd = ["echo", "loadfile", '"' + clip_filename + '"']
cmd = ["loadfile", '"' + clip_filename + '"']
if ending_mode:
cmd.append("append-play start=%s,end=%s" % (clip_start, clip_end))
else:
cmd.append("append-play start=%s" % clip_start)
try:
with open(pipe_name, "w") as mpv_pipe:
subprocess.call(cmd, stdout=mpv_pipe)
if p.poll() == None:
f_pipe.write(" ".join(cmd) + "\n")
else:
break
except IOError as ex:
print ex
p.kill()
if ex.errno != 32:
print ex
if p != None:
p.kill()
return
def main(media_dir, search_phrase, phrase_mode, phrases_gap, padding, limit, output_file, ending_mode, randomize_mode, demo_mode):
cmd = " ".join(["grep", "-r", "-n", "-i", "--include", "\*.txt", "-P", '"' + search_phrase + '"', '"' + media_dir + '"'])
p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=-1)
def main(media_dir, search_phrase, phrase_mode, phrases_gap, padding, limit, output_file, ending_mode, randomize_mode, demo_mode, mpv_options, audio_mode, video_mode, video_with_sub_mode):
search_phrase = search_phrase.decode(locale.getpreferredencoding())
search_phrase_in_utf8_representation = repr(search_phrase.encode("UTF-8"))
search_phrase_in_grep = "\"(?s)\(\d\d:\d\d:\d\d,\d\d\d\, \d\d:\d\d:\d\d,\d\d\d\)\\t[^\\n]*" + search_phrase_in_utf8_representation.strip("\'") + "[^\\n]*\""
cmd = " ".join(["grep", "-r", "-z", "-o", "-i", "--include", "\*\.txt", "-P", search_phrase_in_grep, '"' + media_dir + '"'])
p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True, bufsize=-1)
output, error = p.communicate()
if p.returncode == 0:
matches = output.rstrip("\x00").split("\x00")
if output_file != None:
with open(output_file, 'w') as f_results:
f_results.write(output)
f_results.write("\n".join(matches))
matches = output.splitlines()
clips = []
for match in matches:
filename, line = match.split(".txt:", 1)
line_number, line = line.split(":", 1)
line_number = int(line_number)
sub_timing, sub_content = line.split("\t", 1)
sub_start, sub_end = sub_timing.strip("()").split(", ")
match_sub_start = srt_time_to_seconds(sub_start)
match_sub_end = srt_time_to_seconds(sub_end)
lines = line.splitlines()
def get_line_timings(line):
sub_timing, sub_content = line.split("\t", 1)
sub_start, sub_end = sub_timing.strip("()").split(", ")
return (sub_start, sub_end)
sub_start, sub_end = get_line_timings(lines[0])
match_sub_start = srt_time_to_seconds(sub_start)
sub_start, sub_end = get_line_timings(lines[-1])
match_sub_end = srt_time_to_seconds(sub_end)
phrase_start = match_sub_start
phrase_end = match_sub_end
@@ -158,10 +245,18 @@ def main(media_dir, search_phrase, phrase_mode, phrases_gap, padding, limit, out
with open(filename + ".txt") as f_txt:
txt_lines = f_txt.read().splitlines()
txt_line_start_idx = line_number - 1
txt_line_end_idx = line_number - 1
def find_line_number(lines, line):
for idx, lines in enumerate(lines):
if line in lines:
return idx + 1
for txt_line in reversed(txt_lines[:line_number - 1]):
line_number_start = find_line_number(txt_lines, lines[0])
line_number_end = find_line_number(txt_lines, lines[-1])
txt_line_start_idx = line_number_start - 1
txt_line_end_idx = line_number_end - 1
for txt_line in reversed(txt_lines[:line_number_start - 1]):
sub_timing, sub_content = txt_line.split("\t", 1)
sub_start, sub_end = sub_timing.strip("()").split(", ")
@@ -174,7 +269,7 @@ def main(media_dir, search_phrase, phrase_mode, phrases_gap, padding, limit, out
else:
break
for txt_line in txt_lines[line_number:]:
for txt_line in txt_lines[line_number_end:]:
sub_timing, sub_content = txt_line.split("\t", 1)
sub_start, sub_end = sub_timing.strip("()").split(", ")
@@ -227,8 +322,10 @@ def main(media_dir, search_phrase, phrase_mode, phrases_gap, padding, limit, out
if randomize_mode:
random.shuffle(clips)
if not demo_mode:
play_clips(clips, ending_mode)
if audio_mode or video_mode or video_with_sub_mode:
create_fragments(search_phrase, clips, {"audio": audio_mode, "video": video_mode, "video-sub": video_with_sub_mode})
elif not demo_mode:
play_clips(clips, ending_mode, mpv_options)
elif p.returncode == 1:
print "'%s' is not found in '%s'" % (search_phrase, media_dir)
@@ -261,7 +358,7 @@ def convert_to_unicode(file_content):
print "ERROR: Unknown encoding. Use srt file with 'utf-8' encoding."
return (False, file_content)
def init(media_dir):
def init(media_dir, limit):
for root, dirs, files in os.walk(media_dir):
for file in files:
file_ext = file.split('.')[-1]
@@ -279,7 +376,7 @@ def init(media_dir):
sys.exit(1)
subs = read_subtitles(content)
subs = convert_into_sentences(subs, 20)
subs = convert_into_sentences(subs, limit)
write_subtitles(file_path[:-4] + ".txt", subs)
@@ -292,7 +389,7 @@ def parse_args(argv):
print "Search phrase can't be empty"
sys.exit()
args = {"padding": 0, "limit": 30, "output_file": None, "phrase_mode": False, "phrases_gap":1.75, "search_phrase":search_phrase, "ending_mode":False, "randomize_mode":False, "demo_mode":False}
args = {"padding": 0, "limit": 60, "output_file": None, "phrase_mode": False, "phrases_gap":1.25, "search_phrase":search_phrase, "ending_mode":False, "randomize_mode":False, "demo_mode":False, "mpv_options":"", "audio_mode":False, "video_mode":False, "video_with_sub_mode":False }
argv = argv[:-1]
idx = 0
@@ -323,6 +420,12 @@ def parse_args(argv):
args["randomize_mode"] = True
elif argv[idx] == "--demo" or argv[idx] == "-d":
args["demo_mode"] = True
elif argv[idx] == "--audio" or argv[idx] == "-a":
args["audio_mode"] = True
elif argv[idx] == "--video" or argv[idx] == "-v":
args["video_mode"] = True
elif argv[idx] == "--video-sub" or argv[idx] == "-s":
args["video_with_sub_mode"] = True
elif argv[idx] == "--phrases" or argv[idx] == "-ph":
args["phrase_mode"] = True
if idx + 1 < len(argv):
@@ -332,6 +435,11 @@ def parse_args(argv):
idx += 1
except ValueError:
pass
elif argv[idx] == "--mpv-options" or argv[idx] == "-m":
if idx + 1 >= len(argv):
return False
args["mpv_options"] = argv[idx + 1]
idx += 1
else:
return False
@@ -343,30 +451,36 @@ def parse_args(argv):
return args
def usage():
print "python videogrep.py -i <media_dir> <phrase>"
print "python videogrep.py -i <media_dir> _init_"
print "Usage: playphrase -i <media_dir> <phrase>"
print ""
print "Init: playphrase -i <media_dir> _init_"
print ""
print "Additional options:"
print "-ph, --phrases GAP_BETWEEN_PHRASES", "\t", "move start time of the clip to the beginning of the current phrase. Value is optional (default=1.75 seconds)"
print "-l, --limit", "\t", "maximum duration of the phrase (default=30 seconds)"
print "-p, --padding", "\t", "padding in seconds to add to the start and end of each clip (default=0.0 seconds)"
print "-e, --ending", "\t", "play only matching lines (or phrases)"
print "-r, --randomize", "\t", "randomize the clips"
print "-o, --output", "\t", "name of the file in which output of \'grep\' command will be written"
print "-d, --demo", "\t", "only show grep results"
print "-ph, --phrases GAP_BETWEEN_PHRASES", " ", "move start time of the clip to the beginning of the current phrase. Value is optional (default=1.25 seconds)"
print "-l, --limit", " ", "maximum duration of the phrase (default=60 seconds)"
print "-p, --padding", " ", "padding in seconds to add to the start and end of each clip (default=0.0 seconds)"
print "-e, --ending", " ", "play only matching lines (or phrases)"
print "-r, --randomize", " ", "randomize the clips"
print "-o, --output", " ", "name of the file in which output of \'grep\' command will be written"
print "-d, --demo", " ", "only show grep results"
print "-a, --audio", " ", "create audio fragments"
print "-v, --video", " ", "create video fragments"
print "-s, --video-sub", " ", "create video fragments with subtitles"
print "-m, --mpv-options OPTIONS", " ", "mpv player options"
if __name__ == '__main__':
os.environ["PATH"] += os.pathsep + "." + os.sep + "utils" + os.sep + "grep"
os.environ["PATH"] += os.pathsep + "." + os.sep + "utils" + os.sep + "mpv"
os.environ["PATH"] += os.pathsep + "." + os.sep + "utils" + os.sep + "ffmpeg"
args = parse_args(sys.argv[1:])
if args != False:
if args["search_phrase"] == "_init_":
init(args["media_dir"])
init(args["media_dir"], args["limit"])
else:
if need_update(args["media_dir"]):
print "WARNING: number of '.srt' and '.txt' files doesn't match. Maybe you need to use 'videogrep <media_dir> _init_'."
print "WARNING: number of '.srt' and '.txt' files doesn't match. Maybe you need to use 'playphrase <media_dir> _init_'."
main(args["media_dir"], args["search_phrase"], args["phrase_mode"], args["phrases_gap"], args["padding"], args["limit"], args["output_file"], args["ending_mode"], args["randomize_mode"], args["demo_mode"])
main(args["media_dir"], args["search_phrase"], args["phrase_mode"], args["phrases_gap"], args["padding"], args["limit"], args["output_file"], args["ending_mode"], args["randomize_mode"], args["demo_mode"], args["mpv_options"], args["audio_mode"], args["video_mode"], args["video_with_sub_mode"])
else:
usage()
+21
View File
@@ -0,0 +1,21 @@
@echo off
setlocal EnableDelayedExpansion
set media_dir="J:\English Movies"
for /L %%n in (1,0,1) do (
set /p phrase="Phrase: "
if /I "!phrase!"=="q" call :stop
if /I "!phrase!"=="x" call :stop
if /I "!phrase!"=="quit" call :stop
if /I "!phrase!"=="exit" call :stop
python playphrase.py --input %media_dir% "!phrase!"
)
:stop
call :__stop 2>nul
:__stop
() creates a syntax error, quits the batch
Executable
+19
View File
@@ -0,0 +1,19 @@
#!/bin/bash
media_dir="/media/nickolay/9A043D5E043D3F17/English Movies"
while true
do
read -p "Phrase: " -r phrase
if [ "$phrase" = "q" ]; then
exit 0
elif [ "$phrase" = "x" ]; then
exit 0
elif [ "$phrase" = "quit" ]; then
exit 0
elif [ "$phrase" = "exit" ]; then
exit 0
else
python "playphrase.py" --input "$media_dir" "$phrase"
fi
done