forked from axiom-team/astrXbian
309 lines
13 KiB
Bash
Executable File
309 lines
13 KiB
Bash
Executable File
#!/bin/bash
|
||
########################################################################
|
||
# Author: Fred (support@qo-op.com)
|
||
# Version: 0.1
|
||
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
|
||
########################################################################
|
||
# SCRIPT INTERACTIF POUR AJOUTER UN FICHIER à ASTROPORT/KODI
|
||
#
|
||
# 1. CAT: film, serie, anime
|
||
# 2. TMDB: ID de la fiche sur https://www.themoviedb.org/
|
||
# 3. TITLE: Titre de la vidéo
|
||
# 4. YEAR: Année de la vidéo
|
||
# 5. RES: Résolution 1080p, 4K, SD, 720, HD
|
||
# 6. SAISON: Pour les séries et animes, c'est le numéro de saison.
|
||
# Pour un film, le champ SAISON est utilisé pour renseigner la Saga
|
||
# 7. GENRES: Action, Aventure, Fantastique, Animation, etc (choix multiple).
|
||
# 8. GROUPES: Permet de regrouper des films. (choix multiple)
|
||
#
|
||
# https://github.com/Kodi-vStream/venom-xbmc-addons/wiki/Voir-et-partager-sa-biblioth%C3%A8que-priv%C3%A9e#d%C3%A9clarer-des-films
|
||
########################################################################
|
||
MY_PATH="`dirname \"$0\"`" # relative
|
||
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
|
||
ME="${0##*/}"
|
||
########################################################################
|
||
[[ $(which ipfs) == "" ]] && echo "ERREUR! Installez ipfs" && echo "wget https://git.p2p.legal/axiom-team/astrXbian/raw/master/.install/ipfs_alone.sh -O /tmp/ipfs_install.sh && chmod +x /tmp/ipfs_install.sh && /tmp/ipfs_install.sh" && exit 1
|
||
[[ $(which zenity) == "" ]] && echo "ERREUR! Installez zenity" && echo "sudo apt install zenity" && exit 1
|
||
[[ $(which ffmpeg) == "" ]] && echo "ERREUR! Installez ffmpeg" && echo "sudo apt install ffmpeg" && exit 1
|
||
[[ $(which xdpyinfo) == "" ]] && echo "ERREUR! Installez x11-utils" && echo "sudo apt install x11-utils" && exit 1
|
||
|
||
# REMOVE GtkDialog errors for zenity
|
||
shopt -s expand_aliases
|
||
alias zenity='zenity 2> >(grep -v GtkDialog >&2)'
|
||
|
||
# GET SCREEN DIMENSIONS
|
||
screen=$(xdpyinfo | grep dimensions | sed -r 's/^[^0-9]*([0-9]+x[0-9]+).*$/\1/')
|
||
width=$(echo $screen | cut -d 'x' -f 1)
|
||
height=$(echo $screen | cut -d 'x' -f 2)
|
||
large=$((width-300))
|
||
haut=$((height-200))
|
||
|
||
########################################################################
|
||
IPFSNODEID=$(ipfs id -f='<id>\n')
|
||
[[ -f ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_g1.gchange_title ]] && XZUID=$(cat ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_g1.gchange_title) || XZUID=$(cat /etc/hostname)
|
||
[[ -f ~/.zen/ipfs/.$IPFSNODEID/_xbian.zuid ]] && AXID=$(cat ~/.zen/ipfs/.$IPFSNODEID/_xbian.zuid)
|
||
|
||
zenity --warning --width 300 --text "Ajoutez une vidéo à ASTROPORT/KODI"
|
||
|
||
# CHOOSE CATEGORY (remove anime, not working!)
|
||
CHOICE=$(zenity --entry --width 300 --title="Catégorie" --text="Choisissez la catégorie de votre vidéo" --entry-text="Film" Anime Serie Youtube MP3)
|
||
[[ $CHOICE == "" ]] && exit 1
|
||
|
||
# LOWER CARACTERS
|
||
CAT=$(echo "${CHOICE}" | awk '{print tolower($0)}')
|
||
PREFIX=$(echo "${CAT}" | head -c 1 | awk '{ print toupper($0) }' ) # ex: F, S, A, Y, M ...
|
||
[[ $PREFIX == "" ]] && exit 1
|
||
|
||
case ${CAT} in
|
||
########################################################################
|
||
# CASE ## YOUTUBE
|
||
########################################################################
|
||
youtube)
|
||
|
||
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 to copy $YID_$TITLE.$FILE_EXT
|
||
YTEMP="/tmp/$(date -u +%s%N | cut -b1-13)"
|
||
mkdir -p ${YTEMP}
|
||
|
||
# youtube-dl $YTURL
|
||
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
|
||
|
||
# Get filename, extract ID, make destination dir and move copy.
|
||
YFILE=$(ls -t ${YTEMP} | head -n 1)
|
||
FILE_NAME="$(basename "${YFILE}")"
|
||
FILE_EXT="${FILE_NAME##*.}"
|
||
|
||
YID=$(echo "${FILE_NAME}" | cut -d "&" -f 1)
|
||
YNAME=$(echo "${FILE_NAME}" | cut -d "&" -f 2- | sed "s/[(][^)]*[)]//g" | sed "s/;/ /g" |sed "s/'/ /g" | sed "s/\"/ /g" | sed "s/&/ /g" ) # Remove YoutubeID_ and (what is in perentheses)
|
||
TMDB="${YID}"
|
||
|
||
FILE_PATH="$HOME/astroport/youtube/$YID"
|
||
mkdir -p ${FILE_PATH} && mv -f ${YTEMP}/* ${FILE_PATH}/
|
||
# Remove "&" from FILE_NAME rename to YNAME
|
||
mv "${FILE_PATH}/${FILE_NAME}" "${FILE_PATH}/${YNAME}" && FILE_NAME="${YNAME}"
|
||
|
||
## CORRECT PARAMETERS to Make Kodi compatible YASTRXBIAN FILE
|
||
TITLE="${YNAME%.*}"
|
||
GENRES="[\"$AXID\"]"
|
||
GROUPES="_IPNSKEY_" # USE GROUPS TO RECORD IPNS MEDIAKEY
|
||
|
||
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
|
||
|
||
## CREATE "~/astroport/${CAT}/${TMDB}/ajouter_video.txt" (with film CAT !!!)
|
||
URLENCODE_FILE_NAME=$(echo ${FILE_NAME} | jq -Rr @uri)
|
||
echo "film;${TMDB};${YEAR};${TITLE};${SAISON};${GENRES};${GROUPES};${RES};/ipfs/_IPFSREPFILEID_/$URLENCODE_FILE_NAME" > ~/astroport/${CAT}/${TMDB}/ajouter_video.txt
|
||
# _IPFSREPFILEID_ is replaced later
|
||
|
||
rm -Rf ${YTEMP}
|
||
|
||
;;
|
||
|
||
########################################################################
|
||
# CASE ## MP3
|
||
########################################################################
|
||
mp3)
|
||
|
||
zenity --warning --width ${large} --text 'MP3 DEV ALPHA CODE !!! EN TRAVAUX !!! RISQUE DE NE PAS FONCTIONNER... CONSEIL ANNULER ENSUITE'
|
||
|
||
# Create TEMP directory
|
||
YTEMP="/tmp/$(date -u +%s%N | cut -b1-13)"
|
||
mkdir -p ${YTEMP}
|
||
|
||
artist=$(zenity --entry --width 400 --title "Extraction MP3 depuis Youtube" --text "Artiste recherché ou Lien Youtube" --entry-text="")
|
||
[[ $artist == "" ]] && exit 1
|
||
|
||
## CHECK if artist is LINK or ID
|
||
length=${#artist}
|
||
islink=$(echo "$artist" | grep "http")
|
||
if [[ ! $islink && $length != 11 ]]
|
||
then
|
||
# Ask for song name
|
||
song=$(zenity --entry --width 300 --title "Titre à chercher sur Youtube" --text "Titre recherché" --entry-text="")
|
||
[[ $song == "" ]] && exit 1
|
||
else
|
||
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 (--write-info-json)
|
||
/usr/local/bin/youtube-dl --default-search ytsearch1: \
|
||
--ignore-errors --no-mtime \
|
||
--embed-thumbnail --metadata-from-title "%(artist)s - %(title)s" --add-metadata \
|
||
--extract-audio --audio-format mp3 -o "${YTEMP}/%(id)s&%(title)s.%(ext)s" "$artist $song"
|
||
|
||
ls ${YTEMP}
|
||
# Get filename, extract ID, make destination dir and move copy.
|
||
YFILE=$(ls -t ${YTEMP} | head -n 1)
|
||
FILE_NAME="$(basename "${YFILE}")"
|
||
FILE_EXT="${FILE_NAME##*.}"
|
||
|
||
YID=$(echo "${FILE_NAME}" | cut -d "&" -f 1)
|
||
YNAME=$(echo "${FILE_NAME}" | cut -d "&" -f 2- | sed "s/[(][^)]*[)]//g" | sed "s/;/ /g" |sed "s/'/ /g" | sed "s/\"/ /g" | sed "s/&/ /g" ) # Remove YoutubeID_ and (what is in perentheses)
|
||
|
||
[[ ! $islink && "$song" != "" ]] && FILE_PATH="$HOME/astroport/$CAT/$artist/_o-o_" \
|
||
|| FILE_PATH="$HOME/astroport/$CAT/${YID}"
|
||
|
||
mkdir -p "${FILE_PATH}" && mv -f ${YTEMP}/* "${FILE_PATH}/"
|
||
# Remove "&" from FILE_NAME rename to YNAME
|
||
mv "${FILE_PATH}/${FILE_NAME}" "${FILE_PATH}/${YNAME}" && FILE_NAME="${YNAME}"
|
||
|
||
TMDB="${YID}"
|
||
TITLE="${YNAME%.*}"
|
||
GENRES="[\"$AXID\"]"
|
||
GROUPES="_IPNSKEY_" # USE GROUPS TO RECORD IPNS MEDIAKEY
|
||
|
||
rm -Rf ${YTEMP}
|
||
# zenity --warning --width ${large} --text "MP3 copié"
|
||
echo "~/.zen/astrXbian/zen/new_mp3_in_astroport.sh \"${FILE_PATH}/\" \"${FILE_NAME}\""
|
||
~/.zen/astrXbian/zen/new_mp3_in_astroport.sh "${FILE_PATH}/" "${FILE_NAME}" > /tmp/${CAT}_${TMDB}.log 2>&1
|
||
|
||
cat /tmp/${CAT}_${TMDB}.log
|
||
|
||
exit 0
|
||
|
||
;;
|
||
|
||
########################################################################
|
||
# CASE ## film serie anime
|
||
########################################################################
|
||
film | serie | anime)
|
||
|
||
# SELECT FILE TO ADD TO ASTROPORT/KODI
|
||
FILE=$(zenity --file-selection --title="Sélectionner le fichier à ajouter")
|
||
echo "${FILE}"
|
||
[[ $FILE == "" ]] && exit 1
|
||
|
||
# Remove file extension to get file name => STITLE
|
||
FILE_PATH="$(dirname "${FILE}")"
|
||
FILE_NAME="$(basename "${FILE}")"
|
||
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 de votre vidéo"
|
||
[ $? == 1 ] && exit 1
|
||
xdg-open "https://www.themoviedb.org/search?query=${FILE_TITLE}"
|
||
|
||
TMDB=$(zenity --entry --title="Identification TMDB" --text="Indiquez le numéro de la fiche du film. Exemple: 301528 (à extraire du lien https://www.themoviedb.org/movie/301528-toy-story-4)" --entry-text="")
|
||
[[ $TMDB == "" ]] && exit 1
|
||
if ! [[ "$TMDB" =~ ^[0-9]+$ ]]
|
||
then
|
||
zenity --warning --width ${large} --text "Vous devez renseigner un numéro! Merci de recommencer..." && exit 1
|
||
fi
|
||
|
||
|
||
# VIDEO TITLE
|
||
TITLE=$(zenity --entry --width 300 --title "Titre" --text "Indiquez le titre de la vidéo" --entry-text="${FILE_TITLE}")
|
||
[[ $TITLE == "" ]] && exit 1
|
||
|
||
# VIDEO YEAR
|
||
YEAR=$(zenity --entry --width 300 --title "Année" --text "Indiquez année de la vidéo. Exemple: 1985" --entry-text="")
|
||
|
||
# VIDEO RESOLUTION
|
||
FILE_RES=$(ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 "${FILE}" | cut -d "x" -f 2)
|
||
RES=${FILE_RES%?}0p # Rounding. Replace last digit with 0
|
||
#RES=$(zenity --entry --width 300 --title="Résolution" --text="Résolution de la vidéo" --entry-text="${FILE_RES}" SD HD 4K 360p 480p 720p 1080p)
|
||
|
||
# VIDEO SEASON or SAGA
|
||
[[ "${CAT}" == "serie" || "${CAT}" == "anime" ]] && SAISON=$(zenity --entry --width 300 --title "${CHOICE} Saison" --text "Indiquez SAISON et EPISODE. Exemple: S02E05" --entry-text="")
|
||
[[ "${CAT}" == "film" ]] && SAISON=$(zenity --entry --width 300 --title "${CHOICE} Saga" --text "Indiquez une SAGA (optionnel). Exemple: James Bond" --entry-text="")
|
||
|
||
# VIDEO GENRES
|
||
FILM_GENRES=$(zenity --list --checklist --title="GENRE" --height=${haut}\
|
||
--text="Choisissez le(s) genre(s) de la vidéo \"${TITLE}\""\
|
||
--column="Use"\
|
||
--column="Feature"\
|
||
FALSE '+18'\
|
||
FALSE Action\
|
||
FALSE Animation\
|
||
FALSE 'Arts martiaux'\
|
||
FALSE Aventure\
|
||
FALSE Autre\
|
||
FALSE Biographie\
|
||
FALSE Biopic\
|
||
FALSE Comedie\
|
||
FALSE 'Comedie dramatique'\
|
||
FALSE 'Comedie musicale'\
|
||
FALSE Crime\
|
||
FALSE Documentaire\
|
||
FALSE Drame\
|
||
FALSE Divers\
|
||
FALSE Educatif\
|
||
FALSE Enfant\
|
||
FALSE 'Epouvante horreur'\
|
||
FALSE Espionnage\
|
||
FALSE Famille\
|
||
FALSE Fantastique\
|
||
FALSE Guerre\
|
||
FALSE Histoire\
|
||
FALSE Historique\
|
||
FALSE Judiciaire\
|
||
FALSE Opera\
|
||
FALSE Medical\
|
||
FALSE Musique\
|
||
FALSE Mystere\
|
||
FALSE Peplum\
|
||
FALSE Policier\
|
||
FALSE Romance\
|
||
FALSE 'Science fiction'\
|
||
FALSE Soap\
|
||
FALSE Spectacle\
|
||
FALSE Sport\
|
||
FALSE Telefilm\
|
||
FALSE Thriller\
|
||
FALSE Western\
|
||
TRUE ${AXID// /-})
|
||
|
||
# FORMAT GENRES ["genre1","genre2"]
|
||
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="${AXID}")
|
||
GROUPES="_IPNSKEY_" # USE GROUPS TO RECORD G1PUB_MEDIAKEY
|
||
|
||
# DEBUG VERIFICATION
|
||
# 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 -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}"
|
||
|
||
## 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
|
||
# _IPFSREPFILEID_ is replaced later
|
||
|
||
;;
|
||
|
||
########################################################################
|
||
# CASE ## DEFAULT
|
||
########################################################################
|
||
*)
|
||
|
||
zenity --warning --width ${large} --text "Impossible d'interpréter votre commande $CAT"
|
||
exit 1
|
||
|
||
;;
|
||
|
||
esac
|
||
|
||
########################################################################
|
||
# ADD $FILE to IPFS / ASTROPORT / KODI
|
||
########################################################################
|
||
~/.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 vidéo a été transférée dans Astroport (/tmp/${CAT}_${TMDB}.log)" && exit 0 \
|
||
|| zenity --warning --width ${large} --height=${haut} --text "Désolé une erreur est survenue... LOG: cat /tmp/${CAT}_${TMDB}.log" && exit 1
|