Going through pages after the initial search
Hello,
I would like to know if it is possible to go through pages after doing the search. Maybe the video I want is not in the first whatever $pages_to_scrape is, so I want to see more videos without existing, changing the value of --pages, and then running it again, and again, and again. I do not think this feature is implemented yet, I could find something similar in neither the documentation (ytfzf.1 and ytfzf.5) nor the issues. I think it may be a keybind (like alt-p) that increases the number of pages and reloads automatically.
Thanks for the time.
So I implemented this because in my head it wouldn't add a lot of complexity and it didn't, problem is with thumbnails. I'm not sure the best way to handle downloading the new ones. I think in order to implement this properly we'd have to refactor when thumbnails are downloaded.
if you want my buggy kinda incomplete version you can do this
- write the patch to a file
- run these commands
git clone https://github.com/pystardust/ytfzf
cd ytfzf
patch < patch_file
./ytfzf ...
patch:
: "${search_again_shortcut:=alt-s}"
: "${custom_shortcut_binds=}"
-: "${shortcut_binds:=Enter,double-click,${download_shortcut},${video_shortcut},${audio_shortcut},${detach_shortcut},${print_link_shortcut},${show_formats_shortcut},${info_shortcut},${search_again_shortcut},${custom_shortcut_binds}}"
+: "${shortcut_binds:=Enter,double-click,${download_shortcut},${video_shortcut},${audio_shortcut},${detach_shortcut},${print_link_shortcut},${show_formats_shortcut},${info_shortcut},${search_again_shortcut},${custom_shortcut_binds},alt-p}"
#number of columns (characters on a line) the external menu can have
: ${external_menu_len:=210}
@@ -627,7 +627,7 @@ scrape_invidious_search () {
pagetype=$3
page_num=$4
- _cur_page=1
+ _cur_page=${5:-1}
while [ ${_cur_page} -le $page_num ]; do
_tmp_json="${session_temp_dir}/yt-search-$_cur_page.json"
@@ -914,6 +914,10 @@ handle_keypress () {
$print_link_shortcut) info_to_print="L"; exit_on_info_to_print=1 ;;
$show_formats_shortcut) show_formats=1 ;;
$info_shortcut) exit_on_info_to_print=1; info_to_print="VJ" ;;
+ alt-p)
+ pages_to_scrape=$((pages_to_scrape+1))
+ scrape_invidious_search "$_search" "$ytfzf_video_json_file" "search" "$pages_to_scrape" "$_cur_page"
+ $(printf "%s" "interface_$interface" | sed 's/-/_/g' | sed 's/^interface_$/interface_text/') "$ytfzf_video_json_file" "$ytfzf_selected_urls" ;;
$search_again_shortcut)
clean_up
make_search ""
@@ -1091,6 +1095,11 @@ get_ueberzug_positioning () {
preview_display_image () {
thumbnail_viewer=$1
id=$2
+ if [ ! -f "${thumb_dir}/${id}.jpg" ]; then
+ url=$(jq -r '.[]|select(.ID=="'"$id"'").thumbs' < "$video_json_file")
+ curl -fLZ -s "$url" > "${thumb_dir}/${id}.jpg"
+ [ $? -eq 2 ] && curl -fL -s "$url" > "${thumb_dir}/${id}.jpg"
+ fi
case $thumbnail_viewer in
ueberzug)
get_ueberzug_positioning "$FZF_PREVIEW_COLUMNS" "$FZF_PREVIEW_LINES" "$fzf_preview_side"
This is working nicely. The patch, however, is not complete, running it results patch: **** Only garbage was found in the patch input.. It needs to be in the following form (I also modified it a bit):
diff --git a/ytfzf b/ytfzf
index 386f205..3471a0b 100755
--- a/ytfzf
+++ b/ytfzf
@@ -206,10 +206,11 @@ search_prompt_menu_wrapper () {
: "${print_link_shortcut:=alt-l}"
: "${show_formats_shortcut:=alt-f}"
: "${info_shortcut:=alt-i}"
+: "${new_page_shortcut:=alt-p}"
: "${search_again_shortcut:=alt-s}"
: "${custom_shortcut_binds=}"
-: "${shortcut_binds:=Enter,double-click,${download_shortcut},${video_shortcut},${audio_shortcut},${detach_shortcut},${print_link_shortcut},${show_formats_shortcut},${info_shortcut},${search_again_shortcut},${custom_shortcut_binds}}"
+: "${shortcut_binds:=Enter,double-click,${download_shortcut},${video_shortcut},${audio_shortcut},${detach_shortcut},${print_link_shortcut},${show_formats_shortcut},${info_shortcut},${new_page_shortcut},${search_again_shortcut},${custom_shortcut_binds}}"
#number of columns (characters on a line) the external menu can have
: ${external_menu_len:=210}
@@ -627,7 +628,7 @@ scrape_invidious_search () {
pagetype=$3
page_num=$4
- _cur_page=1
+ _cur_page=${5:-1}
while [ ${_cur_page} -le $page_num ]; do
_tmp_json="${session_temp_dir}/yt-search-$_cur_page.json"
@@ -914,6 +915,10 @@ handle_keypress () {
$print_link_shortcut) info_to_print="L"; exit_on_info_to_print=1 ;;
$show_formats_shortcut) show_formats=1 ;;
$info_shortcut) exit_on_info_to_print=1; info_to_print="VJ" ;;
+ $new_page_shortcut)
+ pages_to_scrape=$((pages_to_scrape+1))
+ scrape_invidious_search "$_search" "$ytfzf_video_json_file" "search" "$pages_to_scrape" "$_cur_page"
+ $(printf "%s" "interface_$interface" | sed 's/-/_/g' | sed 's/^interface_$/interface_text/') "$ytfzf_video_json_file" "$ytfzf_selected_urls" ;;
$search_again_shortcut)
clean_up
make_search ""
@@ -1091,6 +1096,11 @@ get_ueberzug_positioning () {
preview_display_image () {
thumbnail_viewer=$1
id=$2
+ if [ ! -f "${thumb_dir}/${id}.jpg" ]; then
+ url=$(jq -r '.[]|select(.ID=="'"$id"'").thumbs' < "$video_json_file")
+ curl -fLZ -s "$url" > "${thumb_dir}/${id}.jpg"
+ [ $? -eq 2 ] && curl -fL -s "$url" > "${thumb_dir}/${id}.jpg"
+ fi
case $thumbnail_viewer in
ueberzug)
get_ueberzug_positioning "$FZF_PREVIEW_COLUMNS" "$FZF_PREVIEW_LINES" "$fzf_preview_side"
I think in order to implement this properly we'd have to refactor when thumbnails are downloaded.
I agree. Despite that, the current implementation is "fine" for now.
The patch, however, is not complete
oops sorry.
Despite that, the current implementation is "fine" for now.
Ill probably fiddle around with it for a bit
Should've mentioned this earlier, but I also have plans to make page scraping asynchronous, so you could run ytfzf --pages=100 ... and it'll take just as long as ytfzf ... (although it will use more resources), I may also add a thread cap so let's say you don't want more than 50 forks you could make it limit to 50 forks.
The reason i'm mentioning this is that it almost makes alt-p redundant because you can scrape so many pages quickly.
My above comment has been pushed to master as version 2.2.alpha-3, feel free to update and try ytfzf --pages=50 ... (the default max thread limit is 20 you can change that with --max-threads=.)
In the development branch you can now use alt-p with invidious searches, and it should be in the next update.