From ad39adc15bee8f8cf6fefd9c1047e5f2cd4b8d7b Mon Sep 17 00:00:00 2001 From: Tait Hoyem <44244401+TTWNO@users.noreply.github.com> Date: Fri, 19 Jul 2019 15:00:30 +0000 Subject: [PATCH] Add yt script for surf web browser --- yt/yt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100755 yt/yt diff --git a/yt/yt b/yt/yt new file mode 100755 index 0000000..9598be0 --- /dev/null +++ b/yt/yt @@ -0,0 +1,19 @@ +#!/bin/sh +format="" # leave empty for default +player="mpv --quiet --geometry=50%:50% --keep-open --index default" +tmpdir="$HOME/tmp" + +url="$1" +filepath="$tmpdir/$(youtube-dl --id --get-filename $format $url)" + +youtube-dl -c -o $filepath $format $url & +echo $! > $filepath.$$.pid + +while [ ! -r $filepath ] && [ ! -r $filepath.part ]; do + echo "Waiting for youtube-dl..." + sleep 3 +done + +[ -r $filepath.part ] && $player $filepath.part || $player $filepath +kill $(cat $filepath.$$.pid) +rm $filepath.$$.pid