Browse Source

simpler rewriting

master
qo-op 1 year ago
parent
commit
98092ac305
  1. 66
      ajouter_video.sh
  2. 63
      zen/new_file_in_astroport.sh

66
ajouter_video.sh

@ -50,7 +50,7 @@ CHOICE=$(zenity --entry --width 300 --title="Catégorie" --text="Choisissez la c
# LOWER CARACTERS
CAT=$(echo "${CHOICE}" | awk '{print tolower($0)}')
PREFIX=$(echo "${CAT}" | head -c 1 | awk '{ print toupper($0) }' ) # ex: F, S, A, Y
PREFIX=$(echo "${CAT}" | head -c 1 | awk '{ print toupper($0) }' ) # ex: F, S, A, Y, M ...
[[ $PREFIX == "" ]] && exit 1
case ${CAT} in
@ -59,10 +59,10 @@ case ${CAT} in
########################################################################
youtube)
YTURL=$(zenity --entry --width 300 --title "Lien ou identifiant à copier" --text "Copiez le lien (URL) ou l'ID de la vidéo" --entry-text="")
YTURL=$(zenity --entry --width 300 --title "Lien ou identifiant à copier" --text "Indiquez le lien (URL) ou l'ID de la vidéo" --entry-text="")
[[ $YTURL == "" ]] && exit 1
# Create TEMP directory
# Create TEMP directory to copy $YID_$TITLE.$FILE_EXT
YTEMP="/tmp/$(date -u +%s%N | cut -b1-13)"
mkdir -p ${YTEMP}
@ -71,7 +71,6 @@ echo "VIDEO $YTURL"
/usr/local/bin/youtube-dl -f '[height=720]/best' \
--write-info-json --write-annotations \
--no-mtime -o "${YTEMP}/%(id)s_%(title)s.%(ext)s" $YTURL
CAT="youtube"
# Get filename, extract ID, make destination dir and move copy.
YFILE=$(ls -t ${YTEMP} | head -n 1)
@ -79,18 +78,23 @@ FILE_NAME="$(basename "${YFILE}")"
FILE_EXT="${FILE_NAME##*.}"
YID=$(echo "${FILE_NAME}" | cut -d "_" -f 1)
YNAME=$(echo "${FILE_NAME}" | cut -d "_" -f 2)
FILE_PATH="$HOME/astroport/$CAT/$YID"
mkdir -p ${FILE_PATH} && mv ${YTEMP}/* ${FILE_PATH}/
YNAME=$(echo "${FILE_NAME}" | cut -d "_" -f 2-)
TMDB="${YID}"
TMDB=$YID
FILE_PATH="$HOME/astroport/youtube/$YID"
mkdir -p ${FILE_PATH} && mv -f ${YTEMP}/* ${FILE_PATH}/
## CORRECT PARAMETERS to Make Kodi compatible YASTRXBIAN FILE
CAT="film"
PREFIX="Y"
TITLE="${YNAME%.*}"
GENRES="[Youtube]"
GROUPES="${XZUID}"
FILE_RES=$(ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 "${FILE_PATH}/${FILE_NAME}" | cut -d "x" -f 2)
RES=${FILE_RES%?}0p
rm -Rf ${YTEMP}
;;
########################################################################
@ -114,7 +118,8 @@ then
song=$(zenity --entry --width 300 --title "Titre à chercher sur Youtube" --text "Titre recherché" --entry-text="")
[[ $song == "" ]] && exit 1
else
song=""
song=$(zenity --entry --width 300 --title "Confirmer ID" --text "Titre recherché (ou confirmer la saisie précédente)" --entry-text="$artist")
[[ "$song" == "$artist" ]] && song=""
fi
# Download mp3 from 1st youtube search video result
@ -129,20 +134,18 @@ FILE_NAME="$(basename "${YFILE}")"
FILE_EXT="${FILE_NAME##*.}"
YID=$(echo "${FILE_NAME}" | cut -d "_" -f 1)
YNAME=$(echo "${FILE_NAME}" | cut -d "_" -f 2)
YNAME=$(echo "${FILE_NAME}" | cut -d "_" -f 2-)
FILE_PATH="$HOME/astroport/$CAT/$artist/$song"
mkdir -p "${FILE_PATH}" && mv ${YTEMP}/* "${FILE_PATH}/"
[[ ! $islink ]] && FILE_PATH="$HOME/astroport/$CAT/$artist/$song" \
|| FILE_PATH="$HOME/astroport/$CAT/${YID}"
TMDB=$YID
mkdir -p "${FILE_PATH}" && mv -f ${YTEMP}/* "${FILE_PATH}/"
TMDB="${YID}"
TITLE="${YNAME%.*}"
GENRES="[MP3]"
GROUPES="${XZUID}"
## TODO call mazash to get audiofingerprint
# curl -X POST "http://localhost:8600/api/v1/mazash/recognize" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"cid\":\"QmU3XRYZiebdDMcUwKrvecxyDgtgVY6zaNYrzQBeCkFb2r\",\"extension\":\".mp3\",\"song\":\"${TITLE}\"}"
rm -Rf ${YTEMP}
zenity --warning --width ${large} --text "DEBUG: MP3 copié dans ${FILE_PATH}"
@ -167,7 +170,7 @@ FILE_EXT="${FILE_NAME##*.}"
FILE_TITLE="${FILE_NAME%.*}"
# OPEN default browser and search TMDB
zenity --question --width 300 --text "IMPORTANT! Nous allons ouvrir le site themoviedb pour y récuperer le numéro d'identification"
zenity --question --width 300 --text "IMPORTANT! Nous allons ouvrir le site themoviedb pour y récuperer le numéro d'identification de votre vidéo"
[ $? == 1 ] && exit 1
xdg-open "https://www.themoviedb.org/search?query=${FILE_TITLE}"
@ -239,17 +242,19 @@ FILM_GENRES=$(zenity --list --checklist --title="GENRE" --height=${haut}\
GENRES="[\"$(echo ${FILM_GENRES} | sed s/\|/\",\"/g)\"]"
[[ $GENRES == "" ]] && exit 1
# VIDEO GROUP
GROUPES=$(zenity --entry --width 300 --title "Groupe" --text "Associez la vidéo à un groupe (optionnel). Exemple: PIXAR" --entry-text="${XZUID}")
# VIDEO GROUP (was XZUID, now becoming IPNS key)
# GROUPES=$(zenity --entry --width 300 --title "Groupe" --text "Associez la vidéo à un groupe (optionnel). Exemple: PIXAR" --entry-text="${XZUID}")
GROUPES="_IPNSKEY_" # USE GROUPS TO RECORD IPNS LINK : Replaced later
# DEBUG VERIFICATION
zenity --question --width ${large} --title "CONTROLE DES INFORMATIONS - EMBARQUEMENT ASTROPORT! OK?"\
--text "${CAT}; ${TMDB}; ${YEAR}; ${TITLE}; ${SAISON}; ${GENRES}; ${GROUPES}; ${RES} = ${FILE_NAME}"
[ $? == 1 ] && echo "ANNULATION." && exit 1
# zenity --question --width ${large} --title "EMBARQUEMENT ASTROPORT! OK?"\
# --text "${FILE_NAME} (${CAT};${TMDB};${YEAR};${TITLE};${SAISON};${GENRES};${GROUPES};${RES})"
# [ $? == 1 ] && echo "ANNULATION." && exit 1
### OK MOVING FILE TO ASTROPORT ####
mkdir -p ~/astroport/${CAT}/${TMDB}/
mv "${FILE_PATH}/${FILE_NAME}" "$HOME/astroport/${CAT}/${TMDB}/${TITLE}.${FILE_EXT}" && zenity --warning --width ${large} --text "Votre fichier ~/astroport/${CAT}/${TMDB}/${TITLE}.${FILE_EXT} est prêt à embarquer. Cliquez sur OK puis patientez quelques minutes..."
mv -f "${FILE_PATH}/${FILE_NAME}" "$HOME/astroport/${CAT}/${TMDB}/${TITLE}.${FILE_EXT}" && zenity --warning --width ${large} --text "Votre fichier ~/astroport/${CAT}/${TMDB}/${TITLE}.${FILE_EXT} est prêt à embarquer. Cliquez sur OK puis patientez quelques minutes..."
FILE_NAME="${TITLE}.${FILE_EXT}"
;;
@ -259,21 +264,24 @@ FILE_NAME="${TITLE}.${FILE_EXT}"
*)
zenity --warning --width ${large} --text "Impossible d'interpréter votre commande $CAT"
exit 1
;;
esac
## TRANSMIT "ajouter_video.txt"
########################################################################
## CREATE "~/astroport/${CAT}/${TMDB}/ajouter_video.txt"
########################################################################
URLENCODE_FILE_NAME=$(echo ${FILE_NAME} | jq -Rr @uri)
echo "${CAT};$TMDB;$YEAR;$TITLE;$SAISON;${GENRES};${GROUPES};$RES;/ipfs/_IPFSREPFILEID_/$URLENCODE_FILE_NAME" > ~/astroport/${CAT}/${TMDB}/ajouter_video.txt
echo "${CAT};${TMDB};${YEAR};${TITLE};${SAISON};${GENRES};${GROUPES};${RES};/ipfs/_IPFSREPFILEID_/$URLENCODE_FILE_NAME" > ~/astroport/${CAT}/${TMDB}/ajouter_video.txt
# _IPFSREPFILEID_ is replaced later
########################################################################
# ADD $FILE to IPFS / ASTROPORT / KODI
########################################################################
~/.zen/astrXbian/zen/new_file_in_astroport.sh "$HOME/astroport/${CAT}/${TMDB}/" "${FILE_NAME}"
~/.zen/astrXbian/zen/new_file_in_astroport.sh "$HOME/astroport/${CAT}/${TMDB}/" "${FILE_NAME}" > /tmp/${CAT}_${TMDB}.log 2>&1
########################################################################
########################################################################
[ $? == 0 ] && zenity --warning --width 300 --text "OK! Votre source vidéo $cat a été transférée dans Astroport" \
|| zenity --warning --width 300 --text "Désolé une erreur est survenue..."
[ $? == 0 ] && zenity --warning --width 300 --text "OK! Votre source vidéo $cat a été transférée dans Astroport" && exit 0 \
|| zenity --warning --width 300 --text "Désolé une erreur est survenue... LOG: /tmp/${CAT}_${TMDB}.log" && exit 1

63
zen/new_file_in_astroport.sh

@ -60,12 +60,14 @@ case ${CAT} in
youtube)
INDEXPREFIX="YOUTUBE_"
REFERENCE=$(echo "$file" | cut -d "_" -f 1) # Youtube filename starts with ID_
TITLE=$(echo "$TITLE" | cut -d "_" -f 2)
TITLE=$(echo "$TITLE" | cut -d "_" -f 2-)
;;
mp3)
## DIFFERENT TREATMENT
INDEXPREFIX="MP3_"
REFERENCE=$(echo "$file" | cut -d "_" -f 1) # Youtube filename starts with ID_
echo "Please use new_mp3_in_astroport.sh ... EXIT"
exit 1
;;
film | serie | anime)
INDEXPREFIX="TMDB_"
@ -86,18 +88,18 @@ if [[ ${isREFERENCEinINDEX} ]]
then
if [[ -d ~/.zen/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB} ]]
then
# FILE IS MINE, replacing it in INDEX
# FILE IS MINE, NEW VERSION?! replacing it in INDEX
ipnslink=$(cat ~/.zen/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/.ipns.link)
echo "FOUND IPNS ${INDEXPREFIX}${REFERENCE} = $ipnslink"
# DELETING GCHANGE AD
# DELETING GCHANGE AD, WILL BE CREATED AGAIN
gchangeAD=$(cat ~/.zen/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/.gchange.ad)
~/.zen/astrXbian/zen/jaklis/jaklis.py deleteoffer -i $gchangeAD
rm ~/.zen/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/.gchange.ad
else
echo "FILE IS ALREADY EXISTING FROM ANOTHER FRIEND"
echo ${isREFERENCEinINDEX}
# I could send message to my friend, PIN, exchange contract... TODO
echo ${isREFERENCEinINDEX} | head -n 1 | cut -d ":" -f 2-
# I could send message to my friend, PIN, exchange contract... WHAT IS BEST TODO ??
fi
# DELETING OLD LINE FROM INDEX
@ -160,7 +162,7 @@ echo "<meta http-equiv=\"Refresh\" content=\"0;URL=http://127.0.0.1:8181/ipfs/$I
IPNSLINK=$(ipfs key list -l | grep ${INDEXPREFIX}${REFERENCE} | cut -d ' ' -f 1)
echo "<meta http-equiv=\"Refresh\" content=\"10;URL=https://aries.copylaradio.com/ipns/$IPNSLINK/${G1PUB}/\">
<h1><a href='https://astroport.com'>ASTROPORT</a>/KODI</h1>
pour regarder <a target='tmdb' href='https://www.themoviedb.org/search?query=${TITLE}'>${TITLE}</a>, rejoignez notre video-club et devenons amis...<br><br>
Pour regarder <a target='tmdb' href='https://www.themoviedb.org/search?query=${TITLE}'>${TITLE}</a>, rejoignez notre video-club et devenons amis...<br><br>
Installez <a href='https://copylaradio.com'>astrXbian</a>" > ~/.zen/KEY/${INDEXPREFIX}${REFERENCE}/index.html
NEWIPFS=$(ipfs add -rHq ~/.zen/KEY/${INDEXPREFIX}${REFERENCE}/ | tail -n 1 )
@ -177,44 +179,35 @@ then
GOFFER=$(~/.zen/astrXbian/zen/jaklis/jaklis.py setoffer -t "${TITLE} #astroport #${INDEXPREFIX}${REFERENCE}" -d "https://aries.copylaradio.com/ipns/$IPNS/" -p ~/.zen/astrXbian/disk.png)
echo $GOFFER > ~/.zen/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/.gchange.ad
NEWIPFS=$(ipfs add -rHq ~/.zen/KEY/${INDEXPREFIX}${REFERENCE}/ | tail -n 1 )
IPNS=$(ipfs name publish --key="${INDEXPREFIX}${REFERENCE}" $NEWIPFS)
IPNS=$(ipfs name publish --quieter --key="${INDEXPREFIX}${REFERENCE}" $NEWIPFS)
fi
echo "Annonce gchange : $(cat ~/.zen/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/.gchange.ad)"
fi
########################################################################
# FIRST ${PREFIX}ASTRXBIAN header
[[ ! -f ~/.zen/ipfs/.${IPFSNODEID}/astroport/kodi/vstream/${PREFIX}ASTRXBIAN ]] && echo "CAT;TMDB;YEAR;TITLE;SAISON;GENRES;GROUPES;RES;URLS=http://127.0.0.1:8181" > ~/.zen/ipfs/.${IPFSNODEID}/astroport/kodi/vstream/${PREFIX}ASTRXBIAN
# NEW ${PREFIX}ASTRXBIAN FILE : Add header
[[ ! -f ~/.zen/ipfs/.${IPFSNODEID}/astroport/kodi/vstream/${PREFIX}ASTRXBIAN ]] \
&& echo "CAT;TMDB;YEAR;TITLE;SAISON;GENRES;GROUPES;RES;URLS=http://127.0.0.1:8181" > ~/.zen/ipfs/.${IPFSNODEID}/astroport/kodi/vstream/${PREFIX}ASTRXBIAN
## CHECK IF $IPFSREPFILEID is NEW, or an already existing in SWARMs?
# MEMORIZE NEW PIN
mkdir -p ~/.zen/ipfs/.${IPFSNODEID}/PIN/${IPFSREPFILEID}/
touch ~/.zen/ipfs/.${IPFSNODEID}/PIN/${IPFSREPFILEID}/${G1PUB}
isFILEinMYINDEX=$(grep "$URLENCODE_FILE_NAME" ~/.zen/ipfs/.${IPFSNODEID}/astroport/kodi/vstream/${PREFIX}ASTRXBIAN)
isLINKinMYINDEX=$(grep "$IPFSREPFILEID" ~/.zen/ipfs/.${IPFSNODEID}/astroport/kodi/vstream/${PREFIX}ASTRXBIAN)
# Is it a new file? Add it to INDEX
if [[ ! $isFILEinMYINDEX && ! $isLINKinMYINDEX ]]; then
mkdir -p ~/.zen/ipfs/.${IPFSNODEID}/PIN/${IPFSREPFILEID}/
touch ~/.zen/ipfs/.${IPFSNODEID}/PIN/${IPFSREPFILEID}/${G1PUB}
# SIMILAR with "ipfs ls /ipns/${IPFSNODEID}/.${IPFSNODEID}/PIN/ (...)"
# TODO: switch case $PREFIX
if [[ -f ~/.zen/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/ajouter_video.txt ]]
then
line=$(cat ~/.zen/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/ajouter_video.txt | sed "s/_IPFSREPFILEID_/$IPFSREPFILEID/g")
else
FILE_RES=$(ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 "${path}${file}" | cut -d "x" -f 2)
RES=${FILE_RES%?}0p
line="$CAT;${REFERENCE};$YEAR;$TITLE;$SAISON;;${XZUID};$RES;/ipfs/$IPFSREPFILEID/$URLENCODE_FILE_NAME"
fi
echo "$line" >> ~/.zen/ipfs/.${IPFSNODEID}/astroport/kodi/vstream/${PREFIX}ASTRXBIAN
# ADD NEW LINE TO INDEX
if [[ -f ~/.zen/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/ajouter_video.txt ]]
then
line=$(cat ~/.zen/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/ajouter_video.txt | sed "s/_IPFSREPFILEID_/$IPFSREPFILEID/g" | sed "s/_IPNSKEY_/$IPNS/g" )
else
FILE_RES=$(ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 "${path}${file}" | cut -d "x" -f 2)
RES=${FILE_RES%?}0p
line="$CAT;${REFERENCE};$YEAR;$TITLE;$SAISON;;${IPNS};$RES;/ipfs/$IPFSREPFILEID/$URLENCODE_FILE_NAME"
fi
echo "-------------------- UPDATE MY INDEX -----------------------------"
echo "$line"
echo "$line" >> ~/.zen/ipfs/.${IPFSNODEID}/astroport/kodi/vstream/${PREFIX}ASTRXBIAN
echo "~/.zen/ipfs/.${IPFSNODEID}/${PREFIX}ASTRXBIAN"
echo "-----------------------------------------------------------------"
cat ~/.zen/ipfs/.${IPFSNODEID}/astroport/kodi/vstream/${PREFIX}ASTRXBIAN ~/.zen/ipfs_swarm/.*/astroport/kodi/vstream/${PREFIX}* | sort | uniq > ~/.zen/ipfs/.${IPFSNODEID}/${PREFIX}ASTRXBIAN
echo "--------------- KODI INDEX UPDATED ----------------------"
# CLEAN all ipns keys except self
# for key in $(ipfs key list | grep -Ev 'self'); do ipfs key rm $key; done
echo "----------------- REFRESH GLOBAL KODI INDEX ----------------------"
cat ~/.zen/ipfs/.${IPFSNODEID}/astroport/kodi/vstream/${PREFIX}ASTRXBIAN ~/.zen/ipfs_swarm/.*/astroport/kodi/vstream/${PREFIX}ASTRXBIAN | sort | uniq > ~/.zen/ipfs/.${IPFSNODEID}/${PREFIX}ASTRXBIAN
########################################################################
# REFRESH IPNS SELF PUBLISH

Loading…
Cancel
Save