astrXbian/zen/mint_youtube.sh

94 lines
4.5 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
########################################################################
# Author: Fred (support@qo-op.com)
# Version: 2020.12.15
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
########################################################################
# Transfert ~/astroport/youtube and mp3 files to IPFS
# Create index in ~/.zen/ipfs/xbian/Y$XZUID
######## #### ### ## #
# ipfs add new file
# create ASTRXBIAN indexes in ~/.zen/ipfs/xbian/${PREFIX}${XZUID}
# unify swarm indexes in /var/www/astrxbian/${PREFIX}ASTRXBIAN
# Vstream/Astroport reads ${PREFIX}ASTRXBIAN through http://localhost:10021/
# Using Vstream/Pastebin file format
# https://github.com/Kodi-vStream/venom-xbmc-addons/wiki/Voir-et-partager-sa-biblioth%C3%A8que-priv%C3%A9e#d%C3%A9clarer-des-films
########################################################################
## ACTUAL inotifywait ~/astroport/ FILESYSTEM STRUCTURE
mkdir -p ~/astroport/youtube
mkdir -p ~/astroport/mp3
########################################################################
path="$1"
file="$2"
echo "~/.zen/astrXbian/zen/mint_youtube.sh \"$path\" \"$file\""
[[ "$file" == "" || "$path" == "" ]] && echo "ERROR. Parameters missing. xbian_vstream.sh file=$file? path=$path?"
extension="${file##*.}"
TITLE="${file%.*}"
# GET XZUID
[[ -f ~/.zen/ipfs/.${IPFSNODEID}/_xbian.zuid ]] && XZUID="$(cat ~/.zen/ipfs/.${IPFSNODEID}/_xbian.zuid)" || XZUID="$(hostname)"
# TODO use ~/.zen/ipfs/.$IPFSNODEID/
TYPE=$(echo "$path" | cut -d '/' -f 5 ) # ex: youtube, mp3
PREFIX=$(echo "$TYPE" | head -c 1 | awk '{ print toupper($0) }' ) # ex: Y, M
# file is placed in ROOT ~/astroport
[[ $PREFIX != "Y" || $PREFIX != "Y" ]] && echo "WARNING. $TYPE unrecognize, please add code for it ${path}${file}" && exit 1
echo "ADDING ${path}${file} IPFS INDEX to ~/.zen/ipfs/xbian/${PREFIX}${XZUID}"
echo "-----------------------------------------------------------------"
NEWSHARE=$(ipfs add -wq "${path}${file}" | tail -n 1)
[[ $NEWSHARE == "" ]] && echo "ipfs add ERROR" && exit 1
echo "-----------------------------------------------------------------"
echo "CHECK IPFS $file : ipfs ls /ipfs/$NEWSHARE"
echo "-----------------------------------------------------------------"
echo "UPDATE $TYPE INDEX in ~/.zen/ipfs/xbian/${PREFIX}${XZUID} "
mkdir -p ~/.zen/ipfs/xbian
# Init ${PREFIX}${XZUID} header
#[[ ! -f ~/.zen/ipfs/xbian/${PREFIX}${XZUID} ]] && echo "CAT;TITLE;URLS" > ~/.zen/ipfs/xbian/${PREFIX}${XZUID}
[[ ! -f ~/.zen/ipfs/xbian/${PREFIX}${XZUID} ]] && echo "CAT;TMDB;YEAR;TITLE;SAISON;GENRES;GROUPES;RES;URLS=http://localhost:10021" > ~/.zen/ipfs/xbian/${PREFIX}${XZUID}
rm ~/.zen/ipfs/xbian/${PREFIX}${XZUID}
## CHECK IF $NEWSHARE is NEW, or an already existing file to upgrade?
isFILEinINDEX=$(grep "$file" ~/.zen/ipfs/xbian/${PREFIX}${XZUID})
isLINKinINDEX=$(grep "$NEWSHARE" ~/.zen/ipfs/xbian/${PREFIX}${XZUID})
# Is it a new file? Add it to INDEX
if [[ ! $isFILEinINDEX && ! $isLINKinINDEX ]]; then
echo "ipfs get -o ~/astroport/$TYPE/ /ipfs/$NEWSHARE/$file" >> ~/.zen/ipfs/xbian/${PREFIX}${XZUID}
else
if [[ $isFILEinINDEX ]]; then
echo "$file already in index" ## File was updated => Change OLDLINK
OLDLINK=$(echo $isFILEinINDEX | cut -d "/" -f 5 | tail -n 1)
sed -i "s/$OLDLINK/$NEWSHARE/g" ~/.zen/ipfs/xbian/${PREFIX}${XZUID}
fi
[[ $isLINKinINDEX ]] && echo "$NEWSHARE already in index. DO NOTHING" ## should not happen
fi
########################################################################
echo "PUBLISH ~/.zen/ipfs to IPNS self for SWARM SHARING"
echo "-----------------------------------------------------------------"
MIPFS=$(ipfs add -rHq ~/.zen/ipfs | tail -n 1)
NODEIPNS=$(ipfs name publish --quieter /ipfs/$MIPFS)
echo "NOW SYNCing ALL SWARM..."
echo "-----------------------------------------------------------------"
~/.zen/astrXbian/zen/ipfs_SWARM_refresh.sh
echo "CREATE my local ${PREFIX}ASTRXBIAN ($TYPE) from ipfs_swarm found indexes"
echo "-----------------------------------------------------------------"
mkdir -p /tmp/xbian/
echo "CAT;TMDB;YEAR;TITLE;SAISON;GENRES;GROUPES;RES;URLS=http://localhost:10021" > /tmp/xbian/${PREFIX}ASTRXBIAN # CREATE INDEX HEADER
cat ~/.zen/ipfs_swarm/xbian/${PREFIX}* | grep -v -E 'CAT;TMDB' | cut -d ';' -f 9 >> /tmp/xbian/${PREFIX}ASTRXBIAN # GET ipfs get commands
cat /tmp/xbian/${PREFIX}ASTRXBIAN | uniq > /tmp/xbian/${PREFIX}ASTRXBIAN.uniq # REMOVE DUPLICATE INDEX
mv /tmp/xbian/${PREFIX}ASTRXBIAN.uniq /var/www/astrxbian/${PREFIX}ASTRXBIAN
echo "NEW $TYPE ($file) ADDED."
echo "INDEX UPDATED : http://localhost:10021/${PREFIX}ASTRXBIAN"