create tiddler with tag=tube any URL is the downloaded, added to IPFS and republish

This commit is contained in:
fred 2022-08-25 19:33:10 +02:00
parent 0b17833a42
commit 3624cc054f
2 changed files with 25 additions and 45 deletions

View File

@ -3,7 +3,6 @@
# 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##*/}"
@ -17,48 +16,52 @@ WISHKEY="$2"
WNS=$(ipfs key list -l | grep -w $WISHKEY | cut -d ' ' -f1)
# Extract tag=tube from TW
rm -f ~/.zen/tmp/tiddlers.json
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
for yurl in $(cat ~/.zen/tmp/tiddlers.json | jq -r '.[].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/)
yt-dlp -f "[height=480]/best" --no-mtime --embed-thumbnail --add-metadata -o "$HOME/.zen/tmp/tube/%(title)s.%(ext)s" ${yurl}
FILE=$(ls -t ~/.zen/tmp/tube/ | tail -n 1)
[[ ! -f ~/.zen/tmp/tube/$FILE ]] && echo "No FILE -- EXIT --" && exit 1
echo "~/.zen/tmp/tube/$FILE downloaded"
echo "Adding to IPFS"
ILINK=$(ipfs add -q ~/.zen/tmp/tube/$FILE | tail -n 1)
ILINK=$(ipfs add -q "$HOME/.zen/tmp/tube/$FILE" | tail -n 1)
echo "/ipfs/$ILINK ready"
MIME=$(file --mime-type "$HOME/.zen/tmp/tube/$FILE" | cut -d ':' -f 2 | cut -d ' ' -f 2)
MIME=$(file --mime-type ~/.zen/tmp/tube/$FILE | cut -d ' ' -f 2)
echo "MIME TYPE : $MIME"
TEXT="<video controls width=360><source src='/ipfs/"${ILINK}"' type='"${MIME}"'></video><h1>"${FILE}"</h1>"
echo "Creating Youtube tiddler"
echo '[
{
"title": "'$FILE'",
"type": "'$MIME'",
"text": "''",
"tags": "'$:/isAttachment $:/isEmbedded ipfs youtube'",
"_canonical_uri": "'/ipfs/${ILINK}'"
"type": "'text/vnd.tiddlywiki'",
"text": "'$TEXT'",
"tags": "'ipfs youtube copylaradio ${MIME}'"
}
]
' > ~/.zen/tmp/tube/tube.json
' > ~/.zen/tmp/tube.json
echo
echo "=========================="
echo "Adding tiddler to TW"
rm -f ~/.zen/tmp/newindex.html
tiddlywiki --verbose --load $INDEX \
--import ~/.zen/tmp/tube/tube.json "application/json" \
--import ~/.zen/tmp/tube.json "application/json" \
--deletetiddlers '[tag[tube]]' \
--output ~/.zen/tmp --render "$:/core/save/all" "newindex.html" "text/plain"
if [[ -s ~/.zen/tmp/newindex.html ]]; then
@ -71,12 +74,16 @@ for yurl in $(cat -r /home/fred/.zen/tmp/tiddlers.json | jq '.[].text' | grep 'h
ipfs name publish -k $WISHKEY /ipfs/$ILINK
echo "/ipfs/$ILINK"
else
echo "Problem with tiddlywiki command. Missing ~/.zen/tmp/newindex.html"
echo "XXXXXXXXXXXXXXXXXXXXXXX"
fi
done
echo "=========================="
echo "Nouveau TW"
echo "http://127.0.0.1:8080/ipns/$WNS"
# Removing tag=tube
--deletetiddlers '[tag[tube]]'
}
# --deletetiddlers '[tag[tube]]'

View File

@ -73,31 +73,4 @@ do
echo "$W : http://127.0.0.1:8080/ipns/$voeuns"
done
############################################
echo "## PLAYER TW"
for PLAYER in $(ls ~/.zen/game/players/); do
echo "PLAYER : $PLAYER"
## REFRESH ASTRONAUTE TW
ASTRONAUTENS=$(cat ~/.zen/game/players/$PLAYER/.playerns)
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. Using 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