corrections

This commit is contained in:
fred 2022-10-10 00:39:07 +02:00
parent 2418770b86
commit 2646c165f6
3 changed files with 85 additions and 79 deletions

View File

@ -187,7 +187,8 @@ done
MOATS=$(date -u +"%Y%m%d%H%M%S%4N") MOATS=$(date -u +"%Y%m%d%H%M%S%4N")
[[ $DIFF ]] && cp ~/.zen/game/players/$PLAYER/ipfs/moa/.chain ~/.zen/game/players/$PLAYER/ipfs/moa/.chain.$MOATS [[ $DIFF ]] && cp ~/.zen/game/players/$PLAYER/ipfs/moa/.chain \
~/.zen/game/players/$PLAYER/ipfs/moa/.chain.$(cat ~/.zen/game/players/$PLAYER/ipfs/moa/.moats)
TW=$(ipfs add -Hq ~/.zen/game/players/$PLAYER/ipfs/moa/index.html | tail -n 1) TW=$(ipfs add -Hq ~/.zen/game/players/$PLAYER/ipfs/moa/index.html | tail -n 1)
ipfs name publish --allow-offline -t 72h --key=$PLAYER /ipfs/$TW ipfs name publish --allow-offline -t 72h --key=$PLAYER /ipfs/$TW

View File

