astroport/zen/ssb_GET_zenyta.sh

79 lines
3.1 KiB
Bash
Raw Normal View History

2020-04-15 04:37:01 +02:00
#!/bin/bash
########################################################################
# Author: Fred (support@qo-op.com)
# Version: 2020.03.24
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
########################################################################
MY_PATH="`dirname \"$0\"`" # relative
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
ME="${0##*/}"
echo '
########################################################################
# \\///
# qo-op
############# '$MY_PATH/$ME'
########################################################################
# ex: ./'$ME'
# #zenyta = youtube-dl video to ~/.zen/zenyta/cache/$timestamp
########################################################################
'
######## YOUTUBE-DL ##########
if [[ ! $(which youtube-dl) ]]; then
sudo wget https://yt-dl.org/downloads/latest/youtube-dl -O /usr/local/bin/youtube-dl || err=1
sudo chmod a+rx /usr/local/bin/youtube-dl
sudo chown $USER /usr/local/bin/youtube-dl
fi
mkdir -p ~/.zen/zenyta/cache/
self=$(sbotc whoami | jq -r .id) || exit 1
g1self=$(echo $self | cut -d '@' -f 2 | cut -d '.' -f 1 | base64 -d | base58)
self_name=$(sbotc query.read '{"query":[{"$filter":{"value":{"author": "'"$self"'", "content":{"type":"about", "about": "'"$self"'"}}}}]}' | jq -r .value?.content?.name | grep -v null | tail -n 1)
ipfsnodeid=$(ipfs id -f='<id>\n')
current_ts=$(date -u +%s%N | cut -b1-13)
[ -f ~/.zen/zenyta/last.ts ] && last_ts=$(cat ~/.zen/zenyta/last.ts) || last_ts=$((current_ts - 10*24*3600*1000 - 1)) # 10*24h ago
echo "
_
____ ___ _ __ _ _ | |_ __ __
|_ / / _ \ | '_ \ | | | | | __| \ \ / /
/ / | __/ | | | | | |_| | | |_ \ V /
/___| \___| |_| |_| \__, | \__| \_/
|___/
last timestamp: $last_ts
"
#messages=$(sbotc messagesByType '{"type":"post","gt":'$last_ts'}')
# SEARCH "#zenyta" CMD in message text
messages=$(sbotc backlinks.read '{"query":[{"$filter":{"dest":"#zenyta","value":{"content":{"type":"post"}},"timestamp":{"$gt":'"$last_ts"'}}}]}')
while read -r msg
do
# EXTRACT CMD PARAM
author=$(printf %s "$msg" | jq -r .value.author)
# echo $author
timestamp=$(printf %s "$msg" | jq -r .value.timestamp)
[[ $timestamp == $last_ts ]] && echo "ALREADY DONE" && continue
# echo $timestamp
msg_root=$(printf %s "$msg" | jq -r .value.content.root)
# echo $msg_root
msg_branch=$(printf %s "$msg" | jq -r .value.content.branch)
# echo $msg_branch
msg_text=$(printf %s "$msg" | jq -r .value.content.text)
# echo $msg_text
msg_ytdlurl=$(echo $msg_text | egrep -o 'https?://[^ ]+' | cut -d '\' -f 1 | tail -n 1)
# echo $msg_ytdlurl
# YOUTUBE-DL AUDIO
mkdir -p ~/.zen/zenyta/cache/$timestamp
/usr/local/bin/youtube-dl -x --audio-format mp3 \
--write-thumbnail --write-info-json --add-metadata --embed-thumbnail \
--no-mtime -o "~/.zen/zenyta/cache/$timestamp/%(title)s.%(id)s.%(ext)s" $msg_ytdlurl
# MEMORIZE timestamp
#echo "$timestamp" > ~/.zen/zenyta/last.ts
rm ~/.zen/zenyta/last.ts
done < <(printf '%s\n' "$messages")