From b72c46c7a948d1d50cfe1103021e5f5117cef7d2 Mon Sep 17 00:00:00 2001 From: "i.ortega" Date: Thu, 2 Jul 2020 13:41:51 +0200 Subject: [PATCH] Now it is much faster --- scripts/channel-videos-after.sh | 15 +++++++++++---- scripts/no-response-timeout.sh | 4 ++-- wlvfs | 16 ++++++++++------ 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/scripts/channel-videos-after.sh b/scripts/channel-videos-after.sh index 3f5d1ec..a4219b5 100644 --- a/scripts/channel-videos-after.sh +++ b/scripts/channel-videos-after.sh @@ -6,11 +6,18 @@ scripts_folder=$(dirname "$(readlink -f "$0")") [ -n "$3" ] && dateafter="--dateafter $3" -sh "$scripts_folder/no-response-timeout.sh" -f 128 -r 10 \ - youtube-dl --get-id "$channel" $dateafter 2>/dev/null | - while read -r line && [ "$line" != "$last_watched_video" ]; do + +fifo="/tmp/channel-videos-after-fifo$(date +%s%N)" +mkfifo "$fifo" + +youtube-dl --get-id "$channel" $dateafter 2>/dev/null > "$fifo" & +ytdlp="$!" +while read -r line && [ "$line" != "$last_watched_video" ]; do echo "$line" -done +done < "$fifo" + +printf "\n" +kill "$!" # youtube-dl --get-id "$channel" | grep -B 4 "$last_watched_video" | tee /home/initega/test/test -a & diff --git a/scripts/no-response-timeout.sh b/scripts/no-response-timeout.sh index 27bbbdd..9eedf2a 100644 --- a/scripts/no-response-timeout.sh +++ b/scripts/no-response-timeout.sh @@ -39,7 +39,7 @@ command_pid="$!" cleanup() { kill "$command_pid" 2>/dev/null - rm "$fifo" + rm "$fifo" 2>/dev/null } trap cleanup TERM INT PIPE @@ -54,5 +54,5 @@ while read -r line; do echo "$line" done < "$fifo" -rm "$fifo" +rm "$fifo" 2>/dev/null kill "$checkpoint_pid" 2>/dev/null diff --git a/wlvfs b/wlvfs index cdf35d5..9dd9d21 100755 --- a/wlvfs +++ b/wlvfs @@ -42,11 +42,11 @@ done shift $((OPTIND-1)) scripts_folder="$(dirname "$(readlink -f "$0")")/scripts" -videos_file="$HOME/.local/share/wlvfs_videos" +videos_file="${XDG_DATA_HOME:-$HOME/.local/share}/wlvfs_videos" if [ -z "$subs_file" ]; then if [ -z "$YT_SUBS" ]; then - subs_file="$HOME/yt-subs" + subs_file="${XDG_CONFIG_HOME:-$HOME/.config}/yt-subs" else subs_file="$YT_SUBS" fi @@ -181,10 +181,14 @@ fi dateafter="$update_date" [ "$update_date" = "-" ] && dateafter="" + + fifo="/tmp/wlvfs$(date +%s%N)" + mkfifo "$fifo" + + sh "$scripts_folder/no-response-timeout.sh" -f 128 -r 10 \ sh "$scripts_folder/channel-videos-after.sh" \ - "https://youtube.com/channel/$channel" "$last_video" "$dateafter" | - tee "$temp" | - while read -r video; do + "https://youtube.com/channel/$channel" "$last_video" "$dateafter" | tee "$temp" > "$fifo" & + while read -r video && [ -n "$video" ]; do printf "\tFound video: %s\n" "$video" if [ ! -f "$videos_file" ]; then echo "ytdl://$video" >> "$videos_file" @@ -200,7 +204,7 @@ fi "$videos_file" } & fi - done + done < "$fifo" new_last_video=$(head -n 1 "$temp") if [ -z "$new_last_video" ]; then new_last_video="$last_video"