forked from axiom-team/astroport
106 lines
4.2 KiB
Bash
Executable File
106 lines
4.2 KiB
Bash
Executable File
#!/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/miam/$timestamp
|
|
########################################################################
|
|
'
|
|
######## YOUTUBE-DL ##########
|
|
if [[ ! $(which youtube-dl) ]]; then
|
|
sudo curl -s 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 $(whoami) /usr/local/bin/youtube-dl
|
|
fi
|
|
|
|
mkdir -p ~/.zen/miam/
|
|
|
|
self=$(sbotc whoami | jq -r .id) || exit 1
|
|
[[ "$self" == "" ]] && 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)
|
|
[ -s ~/.zen/zenyta.last.ts ] && last_ts=$(cat ~/.zen/zenyta.last.ts) || last_ts=$((current_ts - 24*3600*1000)) # 24h ago
|
|
last_ts=$((last_ts + 10))
|
|
|
|
echo "Hi, i am [$self_name]($self)
|
|
last timestamp: $last_ts"
|
|
echo '
|
|
a u d i o
|
|
_ _
|
|
__ _ _ _ __| | (_) ___
|
|
/ _` | | || | / _` | | | / _ \
|
|
\__,_| \_,_| \__,_| |_| \___/
|
|
|
|
'
|
|
|
|
|
|
#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"'}}}]}')
|
|
[[ $messages == "" ]] && messages=$(sbotc query.read '{"query":[{"$filter":{"value":{"author": "'"$WHOAMI"'", "content":{"type":"zenyta"}}}}]}') || exit 1
|
|
while read -r msg
|
|
do
|
|
# EXTRACT CMD PARAM
|
|
msg_key=$(printf %s "$msg" | jq -r .key)
|
|
author=$(printf %s "$msg" | jq -r .value.author)
|
|
timestamp=$(printf %s "$msg" | jq -r .value.timestamp)
|
|
|
|
# TEST CURRENT NODE last_ts
|
|
[[ $timestamp == $last_ts ]] && echo "ALREADY DONE" && continue
|
|
|
|
# SWARM REFRESH
|
|
$MY_PATH/ipfs_SWARM_refresh.sh
|
|
# SWARM ALREADY DONE
|
|
CHECKSWARM=$(grep -Rwl "$timestamp" ~/.zen/ipfs_swarm/.Qm*/TAG/*/_tag.zensource | tail -n 1 | cut -f 6 -d '/')
|
|
# OR SWARM PROCESS IN ACTION
|
|
[[ ! $CHECKSWARM ]] && $(grep -Rwl "$timestamp" ~/.zen/ipfs_swarm/.Qm*/TAG/process.timestamp.ssb | tail -n 1 | cut -f 6 -d '/')
|
|
[[ $CHECKSWARM ]] \
|
|
&& echo "$timestamp ALREADY on NODE $CHECKSWARM CONTINUE" \
|
|
&& echo "$timestamp" > ~/.zen/zenyta.last.ts \
|
|
&& continue
|
|
|
|
# ANTI DOUBLE COPY START
|
|
echo "$timestamp" > ~/.zen/ipfs/.$ipfsnodeid/process.timestamp.ssb
|
|
$MY_PATH/ipfs_SWARM_refresh.sh
|
|
# ANTI DOUBLE COPY
|
|
|
|
msg_root=$(printf %s "$msg" | jq -r .value.content.root)
|
|
msg_branch=$(printf %s "$msg" | jq -r .value.content.branch)
|
|
msg_text=$(printf %s "$msg" | jq -r .value.content.text)
|
|
msg_ytdlurl=$(echo $msg_text | egrep -o 'https?://[^ ]+' | grep you | cut -d '\' -f 1 | tail -n 1)
|
|
|
|
# YOUTUBE-DL AUDIO
|
|
|
|
[[ $timestamp ]] && mkdir -p ~/.zen/miam/$timestamp
|
|
|
|
[[ $msg_ytdlurl ]] && /usr/local/bin/youtube-dl -x --audio-format mp3 \
|
|
--write-thumbnail --write-info-json --add-metadata --embed-thumbnail \
|
|
--no-mtime -o "~/.zen/miam/$timestamp/%(id)s.%(ext)s" $msg_ytdlurl
|
|
|
|
# REFERENCE msg_key AND timestamp
|
|
[[ $timestamp ]] && echo "$((timestamp + 1))" > ~/.zen/zenyta.last.ts
|
|
[[ $msg_key ]] && echo "$msg_key" > ~/.zen/miam/$timestamp/msg_key
|
|
|
|
$MY_PATH/miam_miam.sh "$timestamp"
|
|
|
|
# ANTI DOUBLE COPY END
|
|
echo "$timestamp" > ~/.zen/ipfs/.$ipfsnodeid/process.timestamp.ssb
|
|
$MY_PATH/ipfs_SWARM_refresh.sh
|
|
# ANTI DOUBLE COPY
|
|
|
|
done < <(printf '%s\n' "$messages")
|