#!/bin/bash ################################################################################ # Author: Fred (support@qo-op.com) # Version: 0.1 # License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/) ################################################################################ mkdir -p ~/.zen/bunkerbox # BunkerBOX temp directory # Fred MadeInZion, [20/03/2022 23:03] # Script qui capture et transfert dans IPFS le flux des nouvelles vidéos de https://crowdbunker.com/ # le resultat est inscrit dans une chaine video accessible localement ou publiée au travers de qo-op # ou du TestNET astrXbian, videoclub entre amis d'amis... MY_PATH="`dirname \"$0\"`" # relative MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized ME="${0##*/}" TS=$(date -u +%s%N | cut -b1-13) [[ ! $(which ipfs) ]] && echo "EXIT. Vous devez avoir installé ipfs CLI sur votre ordinateur" && echo "RDV sur https://dist.ipfs.io/#go-ipfs" && exit 1 YOU=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1) || echo " warning ipfs daemon not running" isLAN=$(hostname -I | awk '{print $1}' | head -n 1 | cut -f3 -d '/' | grep -E "(^127\.)|(^192\.168\.)|(^fd42\:)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^::1$)|(^[fF][cCdD])/") IPFSNGW="https://tube.copylaradio.com" IPFSNGW="http://127.0.0.1:8080" [[ ! $isLAN ]] && IPFSNGW="https://$(hostname)" echo "IPFS GATEWAY $IPFSNGW" ## GET LATEST VIDEOS VWALLURL="https://api.crowdbunker.com/post/all" curl -s $VWALLURL -H "Accept: application/json" > ~/.zen/bunkerbox/crowd.json ## LOOP THROUGH for VUID in $(cat ~/.zen/bunkerbox/crowd.json | jq -r '.posts | .[] | .video.id'); do [[ "$VUID" == "null" ]] && echo "MESSAGE... Bypassing..." && echo && continue echo "Bunker BOX : Adding $VUID" mkdir -p ~/.zen/bunkerbox/$VUID/media URL="https://api.crowdbunker.com/post/$VUID/details" # echo "WISHING TO EXPLORE $URL ?"; read TEST; [[ "$TEST" != "" ]] && echo && continue curl -s $URL -H "Accept: application/json" -o ~/.zen/bunkerbox/$VUID/$VUID.json # STREAMING LIVE ? echo ">>> Extracting video caracteristics from ~/.zen/bunkerbox/$VUID/$VUID.json" ISLIVE=$(cat ~/.zen/bunkerbox/$VUID/$VUID.json | jq -r .video.isLiveType)&& [[ "$ISLIVE" == "true" ]] && echo "LIVE... " LIVE=$(cat ~/.zen/bunkerbox/$VUID/$VUID.json | jq -r .video.isLiveActive) && [[ "$LIVE" == "true" ]] && echo "STREAMING... Bypassing..." && echo && continue DURATION=$(cat ~/.zen/bunkerbox/$VUID/$VUID.json | jq -r .video.duration) && [[ $DURATION == 0 ]] && echo "NOT STARTED YET" && echo && continue TITLE=$(cat ~/.zen/bunkerbox/$VUID/$VUID.json | jq -r .video.title | sed "s/'/ /g" | sed 's/"/ /g') # Remove quote CHANNEL=$(cat ~/.zen/bunkerbox/$VUID/$VUID.json | jq -r .channel.name) ORGUID=$(cat ~/.zen/bunkerbox/$VUID/$VUID.json | jq -r .organization.uid) ORGNAME=$(cat ~/.zen/bunkerbox/$VUID/$VUID.json | jq -r .organization.name) ORGBANNER=$(cat ~/.zen/bunkerbox/$VUID/$VUID.json | jq -r .organization.banner.url) HLS=$(cat ~/.zen/bunkerbox/$VUID/$VUID.json | jq -r .video.hlsManifest.url) MEDIASOURCE=$(echo $HLS | rev | cut -d '/' -f 2- | rev) echo "$TITLE ($DURATION s)" ## CHECK PUBLISH MODE [[ ! -f ~/.zen/bunkerbox/choice ]] && echo "READY TO PROCESS ? ENTER. Any character sent means next." && read TEST && [[ "$TEST" != "" ]] && echo && continue ## NO CHOICE MADE start=`date +%s` echo "$HLS" curl -s $HLS -o ~/.zen/bunkerbox/$VUID/$VUID.m3u8 # cat ~/.zen/bunkerbox/$VUID/$VUID.m3u8 echo ">>>>>>>>>>>>>>>> Downloading VIDEO" # Choose 360p or 480p or 240p VSIZE=360 && VIDEOHEAD=$(cat ~/.zen/bunkerbox/$VUID/$VUID.m3u8 | grep -B1 ${VSIZE}p | head -n 1) && VIDEOSRC=$(cat ~/.zen/bunkerbox/$VUID/$VUID.m3u8 | grep ${VSIZE}p | tail -n 1 | cut -f 1 -d '.') [[ "$VIDEOSRC" == "" ]] && VSIZE=480 && VIDEOHEAD=$(cat ~/.zen/bunkerbox/$VUID/$VUID.m3u8 | grep -B1 ${VSIZE}p | head -n 1) && VIDEOSRC=$(cat ~/.zen/bunkerbox/$VUID/$VUID.m3u8 | grep ${VSIZE}p | tail -n 1 | cut -f 1 -d '.') [[ "$VIDEOSRC" == "" ]] && VSIZE=240 &&VIDEOHEAD=$(cat ~/.zen/bunkerbox/$VUID/$VUID.m3u8 | grep -B1 ${VSIZE}p | head -n 1) && VIDEOSRC=$(cat ~/.zen/bunkerbox/$VUID/$VUID.m3u8 | grep ${VSIZE}p | tail -n 1 | cut -f 1 -d '.') VTHUMB="$(cat ~/.zen/bunkerbox/$VUID/$VUID.json | jq -r --arg VSIZE "$VSIZE" '.video.thumbnails[] | select(.height == $VSIZE) | .url')" echo ">>>>>>>>>>>>>>>> Downloading Video $VSIZE Thumbnail" curl -s $VTHUMB -o ~/.zen/bunkerbox/$VUID/media/$VUID.jpg [[ ! -f ~/.zen/bunkerbox/$VUID/media/$VUID.jpg ]] && cp ${MY_PATH}/images/astroport.jpg ~/.zen/bunkerbox/$VUID/media/$VUID.jpg # CORRECT MISSING THUMB echo "VIDEOSRC=$MEDIASOURCE/$VIDEOSRC" # Downloading Video m3u8 and Video [[ ! -f ~/.zen/bunkerbox/$VUID/media/$VIDEOSRC.m3u8 ]] && curl -s $MEDIASOURCE/$VIDEOSRC.m3u8 -o ~/.zen/bunkerbox/$VUID/media/$VIDEOSRC.m3u8 [[ ! -f ~/.zen/bunkerbox/$VUID/media/$VIDEOSRC ]] && curl $MEDIASOURCE/$VIDEOSRC -o ~/.zen/bunkerbox/$VUID/media/$VIDEOSRC echo ">>>>>>>>>>>>>>>> Downloading AUDIO" AUDIOLINE=$(cat ~/.zen/bunkerbox/$VUID/$VUID.m3u8 | grep '=AUDIO') AUDIOFILE=$(echo $AUDIOLINE | rev | cut -d '.' -f 2- | cut -d '"' -f 1 | rev) echo "AUDIO=$MEDIASOURCE/$AUDIOFILE" # Downloading Audio m3u8 and Audio [[ ! -f ~/.zen/bunkerbox/$VUID/media/$AUDIOFILE.m3u8 ]] && curl -s $MEDIASOURCE/$AUDIOFILE.m3u8 -o ~/.zen/bunkerbox/$VUID/media/$AUDIOFILE.m3u8 [[ ! -f ~/.zen/bunkerbox/$VUID/media/$AUDIOFILE ]] && curl $MEDIASOURCE/$AUDIOFILE -o ~/.zen/bunkerbox/$VUID/media/$AUDIOFILE echo ">>>>>>>>>>>>>>>> CREATING $VSIZE M3U8" echo "#EXTM3U #EXT-X-VERSION:6 #EXT-X-INDEPENDENT-SEGMENTS $AUDIOLINE $VIDEOHEAD $VIDEOSRC.m3u8 " > ~/.zen/bunkerbox/$VUID/media/$VUID.m3u8 ls ~/.zen/bunkerbox/$VUID/media/ ########################################################################## echo "##########################################################################" echo ">>>>>>>>>>>>>>>> ADDING index.html" # COPY index, style, js AND data cp -R ${MY_PATH}/templates/styles ~/.zen/bunkerbox/$VUID/media/ cp -R ${MY_PATH}/templates/js ~/.zen/bunkerbox/$VUID/media/ cp ${MY_PATH}/templates/videojs.html ~/.zen/bunkerbox/$VUID/media/index.html cp ${MY_PATH}/images/astroport.jpg ~/.zen/bunkerbox/$VUID/media/ # Add current/latest common history reversed if [[ -f ~/.zen/bunkerbox/history.json ]]; then # qo-op get latest history.json [[ "$(cat ~/.zen/bunkerbox/choice)"=="qo-op" ]] && ipfs get -o ~/.zen/bunkerbox/history.qo-op.json /ipns/$(cat ~/.zen/bunkerbox/qo-op)/history.json # FUSION/REPLACEMENT WHAT TODO ? ## echo '{ "Videos":' > ~/.zen/bunkerbox/$VUID/media/history.json cat ~/.zen/bunkerbox/history.json | jq '.[] | reverse' >> ~/.zen/bunkerbox/$VUID/media/history.json echo '}' >> ~/.zen/bunkerbox/$VUID/media/history.json else ## NEW history [[ ! $(cat ~/.zen/bunkerbox/history.json | grep Videos) ]] && cp ${MY_PATH}/templates/data/history.json ~/.zen/bunkerbox/history.json cp ~/.zen/bunkerbox/history.json ~/.zen/bunkerbox/$VUID/media/history.json fi # Using relative links sed "s/_IPFSROOT_/./g" ${MY_PATH}/templates/videojs.html > ~/.zen/bunkerbox/$VUID/media/index.html sed -i "s/_VUID_/$VUID/g" ~/.zen/bunkerbox/$VUID/media/index.html # sed -i s/_DATE_/$(date -u "+%Y-%m-%d#%H:%M:%S")/g ~/.zen/bunkerbox/$VUID/media/index.html # Different Copy Makes Different Chains ! sed -i "s~_TITLE_~$TITLE~g" ~/.zen/bunkerbox/$VUID/media/index.html sed -i "s~_CHANNEL_~$CHANNEL~g" ~/.zen/bunkerbox/$VUID/media/index.html echo ">>>>> ADDING TO IPFS : ipfs add -rwH ~/.zen/bunkerbox/$VUID/media/* " echo IPFSROOT=$(ipfs add -rwHq ~/.zen/bunkerbox/$VUID/media/* | tail -n 1) INDEX="/ipfs/$IPFSROOT" VMAIN="/ipfs/$IPFSROOT/$VUID.m3u8" # UPDATING original JSON cat ~/.zen/bunkerbox/$VUID/$VUID.json | jq ".video.hlsManifest.url = \"$VMAIN\"" > ~/.zen/bunkerbox/$VUID/media/$VUID.json echo "M3U8 : $IPFSNGW$VMAIN" ## UPDATE GLOCAL HISTORY ? IsThere=$(cat ~/.zen/bunkerbox/history.json | jq .Videos[].link | grep $VUID) if [[ ! $IsThere ]]; then echo "Add $INDEX to ~/.zen/bunkerbox/$VUID/media/history.json" cat ~/.zen/bunkerbox/history.json | jq '.Videos += [{"link": "
'"'_TITLE_'"'"}]' > ~/.zen/bunkerbox/$VUID/media/history.json echo $INDEX sed -i "s~_INDEX_~$INDEX~g" ~/.zen/bunkerbox/$VUID/media/history.json echo $VUID sed -i "s~_VUID_~$VUID~g" ~/.zen/bunkerbox/$VUID/media/history.json echo $TITLE sed -i "s~_TITLE_~$TITLE~g" ~/.zen/bunkerbox/$VUID/media/history.json # COULD BE DONE LIKE THAT # cat ~/.zen/bunkerbox/$VUID/media/history.json | jq --arg INDEX "$INDEX" --arg TITLE "$TITLE" '.Videos += [{"link": "'''$TITLE'''"}]' > ~/.zen/bunkerbox/history.json echo "Mise à jour ~/.zen/bunkerbox/history.json" [[ "$(cat ~/.zen/bunkerbox/$VUID/media/history.json)" == "" ]] && echo "FATAL ERROR MAJ" && exit 1 [[ -f ~/.zen/bunkerbox/$VUID/media/history.json ]] && cp -f ~/.zen/bunkerbox/$VUID/media/history.json ~/.zen/bunkerbox/history.json fi echo "" > ~/.zen/bunkerbox/index.html echo "ACTUEL INDEX $IPFSNGW/ipfs/$IPFSROOT" echo "OLD JSON : $IPFSNGW/ipfs/$IPFSROOT/history.json" PS3="Comment voulez-vous continuer et publier la collecte ? " choices=("debug" "local" "qo-op" "astrXbian") fav=$(cat ~/.zen/bunkerbox/choice) [[ ! $fav ]] && select fav in "${choices[@]}"; do [[ $fav ]] && break; done case $fav in "local") echo 'local' > ~/.zen/bunkerbox/choice echo "Historique LOCAL = ~/.zen/bunkerbox/history.json" continue ;; "astrXbian") [[ ! -d ~/.zen/astrXbian ]] && echo "DEV ZONE - Installez astrXbian SVP ... P2P VideoClub DEMO - DEV ZONE !" && exit 1 [[ ! $IPFSNODEID ]] && echo "Missing IPFSNODEID. Exit" && exit 1 echo 'astrXbian' > ~/.zen/bunkerbox/choice mkdir -p ~/.zen/ipfs/.$IPFSNODEID/astroport/bunkerbox echo "" > ~/.zen/ipfs/.$IPFSNODEID/astroport/bunkerbox/index.html cp ~/.zen/bunkerbox/history.json ~/.zen/ipfs/.$IPFSNODEID/astroport/bunkerbox/ echo "BALISE Station $IPFSNGW/ipns/$IPFSNODEID/.$IPFSNODEID/astroport/bunkerbox/ propagation au prochain cycle astrXbian" continue ;; "qo-op") if [[ ! $(ipfs key list | grep 'qo-op') ]]; then echo "MIssing qo-op key! Clef qo-op manquante!" echo "get it from your best friend and do not break confidence ring!" echo "récupérez la auprès de votre meilleur ami. Et ne brisez pas la chaine de confiance!" echo "Contact support@qo-op.com for help! Envoyez un email pour obtenir assistance." echo "Utiliser la clef de DEV ? ENTRER pour OUI. Répondez qqch pour NON." read KDEV [[ "$KDEV" != "" ]] && echo "BRAVO! Confidence is in the KEY. La confiance est dans la CLEF." && break ## NO CHOICE MADE ## USE DEV KEY echo "k51qzi5uqu5djt17zonkpg1cb8hrxhahpesybusz8q57j4ocqm0qlc6s99z60x" > ~/.zen/bunkerbox/qo-op cp ${MY_PATH}/key_ofxs233q ~/.ipfs/keystore/ mkdir -p /tmp/$VUID echo "" > /tmp/$VUID/index.html cp ~/.zen/bunkerbox/history.json > /tmp/$VUID/history.json echo "$TS" > /tmp/$VUID/ts # TimeStamping VROOT=$(ipfs add -wHq /tmp/$VUID/* | tail -n 1) ipfs name publish --key=qo-op /ipfs/$VROOT echo "qo-op : $IPFSNGW/ipns/$IPNS/history.json /ipfs/$VROOT" else ## WRITE qo-op IPNS key ipfs key list -l | grep 'qo-op' | cut -f 1 -d ' ' > ~/.zen/bunkerbox/qo-op fi echo 'qo-op' > ~/.zen/bunkerbox/choice IPNS=$(cat ~/.zen/bunkerbox/qo-op) echo "Votre chaine vidéo qo-op /ipns/$IPNS" echo InHere=$(cat ~/.zen/bunkerbox/history.qo-op.json | jq .Videos[].link | grep $VUID) if [[ ! $InHere ]]; then echo "NOUVELLE VIDEO." mkdir -p /tmp/$VUID echo "" > /tmp/$VUID/index.html cp ~/.zen/bunkerbox/history.json /tmp/$VUID/history.json echo "$TS" > /tmp/$VUID/ts # TimeStamping VROOT=$(ipfs add -wHq /tmp/$VUID/* | tail -n 1) ipfs name publish --key=qo-op /ipfs/$VROOT echo "qo-op : $IPFSNGW/ipns/$IPNS/" echo "qo-op : $IPFSNGW/ipns/$IPNS/history.json" fi #[[ $VUID != "" ]] && rm -Rf /tmp/$VUID # Cleaning continue ;; "debug") echo "debug" > ~/.zen/bunkerbox/choice break ;; esac ########################################################################## # cat ~/.zen/bunkerbox/$VUID/media/$VUID.json | jq -r .video.hlsManifest.url end=`date +%s`; echo Duration `expr $end - $start` seconds. done