NOW telegram working properly and script updated

This commit is contained in:
inigoortega 2020-03-08 17:29:29 +01:00
parent 919eb03f6c
commit e92a9a7e77
3 changed files with 101 additions and 16 deletions

11
bin/telegram-loop Executable file
View File

@ -0,0 +1,11 @@
#!/usr/bin/env sh
while [ 1 ]; do
$TELEGRAM -startintray
done &
#
# error: : cannot open
# error: : cannot open
# error: : cannot open
#

View File

@ -1,6 +1,6 @@
#!/usr/bin/env sh
telegram-desktop &
telegram-desktop
iterations=100

View File

@ -1,8 +1,55 @@
#!/usr/bin/env sh
usage() {
echo "Usage: $0 [-f <file>] [-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