add [-n] option, bugfixes
This commit is contained in:
21
subs
21
subs
@@ -15,7 +15,7 @@
|
|||||||
: "${SUBS:=${XDG_CACHE_HOME:-~/.cache}/subs}"
|
: "${SUBS:=${XDG_CACHE_HOME:-~/.cache}/subs}"
|
||||||
: "${SUBS_LINKS:=$SUBS/links}"
|
: "${SUBS_LINKS:=$SUBS/links}"
|
||||||
: "${SUBS_CACHE:=$SUBS/cache}"
|
: "${SUBS_CACHE:=$SUBS/cache}"
|
||||||
: "${SUBS_SLEEP_VALUE:=0.05}" # raise this if you experience problems
|
: "${SUBS_SLEEP_VALUE:=0.1}" # raise this if you experience problems
|
||||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
SEP=^^^^^ # shouldn't need to change this
|
SEP=^^^^^ # shouldn't need to change this
|
||||||
# -/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/
|
# -/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/
|
||||||
@@ -26,7 +26,7 @@ die() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
die 'Usage: subs [-m no-video] [-g gen-links] [-u update-cache] [-d daemonize]'
|
die 'Usage: subs [-m no-video] [-g gen-links] [-u update-cache] [-d daemonize] [-n dont-play]'
|
||||||
}
|
}
|
||||||
|
|
||||||
# -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
|
# -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
|
||||||
@@ -142,6 +142,8 @@ update_subs() {
|
|||||||
mkdir -p "$SUBS_CACHE"
|
mkdir -p "$SUBS_CACHE"
|
||||||
|
|
||||||
total=$(wc -l <"$SUBS_LINKS")
|
total=$(wc -l <"$SUBS_LINKS")
|
||||||
|
set -- $total
|
||||||
|
total=$1
|
||||||
|
|
||||||
count=0
|
count=0
|
||||||
while read -r link ; do
|
while read -r link ; do
|
||||||
@@ -154,6 +156,8 @@ update_subs() {
|
|||||||
count=0
|
count=0
|
||||||
while [ "$count" -ne "$total" ] ; do
|
while [ "$count" -ne "$total" ] ; do
|
||||||
count=$(printf '%s\n' "$SUBS_CACHE"/* | wc -l)
|
count=$(printf '%s\n' "$SUBS_CACHE"/* | wc -l)
|
||||||
|
set -- $count
|
||||||
|
count=$1
|
||||||
printf "[%s/%s] waiting for fetch jobs to complete...\n" "$count" "$total"
|
printf "[%s/%s] waiting for fetch jobs to complete...\n" "$count" "$total"
|
||||||
sleep 0.5
|
sleep 0.5
|
||||||
done
|
done
|
||||||
@@ -197,11 +201,16 @@ get_sel() {
|
|||||||
*"$SEP$title$SEP"*)
|
*"$SEP$title$SEP"*)
|
||||||
url=${line##*$SEP}
|
url=${line##*$SEP}
|
||||||
if [ "$url" ] ; then
|
if [ "$url" ] ; then
|
||||||
printf 'playing: %s\n' "$url"
|
if [ "$DONT_PLAY" ] ; then
|
||||||
# Play the selection.
|
# just print the url
|
||||||
|
# (useful for piping to other programs)
|
||||||
|
printf '%s\n' "$url"
|
||||||
|
else
|
||||||
# shellcheck disable=2086
|
# shellcheck disable=2086
|
||||||
|
printf 'playing: %s\n' "$url"
|
||||||
exec mpv $MPV_OPTS "$url"
|
exec mpv $MPV_OPTS "$url"
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
break
|
break
|
||||||
esac
|
esac
|
||||||
done <"$SUBS_CACHE/$chan"
|
done <"$SUBS_CACHE/$chan"
|
||||||
@@ -213,6 +222,7 @@ daemonize() {
|
|||||||
daemon_file=${XDG_CACHE_HOME:-~/.cache}/subs_daemon.cache
|
daemon_file=${XDG_CACHE_HOME:-~/.cache}/subs_daemon.cache
|
||||||
if [ ! -f "$daemon_file" ] ; then
|
if [ ! -f "$daemon_file" ] ; then
|
||||||
cp -f "${SUBS_FILE:=~/files/subs.txt}" "$daemon_file"
|
cp -f "${SUBS_FILE:=~/files/subs.txt}" "$daemon_file"
|
||||||
|
gen_links
|
||||||
fi
|
fi
|
||||||
|
|
||||||
while true ; do
|
while true ; do
|
||||||
@@ -231,6 +241,9 @@ main() {
|
|||||||
mkdir -p "$SUBS"
|
mkdir -p "$SUBS"
|
||||||
|
|
||||||
case ${1#-} in
|
case ${1#-} in
|
||||||
|
n)
|
||||||
|
DONT_PLAY=true
|
||||||
|
;;
|
||||||
m)
|
m)
|
||||||
export MPV_OPTS="$MPV_OPTS --no-video"
|
export MPV_OPTS="$MPV_OPTS --no-video"
|
||||||
shift
|
shift
|
||||||
|
|||||||
Reference in New Issue
Block a user