aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpystardust <notpiestardust@gmail.com>2021-03-02 11:56:59 +0530
committerpystardust <notpiestardust@gmail.com>2021-03-02 11:56:59 +0530
commit528385e4351b6b20ff6d29c538c14517cb715b98 (patch)
treef82cdf077865a57068112382298fe2b7b98aa2a1
parenta016e791b1995d7c90dc6a2e1f27ac457f5e5ec5 (diff)
parent826a61487af2071897a416396d49317888b9dde4 (diff)
downloadytfzf-528385e4351b6b20ff6d29c538c14517cb715b98.tar.gz
Merge branch 'Euro20179-n-flag'
-rw-r--r--README.md1
-rwxr-xr-xytfzf14
2 files changed, 11 insertions, 4 deletions
diff --git a/README.md b/README.md
index 57f1ebd..0e3b566 100644
--- a/README.md
+++ b/README.md
@@ -42,6 +42,7 @@ Usage: ytfzf <search query>
-l <search query> Loop: prompt selector again after video ends
-s <search query> After the video ends make another search
-L <search query> Prints the selected URL only, helpful for scripting
+ -n <link count> <search query> Prints selected URLs only (useful with -a or -r)
Use - instead of <query> for stdin
```
diff --git a/ytfzf b/ytfzf
index 3127476..aa8235b 100755
--- a/ytfzf
+++ b/ytfzf
@@ -43,6 +43,7 @@ printf " -r <search query> Auto play a random result, no selector\n";
printf " -l <search query> Loop: prompt selector again after video ends\n";
printf " -s <search query> After the video ends make another search \n";
printf " -L <search query> Prints the selected URL only, helpful for scripting\n";
+printf " -n <link count> <search query> Prints selected URLs only (useful with -a or -r)\n";
printf " Use - instead of <query> for stdin\n";
printf "\n"
printf " Option can be combines. Like\n"
@@ -277,10 +278,11 @@ scrape_fn () {
user_selection () {
[ $is_url -eq 1 ] && return
format_menu
+
if [ $auto_select -eq 1 ] ; then
- selected_data="$(echo "$videos_data" | sed 1q )" ;
+ selected_data="$(echo "$videos_data" | sed ${link_count}q )" ;
elif [ $random_select -eq 1 ] ; then
- selected_data="$(echo "$videos_data" | shuf -n 1)"
+ selected_data="$(echo "$videos_data" | shuf -n $link_count )"
elif [ $show_thumbnails -eq 1 ] ; then
dep_ck "ueberzug"
start_ueberzug
@@ -289,12 +291,13 @@ user_selection () {
else
selected_data="$(echo "$videos_data" | video_menu )"
fi
-
+
shorturls="$(echo "$selected_data" | sed -E -e 's_.*\|([^|]+) *$_\1_')"
[ -z "$shorturls" ] && exit;
urls=""
selected_data=""
while read surl; do
+ [ -z "$surl" ] && continue
urls="$urls\nhttps://www.youtube.com/watch?v=$surl"
# to get back untrucated titles from formatting
selected_data="$selected_data\n$(echo "$videos_data" | grep -m1 -e "$surl" )"
@@ -356,8 +359,9 @@ auto_select=0
random_select=0
search_again=0
show_format=0
+link_count=1
# OPT
-while getopts "LhDmdfxHarltsU:" opt; do
+while getopts "LhDmdfxHarltsn:U:" opt; do
case ${opt} in
h) helpinfo
exit;
@@ -390,6 +394,8 @@ while getopts "LhDmdfxHarltsU:" opt; do
;;
L) show_link_only=1
;;
+ n) link_count="$OPTARG"
+ ;;
U) [ -p "$FIFO" ] && preview_img "$OPTARG"; exit;
# This option is reserved for the script, to show image previews
# Not to be used by explicitly
Un proyecto texto-plano.xyz