Mesh decentralized Unified P2P Fat Protocol Layer. Connectors between Libre Money, ScuttleButt, IPFS, ... Salamalec between Nodes and Human.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

107 lines
4.7 KiB

#!/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
echo "sbotc backlinks.read '{\"query\":[{\"\$filter\":{\"dest\":\"#zenyta\",\"value\":{\"content\":{\"type\":\"post\"}},\"timestamp\":{\"\$gt\":'\"$last_ts\"'}}}]}'"
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"}}}}]}') && echo "sbotc query.read '{\"query\":[{\"\$filter\":{\"value\":{\"author\": \"'"$WHOAMI"'\", \"content\":{\"type\":\"zenyta\"}}}}]}'"
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 -lt $last_ts ]] && echo "$last_ts: ALREADY DONE $msg_key timestamp is $timestamp " && continue
# SWARM REFRESH
$MY_PATH/ipfs_SWARM_refresh.sh
# SWARM ALREADY DONE IT ??
# IS LIKE "SELECT FROM ipfs_swarm WHERE _tag.zensource=$timestamp"(or something like that in SQL), means a ZenTag already exists.
CHECKSWARM=$(grep -Rwl "$timestamp" ~/.zen/ipfs_swarm/.12D3KooW*/TAG/*/_tag.zensource | tail -n 1 | cut -f 6 -d '/')
# OR SWARM PROCESS IN ACTION (NB: copy tasks must be asynchronous in swarm)
[[ ! $CHECKSWARM ]] && CHECKSWARM=$(grep -Rwl "$timestamp" ~/.zen/ipfs_swarm/.12D3KooW*/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
rm ~/.zen/ipfs/.$ipfsnodeid/process.timestamp.ssb
$MY_PATH/ipfs_SWARM_refresh.sh
# ANTI DOUBLE COPY
done < <(printf '%s\n' "$messages")