From e92a9a7e771e436aa81745c337092e1f9b46c2f5 Mon Sep 17 00:00:00 2001 From: inigoortega Date: Sun, 8 Mar 2020 17:29:29 +0100 Subject: [PATCH] NOW telegram working properly and script updated --- bin/telegram-loop | 11 +++ scripts/telegram-reply.sh | 2 +- scripts/watch-last-videos-from-subs.sh | 104 +++++++++++++++++++++---- 3 files changed, 101 insertions(+), 16 deletions(-) create mode 100755 bin/telegram-loop diff --git a/bin/telegram-loop b/bin/telegram-loop new file mode 100755 index 0000000..625a105 --- /dev/null +++ b/bin/telegram-loop @@ -0,0 +1,11 @@ +#!/usr/bin/env sh + +while [ 1 ]; do + $TELEGRAM -startintray +done & + +# +# error: : cannot open +# error: : cannot open +# error: : cannot open +# diff --git a/scripts/telegram-reply.sh b/scripts/telegram-reply.sh index 8ca797a..ebed786 100644 --- a/scripts/telegram-reply.sh +++ b/scripts/telegram-reply.sh @@ -1,6 +1,6 @@ #!/usr/bin/env sh -telegram-desktop & +telegram-desktop iterations=100 diff --git a/scripts/watch-last-videos-from-subs.sh b/scripts/watch-last-videos-from-subs.sh index e9cc0c9..577d07f 100644 --- a/scripts/watch-last-videos-from-subs.sh +++ b/scripts/watch-last-videos-from-subs.sh @@ -1,8 +1,55 @@ #!/usr/bin/env sh +usage() { + echo "Usage: $0 [-f ] [-u] [-h]" 1>&2 + echo "" 1>&2 + printf \ + "\tThis program manages your subscriptions with the given file with -f or\n" 1>&2 + printf \ + "\tby default using \$YT_SUBS or \$HOME/yt-subs, respectively.\n\n" 1>&2 + printf "\t-u To update now previous video upload speeds\n" 1>&2 + printf \ + "\t-e To play the videos when at the end instead of progressivaly\n" 1>&2 + printf "\t-h Show this help text\n" 1>&2 + exit 1 +} + +while getopts ":uf:" option; do + case "${option}" in + u) + update_now="1" + ;; + e) + play_at_the_end="1" + ;; + f) + subs_file="${OPTARG}" + ;; + *) + usage + ;; + esac +done +shift $((OPTIND-1)) + videos_file="/tmp/wlvfs_videos" -grep -vE '^#|^$' yt-subs | while read line; do +if [ -z "$subs_file" ]; then + if [ -z "$YT_SUBS" ]; then + subs_file="$HOME/yt-subs" + else + subs_file="$YT_SUBS" + fi +fi + +already_updated=$(grep "^!updated" "$subs_file") + +if [ "$(echo "$(date +%j) % 14" | bc)" -ne 0 ] && [ "$already_updated" ]; then + sed -i '/!updated/d' "$subs_file" +fi + + +grep -vE '^#|^$' "$subs_file" | while read line; do channel=$(echo "$line" | awk '{print $1}') last_video=$(echo "$line" | awk '{print $2}') upload_frequency=$(echo "$line" | awk '{print $3}') @@ -29,46 +76,73 @@ grep -vE '^#|^$' yt-subs | while read line; do fi sed -E \ - "s|($channel)(\t$last_video)?(\t$upload_frequency)?(\t$prev_upload_frequency)?|$channel\t$new_last_video\t$new_upload_frequency\t$new_prev_upload_frequency|" \ - yt-subs -i + "s|\ + ($channel)(\t$last_video)?\ + (\t$upload_frequency)?(\t$prev_upload_frequency)?\ + |\ + $channel\t$new_last_video\t\ + $new_upload_frequency\t$new_prev_upload_frequency\ + |" \ + "$subs_file" -i fi done -grep -vE '^#|^$' yt-subs | sed -E 's|([^\t]+)(\t)([^\t]+)(\t)([^\t]+)(\t)([^\t]+)|\7\t\1\t\3\t\5|g' | sort -rg | while read line; do +grep -vE '^#|^$|^!' "$subs_file" | \ + sed -E 's|([^\t]+)(\t)([^\t]+)(\t)([^\t]+)(\t)([^\t]+)|\7\t\1\t\3\t\5|g' \ + | sort -rg | while read line; do channel=$(echo "$line" | awk '{print $2}') last_video=$(echo "$line" | awk '{print $3}') prev_upload_frequency=$(echo "$line" | awk '{print $1}') upload_frequency=$(echo "$line" | awk '{print $4}') - echo "Processing: $channel" + echo "Processing: $channel on Preference: $prev_upload_frequency" temp="/tmp/wlvfs" dash termscripts/channel-videos-after.sh \ "https://invidio.us/channel/$channel" "$last_video" | tee "$temp" | \ while read video; do - # $VIDEOPLAYER "ytdl://$video" + printf "\tFound video: %s\n" "$video" if [ ! -f "$videos_file" ]; then - printf "\tFound video: %s\n" "$video" echo "ytdl://$video" >> $videos_file - (dash termscripts/play-videos-from-file.sh "$videos_file" && \ - rm "$videos_file") & + if [ -z "$play_at_the_end" ]; then + (dash termscripts/play-videos-from-file.sh "$videos_file"&& \ + rm "$videos_file") & + fi else echo "ytdl://$video" >> $videos_file fi done new_last_video=$(head -n 1 "$temp") [ -z "$new_last_video" ] && new_last_video="$last_video" - new_upload_frequency=$(( $(wc -l "$temp" | awk '{print $1}') + $upload_frequency )) + new_upload_frequency=\ + $(( $(wc -l "$temp" | awk '{print $1}') + $upload_frequency )) - if [ $(( $(date +%V) % 3 )) -eq 0 ]; then + if [ "$update_now" ] || \ + ([ "$(echo "$(date +%j) % 14" | bc)" -eq 0 ] && [ ! "$already_updated" ]) + then sed \ - "s|$channel\t$last_video\t$upload_frequency\t$prev_upload_frequency|$channel\t$new_last_video\t0\t$new_upload_frequency|" \ - yt-subs -i + "s|\ + $channel\t$last_video\ + \t$upload_frequency\t$prev_upload_frequency\ + |\ + $channel\t$new_last_video\ + \t0\t$new_upload_frequency\ + |" \ + "$subs_file" -i else sed \ - "s|$channel\t$last_video\t$upload_frequency\t$prev_upload_frequency|$channel\t$new_last_video\t$new_upload_frequency\t$prev_upload_frequency|" \ - yt-subs -i + "s|$channel\t$last_video\ + \t$upload_frequency\t$prev_upload_frequency\ + |$channel\t$new_last_video\ + \t$new_upload_frequency\t$prev_upload_frequency\ + |" \ + "$subs_file" -i fi done + + +if [ "$(echo "$(date +%j) % 14" | bc)" -eq 0 ] && [ ! "$already_updated" ]; then + echo "!updated" >> "$subs_file" +fi