blob: 60c4e2db73933a2f2a95b9af1bf465712dd3afdb (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
#!/usr/bin/env dash
# shellcheck source=/dev/null
SHELL_LIBRARY_VERSION="1.10.2" . %SHELL_LIBRARY_PATH
TASK_UUID=ce4f9e07-8324-4570-8be6-967955e9271e
# these are used in version()
AUTHORS="Soispha"
YEARS="2023"
NAME="neorg"
help_text="
# Commands:
# w, watch <id> = watch id
# d, drop <id> = mark id as watched
# p, pick <id> = leave id as is; This is a noop
#
# These lines can be re-ordered; they are executed from top to bottom.
# vim: ft=gitrebase"
help() {
cat << EOF
A help script to make selecting videos to play for ytcc easier.
USAGE:
$NAME [OPTIONS] [COMMAND]
OPTIONS:
--help | -h
Display this help and exit.
--version | -v
Display version and copyright information and exit.
COMMANDS:
order MODE
Select the ordering mode.
ARGUMENTS:
MODE := date | raw
date will sort descending by publishing date,
whilest raw esxposes the ytcc interface. See
the help info of the 'ytcc list --help'
'--order-by' option for more details.
EOF
}
for arg in "$@"; do
case "$arg" in
"--help")
help;
exit 0;
;;
"--version")
version;
exit 0;
;;
esac
done
if [ -n "$1" ]; then
case "$1" in
"order")
shift 1;
case "$1" in
"date")
set -- "--order-by" "publish_date" "desc"
oder_mode_set=true;
;;
"raw")
shift 1;
if [ -n "$1" ]; then
[ -z "$2" ] && die "A first argument to 'order raw' requires a second"
set -- "--order-by" "$1" "$2"
fi
oder_mode_set=true;
;;
*)
die "'$1' is not a valid subcommand for 'order'; See '--help' for a list";
;;
esac
;;
*)
die "'$1' is not a valid subcommand; See '--help' for a list";
;;
esac
fi
# Set the default ordering mode
[ -z "$oder_mode_set" ] && set -- "--order-by" "publish_date" "desc"
table="$(ytcc --output json list "$@" | jq --raw-output 'map("pick \(.id) \(.title) (\(.playlists | map(.name) | join(", "))) [\(.duration | gsub("^\\s+|\\s+$";""))]") | join("\n")')"
selection_file="$(mktmp)";
cleanup() {
task stop "$TASK_UUID"
}
trap cleanup EXIT
task start "$TASK_UUID"
echo "$table" > "$selection_file";
echo "$help_text" >> "$selection_file";
$EDITOR "$selection_file"
is_first=true;
while read -r line; do
cmd="$(echo "$line" | awk '{print $1}')";
case "$cmd" in
"" )
# An empty line, simply ignore it
;;
"#")
# This is a comment, do nothing here
;;
"pick" | "p")
# noop do nothing here
;;
"drop" | "d")
id="$(echo "$line" | awk '{print $2}')";
ytcc mark "$id";
dbg "Marked as watched: $id"
;;
"watch" | "w")
id="$(echo "$line" | awk '{print $2}')";
if [ "$is_first" = "true" ]; then
set -- "$id"
else
set -- "$@" "$id"
fi
dbg "Added to be watched: $id"
is_first=false
;;
esac
done < "$selection_file"
[ -n "$1" ] && ytc "id" "$@";
# vim: ft=sh
|