#!/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)) ######################################################################## # CHECK for Kodi + astroport.py IPFSNODEID=$(ipfs id -f='\n') if [[ -f ~/.zen/astroport.py ]] then ## NORMAL behaviour (ISOConfig.sh made the Job) ## astroport.py already created (refresh vstream plugin,in case update erase it) cp ~/.zen/astroport.py ~/.kodi/addons/plugin.video.vstream/resources/sites/astroport.py else ## astroport.py missing cp -f ~/.zen/astrXbian/.install/.kodi/addons/plugin.video.vstream/resources/sites/astroport.py ~/.zen/astroport.py ## CONFIGURE ASTROPORT ACCOUNT # Make xbian G1BILLET or ASK for it? zenity --warning --width 300 --text "Vous devez avoir un compte Gchange.fr pour utiliser ASTROPORT / KODI" zenity --question --width 300 --text "Avez vous déjà un compte sur Gchange.fr ?" [ $? == 1 ] && xdg-open "https://gchange.fr" #sed -i "s/_PROFIL_/$XZUID/g" ~/.zen/astroport.py #sed -i "s/_LOGIN_/$salt/g" ~/.zen/astroport.py #sed -i "s/_MDP_/$pepper/g" ~/.zen/astroport.py sed -i "s/_IPFSNODEID_/$IPFSNODEID/g" ~/.zen/astroport.py cp ~/.zen/astroport.py ~/.kodi/addons/plugin.video.vstream/resources/sites/astroport.py fi ## GET XZUID [[ -f ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_g1.gchange_title ]] && XZUID=$(cat ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_g1.gchange_title) || XZUID=$(hostname) zenity --warning --width 300 --text "Ajoutez une vidéo à ASTROPORT/KODI" # CHOOSE CATEGORY CHOICE=$(zenity --entry --width 300 --title="Catégorie" --text="Choisissez la catégorie de votre vidéo" --entry-text="Film" Serie Anime Youtube) [[ $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 [[ $PREFIX == "" ]] && exit 1 case ${PREFIX} in ######################################################################## # CASE ## YOUTUBE ######################################################################## Y) 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 == "" ]] && exit 1 # Create TEMP directory 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 CAT="youtube" # 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) FILE_PATH="$HOME/astroport/$CAT/$YID" mkdir -p ${FILE_PATH} && mv ${YTEMP}/* ${FILE_PATH}/ TMDB=$YID TITLE="${YNAME%.*}" GENRES="[Youtube]" GROUPES="${XZUID}" rm -Rf ${YTEMP} ;; ######################################################################## # CASE ## MP3 ######################################################################## M) # Create TEMP directory YTEMP="/tmp/$(date -u +%s%N | cut -b1-13)" mkdir -p ${YTEMP} artist=$(zenity --entry --width 300 --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 fi # Download mp3 from 1st youtube search video result /usr/local/bin/youtube-dl --default-search ytsearch1: --download-archive /home/$USER/.ytdl.list \ --continue --no-overwrites --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" # 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) FILE_PATH="$HOME/astroport/$CAT/$artist/" mkdir -p ${FILE_PATH} && mv ${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} ;; ######################################################################## # CASE ## DEFAULT ######################################################################## *) # 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" [ $? == 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: https://www.themoviedb.org/movie/301528-toy-story-4 => 301528" --entry-text="") [[ $TMDB == "" ]] && exit 1 # 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) # 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="${XZUID}") # 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 ### 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..." FILE_NAME="${TITLE}.${FILE_EXT}" ;; esac ## TRANSMIT "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 ######################################################################## # ADD $FILE to IPFS / ASTROPORT / KODI ######################################################################## ~/.zen/astrXbian/zen/new_file_in_astroport.sh "$HOME/astroport/${CAT}/${TMDB}/" "${FILE_NAME}" ######################################################################## ######################################################################## [ $? == 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..."