@ -23,40 +23,53 @@ WISHKEY="$2" ## IPNS KEY NAME - G1PUB - PLAYER ...
[[ ! $WISHKEY ]] && echo "Please provide IPFS publish key" && exit 1 [[ ! $WISHKEY ]] && echo "Please provide IPFS publish key" && exit 1
TWNS=$(ipfs key list -l | grep -w $WISHKEY | cut -d ' ' -f1) TWNS=$(ipfs key list -l | grep -w $WISHKEY | cut -d ' ' -f1)
# Extract tag=tube from TW into ~/.zen/tmp/tube.json # Extract tag=tube from TW into ~/.zen/tmp/$WISHKEY/tube.json
rm -f ~/.zen/tmp/tube.json MOATS=$(date -u +"%Y%m%d%H%M%S%4N")
tiddlywiki --verbose --load ${INDEX} --output ~/.zen/tmp --render '.' 'tube.json' 'text/plain' '$:/core/templates/exporters/JsonFile' 'exportFilter' '[tag[tube]]' mkdir -p ~/.zen/tmp/$WISHKEY
rm -f ~/.zen/tmp/$WISHKEY/tube.json
tiddlywiki --verbose --load ${INDEX} --output ~/.zen/tmp/$WISHKEY --render '.' 'tube.json' 'text/plain' '$:/core/templates/exporters/JsonFile' 'exportFilter' '[tag[tube]]'
## Extract URL from text field ## Extract URL from text field
for YURL in $(cat ~/.zen/tmp/tube.json | jq -r '.[].text' | grep 'http'); do for YURL in $(cat ~/.zen/tmp/$WISHKEY/tube.json | jq -r '.[].text' | grep 'http'); do
echo "Detected $YURL" echo "Detected $YURL"
echo "Start Downloading" echo "Extracting video playlist"
mkdir -p ~/.zen/tmp/tube
### GETTING ALL VIDEO IDs (for playlist copy) ### GETTING ALL VIDEO IDs (for playlist copy)
yt-dlp --print "%(id)s" "${YURL}" > ~/.zen/tmp/ytids yt-dlp --print "%(id)s" "${YURL}" >> ~/.zen/tmp/$WISHKEY/ytids.$MOATS
done # FINISH YURL loop
###################################################################
###################################################################
while read YID; while read YID;
do do
[[ -f ~/.zen/tmp/$WISHKEY/$YID.TW.json ]] && echo "Tiddler json already existing : ~/.zen/tmp/$WISHKEY/$YID.TW.json" && continue
# SINGLE VIDEO YURL # SINGLE VIDEO YURL
ZYURL="https://www.youtube.com/watch?v=$YID"; ZYURL="https://www.youtube.com/watch?v=$YID";
echo "YOUTUBE : $ZYURL"
TITLE="$(yt-dlp --print "%(title)s" "${ZYURL}")" TITLE="$(yt-dlp --print "%(title)s" "${ZYURL}")"
TITLE=${TITLE//[^A-zÀ-ÿ0-9 ]/} TITLE=${TITLE//[^A-zÀ-ÿ0-9 ]/}
echo "OK! Going to download $TITLE.mp4 from $ZYURL"
[[ ! $TITLE ]] && continue [[ ! $TITLE ]] && continue
echo ".... Downloading $TITLE.mp4"
# https://github.com/yt-dlp/yt-dlp#format-selection-examples # https://github.com/yt-dlp/yt-dlp#format-selection-examples
# SUBS ? --write-subs --write-auto-subs --sub-langs "fr, en, en-orig" --embed-subs # SUBS ? --write-subs --write-auto-subs --sub-langs "fr, en, en-orig" --embed-subs
# (bv*[height<=720][vcodec~='^((he|a)vc|h26[45])']+ba)
# TODO : DELAY COPY OPERATION... Astro can download quicker at 03:00 AM # TODO : DELAY COPY OPERATION... Astro can download quicker at 03:00 AM
echo "yt-dlp -f \"bv*[ext=mp4][height<=480]+ba/b[height<=480] / bv*[ext=mp4][height<=720]+ba/b[height<=720]\" --no-mtime --embed-thumbnail --add-metadata -o \"$HOME/.zen/tmp/tube/$TITLE.%(ext)s\" ${ZYURL}" echo "yt-dlp -f \"bv*[ext=mp4][height<=480]+ba/b[height<=480] / bv*[ext=mp4][height<=720]+ba/b[height<=720]\" --no-mtime --embed-thumbnail --add-metadata -o \"$HOME/.zen/tmp/$WISHKEY/$TITLE.%(ext)s\" ${ZYURL}"
############################################################################# #############################################################################
## COPY FROM YOUTUBE (TODO DOUBLE COPY & MKV to MP4 OPTIMISATION) ## COPY FROM YOUTUBE (TODO DOUBLE COPY & MKV to MP4 OPTIMISATION)
yt-dlp -f "bv*[ext=mp4][height<=480]+ba/b[height<=480] / bv*[ext=mp4][height<=720]+ba/b[height<=720]" \ yt-dlp -f "(bv*[ext=mp4][height<=720]+ba/b[height<=720])" \
-S "filesize:700M" --no-mtime --embed-thumbnail --add-metadata \ -S "filesize:700M" --no-mtime --embed-thumbnail --add-metadata \
--write-subs --write-auto-subs --sub-langs "fr, en, en-orig" --embed-subs \ --write-subs --write-auto-subs --sub-langs "fr, en, en-orig" --embed-subs \
-o "$HOME/.zen/tmp/tube/$TITLE.%(ext)s" ${ZYURL} -o "$HOME/.zen/tmp/$WISHKEY/$TITLE.%(ext)s" ${ZYURL}
################################################################################ ################################################################################
### ADAPT TO TW RYTHM (DELAY COPY?) ### ADAPT TO TW RYTHM (DELAY COPY?)
echo echo
@ -65,20 +78,24 @@ for YURL in $(cat ~/.zen/tmp/tube.json | jq -r '.[].text' | grep 'http'); do
############################################################################ ############################################################################
### CHECK RESULT CONVERT MKV TO MP4 ### CHECK RESULT CONVERT MKV TO MP4
[[ ! -f "$HOME/.zen/tmp/tube/$ZFILE" ]] && ffmpeg -i "$HOME/.zen/tmp/tube/$TITLE.mkv" -c:v libx264 -c:a aac "$HOME/.zen/tmp/tube/$TITLE.mp4" # TRY TO CONVERT MKV TO MP4 [[ ! -f "$HOME/.zen/tmp/$WISHKEY/$ZFILE" ]] && ffmpeg -i "$HOME/.zen/tmp/$WISHKEY/$TITLE.mkv" -c:v libx264 -c:a aac "$HOME/.zen/tmp/$WISHKEY/$TITLE.mp4" # TRY TO CONVERT MKV TO MP4
[[ ! -f "$HOME/.zen/tmp/tube/$ZFILE" ]] && echo "No FILE -- CONTINUE --" && continue [[ ! -f "$HOME/.zen/tmp/$WISHKEY/$ZFILE" ]] && echo "No FILE -- CONTINUE --" && continue
echo echo
echo "FOUND : ~/.zen/tmp/tube/$ZFILE" ####################################################
echo "FOUND : ~/.zen/tmp/$WISHKEY/$ZFILE"
FILE_BSIZE=$(du -b "$HOME/.zen/tmp/$WISHKEY/$ZFILE" | awk '{print $1}')
FILE_SIZE=$(echo "${FILE_BSIZE}" | awk '{ split( "B KB MB GB TB PB" , v ); s=1; while( $1>1024 ){ $1/=1024; s++ } printf "%.2f %s", $1, v[s] }')
echo "FILE SIZE = $FILE_SIZE ($FILE_BSIZE octets)"
echo "Adding to IPFS" echo "Adding to IPFS"
ILINK=$(ipfs add -q "$HOME/.zen/tmp/tube/$ZFILE" | tail -n 1) ILINK=$(ipfs add -q "$HOME/.zen/tmp/$WISHKEY/$ZFILE" | tail -n 1)
echo "/ipfs/$ILINK <=> $ZFILE" echo "/ipfs/$ILINK <=> $ZFILE"
MIME=$(file --mime-type "$HOME/.zen/tmp/tube/$ZFILE" | rev | cut -d ' ' -f 1 | rev) MIME=$(file --mime-type "$HOME/.zen/tmp/$WISHKEY/$ZFILE" | rev | cut -d ' ' -f 1 | rev)
## ADD TAGS ## ADD TAGS
EXTRATAG=$(yt-dlp --print "crea_%(creator)s chan_%(channel)s sec_%(duration)s list_%(playlist)s" "${ZYURL}") SEC=$(yt-dlp --print "%(duration)s" "${ZYURL}")
## PREPARE VIDEO HTML5 CODE ## PREPARE VIDEO HTML5 CODE
TEXT="<video controls width=360><source src='/ipfs/"${ILINK}"' type='"${MIME}"'></video><h1><a href='"${ZYURL}"'>"${TITLE}"</a></h1>" TEXT="<video controls width=360><source src='/ipfs/"${ILINK}"' type='"${MIME}"'></video><h1><a href='"${ZYURL}"'>"${TITLE}"</a></h1>"
@ -90,43 +107,40 @@ for YURL in $(cat ~/.zen/tmp/tube.json | jq -r '.[].text' | grep 'http'); do
"title": "'$ZFILE'", "title": "'$ZFILE'",
"type": "'text/vnd.tiddlywiki'", "type": "'text/vnd.tiddlywiki'",
"text": "'$TEXT'", "text": "'$TEXT'",
"size": "'${FILE_BSIZE}'",
"sec": "'${SEC}'",
"ipfs": "'${ILINK}'", "ipfs": "'${ILINK}'",
"youtubeid": "'${YID}'", "youtubeid": "'${YID}'",
"tags": "'ipfs youtube g1tube ${EXTRATAG} ${MIME}'" "tags": "'ipfs youtube g1tube ${EXTRATAG} ${MIME}'"
} }
] ]
' > "$HOME/.zen/tmp/tube/$YID.TW.json" ' > "$HOME/.zen/tmp/$WISHKEY/$YID.TW.json"
done < ~/.zen/tmp/ytids # FINISH YID loop 1
done # FINISH YURL loop
################################################################# #################################################################
### ADDING $YID.TW.json to TWNS INDEX.html ### ADDING $YID.TW.json to TWNS INDEX.html
################################################################# #################################################################
while read YID;
do
echo "==========================" echo "=========================="
echo "Adding $YID tiddler to TW /ipns/$TWNS " echo "Adding $YID tiddler to TW /ipns/$TWNS "
rm -f ~/.zen/tmp/newindex.html rm -f ~/.zen/tmp/$WISHKEY/newindex.html
echo ">>> Importing $HOME/.zen/tmp/tube/$YID.TW.json" echo ">>> Importing $HOME/.zen/tmp/$WISHKEY/$YID.TW.json"
tiddlywiki --load $INDEX \ tiddlywiki --load $INDEX \
--import "$HOME/.zen/tmp/tube/$YID.TW.json" "application/json" \ --import "$HOME/.zen/tmp/$WISHKEY/$YID.TW.json" "application/json" \
--deletetiddlers '[tag[tube]]' \ --deletetiddlers '[tag[tube]]' \
--output ~/.zen/tmp --render "$:/core/save/all" "newindex.html" "text/plain" --output ~/.zen/tmp/$WISHKEY --render "$:/core/save/all" "newindex.html" "text/plain"
if [[ -s ~/.zen/tmp/newindex.html ]]; then if [[ -s ~/.zen/tmp/$WISHKEY/newindex.html ]]; then
echo "Updating $INDEX" echo "Updating $INDEX"
cp ~/.zen/tmp/newindex.html $INDEX cp ~/.zen/tmp/$WISHKEY/newindex.html $INDEX
else else
echo "Problem with tiddlywiki command. Missing ~/.zen/tmp/newindex.html" echo "Problem with tiddlywiki command. Missing ~/.zen/tmp/$WISHKEY/newindex.html"
echo "XXXXXXXXXXXXXXXXXXXXXXX" echo "XXXXXXXXXXXXXXXXXXXXXXX"
fi fi
done < ~/.zen/tmp/ytids # FINISH YID loop 2 done < ~/.zen/tmp/$WISHKEY/ytids.$MOATS # FINISH YID loop 1
## FINAL TW IPNS PUBLISHING ## FINAL TW IPNS PUBLISHING
echo "ipfs name publish -k $WISHKEY ($INDEX)" echo "ipfs name publish -k $WISHKEY ($INDEX)"

