Merge branch 'add-datefmt'
[sunny256-utils.git] / ydc
blobc35c80db03960df580cbeee3c6552ee62dc100e6
1 #!/bin/sh
3 #==============================================================================
4 # ydc
5 # File ID: cc9e58bc-9e74-11e8-ae29-db5caa6d21d3
7 # Wrapper around the yd* youtube-dl scripts, checks that the video hasn't been
8 # downloaded before.
10 # Author: Øyvind A. Holm <sunny@sunbase.org>
11 # License: GNU General Public License version 2 or later.
12 #==============================================================================
14 progname=ydc
15 VERSION=0.2.4
17 T_BOLD=$(tput bold)
18 T_RED=$(tput setaf 1)
19 T_RESET=$(tput sgr0)
21 # FIXME: Hardcoding
22 dellog=/tmp/musikk-del.log
23 delloglock="$dellog.lock"
24 repo=/home/annex/musikk
26 if test "$1" = "--version"; then
27 echo $progname $VERSION
28 exit 0
31 if test "$1" = "-h" -o "$1" = "--help"; then
32 cat <<END
34 Wrapper around the yd* youtube-dl scripts, checks that the video hasn't
35 been downloaded before. Works with links understood by the ydid(1)
36 script.
38 Usage: $progname [options] YDPROG
40 Options:
42 -h, --help
43 Show this help.
44 --version
45 Print version information.
47 END
48 exit 0
51 ydprog=$1
52 if [ -z "$ydprog" ]; then
53 echo $progname: Missing ydprog argument >&2
54 exit 1
57 until mkdir "$delloglock" 2>/dev/null; do
58 echo $progname: $delloglock: Waiting for lockdir >&2
59 sleep 1
60 done
62 cd "$repo" && (
63 git log --name-status --format= | grep ^D >"$dellog" || true
66 rmdir "$delloglock" || exit 1
68 while :; do
69 read -p "$ydprog URL: " orig_gr
70 test -z "$orig_gr" && continue
71 gr=$(ydid "$orig_gr")
72 test -z "$gr" && continue
73 echo grep -- $gr
74 (cd "$repo" && (find *; cat "$dellog")) | grep -- $gr ||
75 ($ydprog -- $(ydid -c "$orig_gr") &)
76 if ls | grep -q -- -$gr\\.temp\\.; then
77 echo -n "$T_RED$T_BOLD"
78 rm -v *-$gr*.temp.*
79 echo -n "$T_RESET"
81 done
83 # vim: set ts=8 sw=8 sts=8 noet fo+=w tw=79 fenc=UTF-8 :