Convert tube URL

This commit is contained in:
fred 2022-08-25 17:21:39 +02:00
parent 0a0867f528
commit 0b17833a42
4 changed files with 140 additions and 4 deletions

View File

@ -239,7 +239,8 @@ convert -gravity northwest -pointsize 50 -fill black -draw "text 30,300 \"Ğ1 VO
echo "Hop, Une June pour ce Voeu"
$MY_PATH/tools/jaklis/jaklis.py -k ~/.zen/game/players/$PLAYER/secret.dunikey pay -a 1 -p $WISHKEY -c "G1Voeu $PEPPER $VOEUXNS" -m -v
echo "************************************************************"
echo
done
exit 0

46
tools/PLAYER.refresh.sh Executable file
View File

@ -0,0 +1,46 @@
#!/bin/bash
################################################################################
# Author: Fred (support@qo-op.com)
# Version: 0.1
# 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##*/}"
################################################################################
# Inspect game wishes, refresh latest IPNS version
# Backup and chain
[[ $PLAYER == "" ]] && PLAYER=$(cat ~/.zen/game/players/.current/.player 2>/dev/null)
############################################
echo "## PLAYER TW"
for PLAYER in $(ls ~/.zen/game/players/); do
echo "PLAYER : $PLAYER"
## REFRESH ASTRONAUTE TW
ASTRONAUTENS=$(ipfs key list -l | grep $PLAYER | cut -d ' ' -f1)
[[ ! $ASTRONAUTENS ]] && echo "Missing $PLAYER IPNS KEY -- EXIT --" && exit 1
rm -Rf ~/.zen/tmp/astro
mkdir -p ~/.zen/tmp/astro
ipfs --timeout 12s cat /ipns/$ASTRONAUTENS > ~/.zen/tmp/astro/index.html
if [ ! -s ~/.zen/tmp/astro/index.html ]; then
echo "ERROR IPNS TIMEOUT. Unchanged local backup..."
continue
else
echo "Upgrade TW local copy..."
cp ~/.zen/tmp/astro/index.html ~/.zen/game/players/$PLAYER/ipfs/moa/index.html
fi
TW=$(ipfs add -Hq ~/.zen/game/players/$PLAYER/ipfs/moa/index.html | tail -n 1)
ipfs name publish --key=$PLAYER /ipfs/$TW
echo "$PLAYER : http://127.0.0.1:8080/ipns/$ASTRONAUTENS"
done
exit 0

82
tools/TUBE.tw.sh Executable file
View File

@ -0,0 +1,82 @@
#!/bin/bash
########################################################################
# Version: 0.3
# 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##*/}"
INDEX="$1"
[[ ! $INDEX ]] && echo "Please provide path to source TW index.html" && exit 1
[[ ! -f $INDEX ]] && echo "Fichier TW absent. $INDEX" && exit 1
WISHKEY="$2"
[[ ! $WISHKEY ]] && echo "Please provide IPFS publish key" && exit 1
WNS=$(ipfs key list -l | grep -w $WISHKEY | cut -d ' ' -f1)
# Extract tag=tube from TW
tiddlywiki --verbose --load ${INDEX} --output ~/.zen/tmp --render '.' 'tiddlers.json' 'text/plain' '$:/core/templates/exporters/JsonFile' 'exportFilter' '[tag[tube]]'
## Extract URL from text field
for yurl in $(cat -r /home/fred/.zen/tmp/tiddlers.json | jq '.[].text' | grep 'http'); do
echo "Detected $yurl"
echo "Start Downloading"
rm -Rf ~/.zen/tmp/tube
mkdir -p ~/.zen/tmp/tube
yt-dlp -f "[height=480]/best" --no-mtime --embed-thumbnail --add-metadata -o ~/.zen/tmp/tube/%(title)s.%(ext)s ${yurl}
FILE=$(ls ~/.zen/tmp/tube/)
echo "~/.zen/tmp/tube/$FILE downloaded"
echo "Adding to IPFS"
ILINK=$(ipfs add -q ~/.zen/tmp/tube/$FILE | tail -n 1)
echo "/ipfs/$ILINK ready"
MIME=$(file --mime-type ~/.zen/tmp/tube/$FILE | cut -d ' ' -f 2)
echo "MIME TYPE : $MIME"
echo "Creating Youtube tiddler"
echo '[
{
"title": "'$FILE'",
"type": "'$MIME'",
"text": "''",
"tags": "'$:/isAttachment $:/isEmbedded ipfs youtube'",
"_canonical_uri": "'/ipfs/${ILINK}'"
}
]
' > ~/.zen/tmp/tube/tube.json
echo
echo "Adding tiddler to TW"
rm -f ~/.zen/tmp/newindex.html
tiddlywiki --verbose --load $INDEX \
--import ~/.zen/tmp/tube/tube.json "application/json" \
--output ~/.zen/tmp --render "$:/core/save/all" "newindex.html" "text/plain"
if [[ -s ~/.zen/tmp/newindex.html ]]; then
echo "Updating $INDEX"
cp ~/.zen/tmp/newindex.html $INDEX
echo "ipfs name publish -k $WISHKEY"
ILINK=$(ipfs add -q $INDEX | tail -n 1)
ipfs name publish -k $WISHKEY /ipfs/$ILINK
echo "/ipfs/$ILINK"
fi
done
# Removing tag=tube
--deletetiddlers '[tag[tube]]'
}

View File

@ -13,10 +13,11 @@ ME="${0##*/}"
[[ $PLAYER == "" ]] && PLAYER=$(cat ~/.zen/game/players/.current/.player 2>/dev/null)
############################################
echo "## WORLD VOEUX"
for v in $(cat ~/.zen/game/players/*/voeux/*/.title); do echo $v ;done
for voeu in $(ls ~/.zen/game/world/);
do
echo "VOEU : $voeu"
@ -26,17 +27,23 @@ do
W=$(cat ~/.zen/game/world/$voeu/.pepper 2>/dev/null)
echo $W
rm -Rf ~/.zen/tmp/work
mkdir -p ~/.zen/tmp/work
rm -f ~/.zen/tmp/work/index.html
echo "Getting latest online TW..."
ipfs --timeout 12s cat /ipns/$voeuns > ~/.zen/tmp/work/index.html
if [[ ! -f ~/.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 "ipfs key rm $voeu && rm -Rf ~/.zen/game/world/$voeu"
continue
else
# Downloading "tag=tube"
echo "$MY_PATH/TUBE.tw.sh ~/.zen/tmp/work/index.html $voeu"
echo "PLEASE MANUAL RUN"
read
# Update local copy
cp ~/.zen/tmp/work/index.html ~/.zen/game/world/$voeu/index.html
fi