Skip to content

Commit 0167891

Browse files
committed
readitlater: get tags together with title and duration in video
Signed-off-by: Carlo Lobrano <[email protected]>
1 parent eeb4c29 commit 0167891

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

readitlater.sh

+11-19
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ get_tags() {
5151
get_video_data_fallback() {
5252
command -v kdialog >/dev/null
5353
if [[ $? -eq 0 ]]; then
54-
DATA=$(kdialog --title ReadItLater --inputbox "description and duration (comma separated)")
54+
DATA=$(kdialog --title ReadItLater --inputbox "tags, description and duration (comma separated)")
5555
if [ $? -eq 0 ] && [ -n "$DATA" ]; then
5656
echo "$DATA"
5757
return 0
@@ -60,7 +60,7 @@ get_video_data_fallback() {
6060
fi
6161
command -v termux-setup-storage >/dev/null
6262
if [[ $? -eq 0 ]]; then
63-
DATA=$(termux-dialog text -t "ReadItLater" -i "description and duration (comma separated)" | jq -r .text)
63+
DATA=$(termux-dialog text -t "ReadItLater" -i "tags, description and duration (comma separated)" | jq -r .text)
6464
if [ $? -eq 0 ] && [ -n "$DATA" ]; then
6565
echo "$DATA"
6666
return 0
@@ -118,25 +118,17 @@ process_youtube() {
118118
return 0
119119
fi
120120

121-
custom_tags=`get_tags`
121+
values=$(get_video_data_fallback)
122122

123-
if [[ "$url" =~ "playlist" ]]; then
124-
title=$(yt-dlp --skip-download --print playlist_title "$url" | uniq)
125-
rc=$?
126-
title="$title playlist"
127-
else
128-
info=$(yt-dlp --skip-download --get-title --get-duration "$url")
129-
rc=$?
130-
title=$(echo "$info" | sed -n '1p')
131-
duration=$(echo "$info" | sed -n '2p')
132-
fi
123+
custom_tags=$(echo "$values" | cut -d"," -f1 | tr -d ' ')
124+
125+
title=$(echo "$values" | cut -d"," -f2)
126+
# remove trailing white spaces
127+
title=$(echo $title)
128+
129+
duration_minutes=$(echo "$values" | cut -d"," -f3 | tr -d ' ')
130+
duration=$((duration_minutes * 60))
133131

134-
if [ $rc -ne 0 ]; then
135-
values=$(get_video_data_fallback)
136-
title=$(echo "$values" | cut -d"," -f1)
137-
duration_minutes=$(echo "$values" | cut -d"," -f2)
138-
duration=$((duration_minutes * 60))
139-
fi
140132
if [ -z "$title" ] || [ -z "$duration" ]; then
141133
$WARNING "Could not process link: missing title or duration"
142134
exit 1

0 commit comments

Comments
 (0)