View File

@ -9,85 +9,76 @@ MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
ME="${0##*/}" ME="${0##*/}"
################################################################################ ################################################################################
# Inspect game wishes, refresh latest IPNS version # Inspect game wishes, refresh latest IPNS version
# Backup and chain # SubProcess Backup and chain
[[ $PLAYER == "" ]] && PLAYER=$(cat ~/.zen/game/players/.current/.player 2>/dev/null)
############################################ ############################################
echo "## WORLD VOEUX" echo "## WORLD VOEUX"
myIP=$(hostname -I | awk '{print $1}' | head -n 1)
for v in $(cat ~/.zen/game/players/*/voeux/*/.title); do echo $v ;done for v in $(cat ~/.zen/game/players/*/VOEUx/*/.title); do echo $v ;done
for voeu in $(ls ~/.zen/game/world/); for VOEU in $(ls ~/.zen/game/world/);
do do
echo "VOEU : $voeu" ## CLEAN OLD CACHE
voeuns=$(ipfs key list -l | grep $voeu | cut -d ' ' -f1)
echo "http://127.0.0.1:8080/ipns/$voeuns"
echo
W=$(cat ~/.zen/game/world/$voeu/.pepper 2>/dev/null)
echo $W
rm -Rf ~/.zen/tmp/work rm -Rf ~/.zen/tmp/work
mkdir -p ~/.zen/tmp/work mkdir -p ~/.zen/tmp/work
echo "==============================="
echo "VOEU : $VOEU"
VOEUNS=$(ipfs key list -l | grep $VOEU | cut -d ' ' -f1)
WISHNAME=$(cat ~/.zen/game/world/$VOEU/.pepper 2>/dev/null)
echo "$WISHNAME"
echo "==============================="
echo "Getting latest online TW..."
YOU=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1); YOU=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1);
LIBRA=$(head -n 2 ~/.zen/Astroport.ONE/A_boostrap_nodes.txt | tail -n 1 | cut -d ' ' -f 2) LIBRA=$(head -n 2 ~/.zen/Astroport.ONE/A_boostrap_nodes.txt | tail -n 1 | cut -d ' ' -f 2)
echo "$LIBRA/ipns/$voeuns" echo "$LIBRA/ipns/$VOEUNS"
[[ $YOU ]] && ipfs --timeout 12s cat /ipns/$voeuns > ~/.zen/tmp/work/index.html \ echo "http://$myIP:8080/ipns/$VOEUNS"
|| curl -m 12 -so ~/.zen/tmp/work/index.html "$LIBRA/ipns/$voeuns" echo "Getting latest online TW..."
[[ $YOU ]] && ipfs --timeout 12s cat /ipns/$VOEUNS > ~/.zen/tmp/work/index.html \
|| curl -m 12 -so ~/.zen/tmp/work/index.html "$LIBRA/ipns/$VOEUNS"
if [[ ! -s ~/.zen/tmp/work/index.html ]]; then if [[ ! -s ~/.zen/tmp/work/index.html ]]; then
echo "UNAVAILABLE WISH! If you want to remove $W $voeu" echo "UNAVAILABLE WISH! If you want to remove $WISHNAME $VOEU"
echo "ipfs key rm $voeu && rm -Rf ~/.zen/game/world/$voeu" echo "ipfs key rm $VOEU && rm -Rf ~/.zen/game/world/$VOEU"
echo "============================================="
echo "ipfs name publish -t 72h /ipfs/$(cat ~/.zen/game/world/$VOEU/.chain)"
echo "=============================================" echo "============================================="
echo "ipfs name publish -t 72h /ipfs/$(cat ~/.zen/game/world/$voeu/.chain)"
continue continue
else else
## Replace tube links with downloaded video echo "SEARCH VOEU TW FOR tag=tube"
$MY_PATH/TUBE.copy.sh ~/.zen/tmp/work/index.html $voeu ## TAG="tube" tiddler => Dowload youtube video links (playlist accepted) ## WISHKEY=G1PUB !
$MY_PATH/TUBE.copy.sh ~/.zen/tmp/work/index.html $VOEU
## LAN TO WAN MIGRATION echo "NEXT SEARCH Ŋ1 FRIENDS TW's FOR tag=$WISHNAME"
myIP=$(hostname -I | awk '{print $1}' | head -n 1)
sed -i "s~192.168.199.191~${myIP}~g" ~/.zen/tmp/work/index.html
echo $myIP > ~/.zen/game/world/$voeu/.myIP
echo "Setting new IP : $myIP"
echo "DIFFERENCE ?" echo "DIFFERENCE ?"
DIFF=$(diff ~/.zen/tmp/work/index.html ~/.zen/game/world/$voeu/index.html) DIFF=$(diff ~/.zen/tmp/work/index.html ~/.zen/game/world/$VOEU/index.html)
if [[ $DIFF ]]; then if [[ $DIFF ]]; then
echo "Backup & Upgrade TW local copy..." echo "Upgrade TW local copy..."
cp -f ~/.zen/game/world/$voeu/index.html ~/.zen/game/world/$voeu/index.backup.html cp ~/.zen/tmp/work/index.html ~/.zen/game/world/$VOEU/index.html
cp ~/.zen/tmp/work/index.html ~/.zen/game/world/$voeu/index.html
else else
echo "No change since last Refresh" echo "No change since last Refresh"
fi fi
fi fi
# RECORDING BLOCKCHAIN TIC # RECORDING CHANGES
MOATS=$(date -u +"%Y%m%d%H%M%S%4N") MOATS=$(date -u +"%Y%m%d%H%M%S%4N")
[[ $DIFF ]] && cp ~/.zen/game/world/$voeu/.chain ~/.zen/game/world/$voeu/.chain.$MOATS [[ $DIFF ]] && cp ~/.zen/game/world/$VOEU/.chain \
~/.zen/game/world/$VOEU/.chain.$(cat ~/.zen/game/world/$VOEU/.moats)
IPUSH=$(ipfs add -Hq ~/.zen/game/world/$voeu/index.html | tail -n 1) # PUBLISH VOEU TW
ipfs name publish -t 72h --key=${voeu} /ipfs/$IPUSH 2>/dev/null IPUSH=$(ipfs add -Hq ~/.zen/game/world/$VOEU/index.html | tail -n 1)
ipfs name publish -t 72h --key=${VOEU} /ipfs/$IPUSH 2>/dev/null
[[ $DIFF ]] && echo $IPUSH > ~/.zen/game/world/$voeu/.chain [[ $DIFF ]] && echo $IPUSH > ~/.zen/game/world/$VOEU/.chain; \
echo $MOATS > ~/.zen/game/world/$voeu/.moats echo $MOATS > ~/.zen/game/world/$VOEU/.moats
rm -Rf ~/.zen/tmp/work rm -Rf ~/.zen/tmp/work
# if [[ -d ~/.zen/game/players/$PLAYER/voeux/$voeu ]]; then
# echo "==========================="
# echo "Voeu$W : commande de suppression"
# echo "ipfs key rm $voeu
# rm -Rf ~/.zen/game/world/$voeu
# rm -Rf ~/.zen/game/players/$PLAYER/voeux/$voeu"
# echo "==========================="
# fi
echo "================================================" echo "================================================"
echo "$W : http://127.0.0.1:8080/ipns/$voeuns" echo "$WISHNAME : http://$myIP:8080/ipns/$VOEUNS"
echo "================================================" echo "================================================"
done done