first commit

This commit is contained in:
Boris Paing 2021-03-12 19:41:24 +01:00
commit 6051609dab
24 changed files with 1007 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
astroport
astrXbian
me
swarm

0
README.md Normal file
View File

89
ajouter_video_youtube.sh Executable file
View File

@ -0,0 +1,89 @@
#!/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
########################################################################
HOME=`cat conf/home_dir.txt`
########################################################################
MY_PATH="`dirname \"$0\"`" # relative
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
ME="${0##*/}"
########################################################################
########################################################################
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)
########################################################################
# CASE ## 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=$1
[[ $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-)
TMDB="${YID}"
FILE_PATH="$HOME/astroport/youtube/$YID"
echo "Creating directory $FILE_PATH"
mkdir -p -v --mode=775 $FILE_PATH || echo "Directory creation failed :-("
echo "Moving files there..."
mv -f ${YTEMP}/* ${FILE_PATH}/
## CORRECT PARAMETERS to Make Kodi compatible YASTRXBIAN FILE
TITLE="${YNAME%.*}"
GENRES="[Youtube]"
GROUPES="_IPNSKEY_"
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/youtube/${TMDB}/ajouter_video.txt
# _IPFSREPFILEID_ is replaced later
rm -Rf ${YTEMP}
########################################################################
# ADD $FILE to IPFS / ASTROPORT / KODI
########################################################################
./new_youtube_video_in_astroport.sh "$HOME/astroport/youtube/${TMDB}/" "${FILE_NAME}" > /tmp/youtube_${TMDB}.log 2>&1
########################################################################
########################################################################
exit 0

5
cat.php Normal file
View File

@ -0,0 +1,5 @@
<?php
exec('cat ./{me,swarm}/.*/astroport/kodi/vstream/YASTRXBIAN | sort | uniq | tail -n +2', $files);
echo '<pre>'; print_r($files); echo '</pre>';

22
conf/conf.php Normal file
View File

@ -0,0 +1,22 @@
<?php
define('HOST', '127.0.0.1:8181');
/*
Youtube Thumbnails
maxresdefault Full resolution image matching the uploaded. This image will not always exist.
sddefault 640x480
hqdefault 480x360 Large Preview
mqdefault 320x180 Large Preview
default 120x 90 Large Preview
0 480x360 Large Preview
1 120x 90 First small thumbnail
2 120x 90 Second small thumbnail
3 120x 90 Third small thumbnail
*/
define('YOUTUBE_THUMB', 'https://i.ytimg.com/vi/%s/mqdefault.jpg');
define('SITENAME', '<span>Astrobunker</span>');
define('USP', 'Votre caverne remplie des <strong>trésors</strong> que vous avez découverts sur le web, votre <strong>forteresse</strong> de contenu imprenable, votre <strong>palais</strong> informationnel.');

1
conf/home_dir.txt Normal file
View File

@ -0,0 +1 @@
/home/boris

View File

@ -0,0 +1,13 @@
$ ./ajouter_video_youtube.sh https://www.youtube.com/watch?v=2JYJF9L5YW4
Error: error loading plugins: open /home/boris/.ipfs/config: permission denied
./ajouter_video_youtube.sh: ligne 31:  XZUID=boris-ThinkPad-T420 : commande introuvable
VIDEO https://www.youtube.com/watch?v=2JYJF9L5YW4
[youtube] 2JYJF9L5YW4: Downloading webpage
WARNING: There are no annotations to write.
[info] Writing video description metadata as JSON to: /tmp/1615547666114/2JYJF9L5YW4_NPC rides his bike into the mayor.info.json
[download] Destination: /tmp/1615547666114/2JYJF9L5YW4_NPC rides his bike into the mayor.mp4
[download] 100% of 988.39KiB in 00:00
mkdir: impossible de créer le répertoire «~»: Permission non accordée
~/astroport/youtube/2JYJF9L5YW4/2JYJF9L5YW4_NPC rides his bike into the mayor.mp4: No such file or directory
./ajouter_video_youtube.sh: ligne 73: /home/boris/astroport/youtube/2JYJF9L5YW4/ajouter_video.txt: Aucun fichier ou dossier de ce type
./ajouter_video_youtube.sh: ligne 82: /tmp/youtube_2JYJF9L5YW4.log: Permission non accordée

10
erreurs/permissions-2.log Normal file
View File

@ -0,0 +1,10 @@
Error: error loading plugins: open /home/boris/.ipfs/config: permission denied
cat: /home/boris/.zen/secret.dunikey: Permission denied
~/.zen/www/new_youtube_video_in_astroport.sh PATH/ "/home/boris/astroport/youtube/2JYJF9L5YW4/" FILE "2JYJF9L5YW4_NPC rides his bike into the mayor.mp4"
./new_youtube_video_in_astroport.sh: line 45: $'\302\240XZUID=boris-ThinkPad-T420': command not found
SEARCH for ;2JYJF9L5YW4; in YASTRXBIAN
ADDING /home/boris/astroport/youtube/2JYJF9L5YW4/2JYJF9L5YW4_NPC rides his bike into the mayor.mp4 to IPFS and create YASTRXBIAN INDEX
~/.zen/ipfs/./astroport/kodi/vstream/YASTRXBIAN
-----------------------------------------------------------------
Error: error loading plugins: open /home/boris/.ipfs/config: permission denied
ipfs add ERROR

4
erreurs/permissions.log Normal file
View File

@ -0,0 +1,4 @@
Error: error loading plugins: open /home/boris/.ipfs/config: permission denied
cat: /home/boris/.zen/secret.dunikey: Permission denied
./astrXbian/zen/new_file_in_astroport.sh PATH/ "/home/boris/astroport/youtube/KaqC5FnvAEc/" FILE "KaqC5FnvAEc_Trolling Saruman.mp4"
NO FILE

50
erreurs/succes.log Normal file
View File

@ -0,0 +1,50 @@
Checking if the file exists at :
/home/boris/astroport/youtube/hpjV962DLWs/hpjV962DLWs_Vladimir Cauchemar - Aulos (Official Music Video).mp4
in ~/.zen/www/new_youtube_video_in_astroport.sh
SEARCH for ;hpjV962DLWs; in YASTRXBIAN
ADDING /home/boris/astroport/youtube/hpjV962DLWs/hpjV962DLWs_Vladimir Cauchemar - Aulos (Official Music Video).mp4 to IPFS and create YASTRXBIAN INDEX
~/.zen/ipfs/.12D3KooWHLLohhFqwTs3Ccego51w1Q2WUQ8JmhSMWtsZnQpMigHY/astroport/kodi/vstream/YASTRXBIAN
-----------------------------------------------------------------
-----------------------------------------------------------------
IPFS: hpjV962DLWs_Vladimir Cauchemar - Aulos (Official Music Video).mp4 : ipfs ls /ipfs/QmZMTghrSQgi45Xm8Pt7Vg2ShigdsCYvCurVqY7fUU7qGS
-----------------------------------------------------------------
New youtube INDEX ~/.zen/ipfs/.12D3KooWHLLohhFqwTs3Ccego51w1Q2WUQ8JmhSMWtsZnQpMigHY/astroport/kodi/vstream/YASTRXBIAN
ls: cannot access '/home/boris/.ipfs/keystore/key_lfhvkvcvijcv62juoffwws2yo5rwuqi': Permission denied
ls: cannot access '/home/boris/.ipfs/keystore/key_lfhvkvcvijcv66tlkrtdatdniryuwsi': Permission denied
ls: cannot access '/home/boris/.ipfs/keystore/key_lfhvkvcvijcv6v3rnnhdowdenrgvkui': Permission denied
ls: cannot access '/home/boris/.ipfs/keystore/key_lfhvkvcvijcv64kbmjsgsnbznfguqsi': Permission denied
ls: cannot access '/home/boris/.ipfs/keystore/key_krguiqs7gy4dm': Permission denied
ls: cannot access '/home/boris/.ipfs/keystore/key_krguiqs7gezdomi': Permission denied
ls: cannot access '/home/boris/.ipfs/keystore/key_lfhvkvcvijcv6ntjkryvi6bwpblxmui': Permission denied
ls: cannot access '/home/boris/.ipfs/keystore/key_lfhvkvcvijcv6wskkntvg6kxne3dc3y': Permission denied
ls: cannot access '/home/boris/.ipfs/keystore/key_lfhvkvcvijcv6qjslf5ewv3vivexq4y': Permission denied
ls: cannot access '/home/boris/.ipfs/keystore/key_lfhvkvcvijcv6wldn5jxunbrpfmukma': Permission denied
ls: cannot access '/home/boris/.ipfs/keystore/key_lfhvkvcvijcv6ykvgbxgc6svkvjuiqi': Permission denied
ls: cannot access '/home/boris/.ipfs/keystore/key_lfhvkvcvijcv65rtjrsgw33sinbwuti': Permission denied
ls: cannot access '/home/boris/.ipfs/keystore/key_lfhvkvcvijcv6sligfghk3swnjreizy': Permission denied
ls: cannot access '/home/boris/.ipfs/keystore/key_lfhvkvcvijcv6msgorrs2r2xjjdtcvi': Permission denied
ls: cannot access '/home/boris/.ipfs/keystore/key_lfhvkvcvijcv632wgjnfavjnnbvtgwi': Permission denied
ls: cannot access '/home/boris/.ipfs/keystore/key_lfhvkvcvijcv6ucrjbifszlmofzdari': Permission denied
ls: cannot access '/home/boris/.ipfs/keystore/key_lfhvkvcvijcv62lviy3eg4cnjqzusui': Permission denied
ls: cannot access '/home/boris/.ipfs/keystore/key_lfhvkvcvijcv633bozgxivkxirbfiti': Permission denied
ls: cannot access '/home/boris/.ipfs/keystore/key_lfhvkvcvijcv6r3kii3ggy2wonyfena': Permission denied
ls: cannot access '/home/boris/.ipfs/keystore/key_lfhvkvcvijcv633ige2davkonrbucma': Permission denied
ls: cannot access '/home/boris/.ipfs/keystore/key_lfhvkvcvijcv6njzom2fm5trkbrequi': Permission denied
ls: cannot access '/home/boris/.ipfs/keystore/key_lfhvkvcvijcv6v2ggm2e4ndhjjauwri': Permission denied
ls: cannot access '/home/boris/.ipfs/keystore/key_lfhvkvcvijcv6nrtjm2xmtl2pfwge3y': Permission denied
ls: cannot access '/home/boris/.ipfs/keystore/key_pbrgsylo': Permission denied
ls: cannot access '/home/boris/.ipfs/keystore/key_lfhvkvcvijcv62dqnjldsnrsirgfo4y': Permission denied
ls: cannot access '/home/boris/.ipfs/keystore/key_lfhvkvcvijcv62keo5yuorzq': Permission denied
ls: cannot access '/home/boris/.ipfs/keystore/key_lfhvkvcvijcv643pgjbfqljynz3fqzy': Permission denied
ls: cannot access '/home/boris/.ipfs/keystore/key_lfhvkvcvijcv6tbzizvucytxmfxw6qi': Permission denied
ls: cannot access '/home/boris/.ipfs/keystore/key_lfhvkvcvijcv6mdso5shatkvn54tqzy': Permission denied
ls: cannot access '/home/boris/.ipfs/keystore/key_lfhvkvcvijcv6odflbvdsn3torreooa': Permission denied
./new_youtube_video_in_astroport.sh: line 149: /home/boris/.zen/webui/tools/natools.py: No such file or directory
./new_youtube_video_in_astroport.sh: line 158: /home/boris/.zen/webui/tools/natools.py: No such file or directory
-------------------- UPDATE MY INDEX -----------------------------
film;hpjV962DLWs;;Vladimir Cauchemar - Aulos (Official Music Video);;[Youtube];k51qzi5uqu5dk28g6cg9s58eesfg0r94zupduir4hsme7dyc4x793w0kfluqdm;360p;/ipfs/QmZMTghrSQgi45Xm8Pt7Vg2ShigdsCYvCurVqY7fUU7qGS/hpjV962DLWs_Vladimir%20Cauchemar%20-%20Aulos%20(Official%20Music%20Video).mp4
----------------- REFRESH GLOBAL KODI INDEX ----------------------
PUBLISHING ~/.zen/ipfs SELF /ipns/12D3KooWHLLohhFqwTs3Ccego51w1Q2WUQ8JmhSMWtsZnQpMigHY
NEW youtube (hpjV962DLWs_Vladimir Cauchemar - Aulos (Official Music Video).mp4) ADDED.
INDEX UPDATED : http://127.0.0.1:8181/ipns/12D3KooWHLLohhFqwTs3Ccego51w1Q2WUQ8JmhSMWtsZnQpMigHY/.12D3KooWHLLohhFqwTs3Ccego51w1Q2WUQ8JmhSMWtsZnQpMigHY/YASTRXBIAN
VIDEO IPNS LINK : http://127.0.0.1:8181/ipns/k51qzi5uqu5dk28g6cg9s58eesfg0r94zupduir4hsme7dyc4x793w0kfluqdm/8WydxZg8kZbYnj9GAUGbEbwfz55fk1MsZJWYQRfTpjZc/

66
functions.php Normal file
View File

@ -0,0 +1,66 @@
<?php
function getCollectionType ($filename) {
switch (substr($filename, 0, 1)) {
case 'F': return 'Films';
case 'Y': return 'Youtube';
}
}
function pingFile ($url) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
//curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return ($httpcode>=200 && $httpcode<300);
}
function guessTypeFromFilename ($filename) {
$ext = substr($filename, (strrpos($filename, '.') + 1));
switch ($ext) {
case 'mkv':
$type = 'video/mkv';
break;
case 'flv':
$type = 'video/flv';
break;
case 'avi':
$type = 'video/x-msvideo';
break;
case 'webm':
$type = 'video/webm';
break;
case 'mkv':
$type = 'video/x-matroska';
break;
case '3gp':
$type = 'video/3gp';
break;
case 'ogv':
$type = 'video/ogv';
break;
default:
$type = 'video/mp4';
break;
}
return $type;
}

4
get_youtube_videos.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash
HOME=`cat conf/home_dir.txt`
cat $HOME/.zen/ipfs*/.*/astroport/kodi/vstream/YASTRXBIAN | sort | uniq | tail -n +2

2
index.php Normal file
View File

@ -0,0 +1,2 @@
<?php
header('Location: youtube.php');

66
install/install_web_ui.sh Executable file
View File

@ -0,0 +1,66 @@
#!/bin/bash
NGINX_CONF_FILE=/etc/nginx/sites-available/astroport
NGINX_ROOT=~/.zen/webui
USER_GROUP=`groups | awk '{print $1}'`
#sudo adduser --home $HOME --no-create-home --disabled-password --disabled-login --quiet --gecos "" astroport
#sudo adduser astroport $USER_GROUP
sudo chgrp -R www-data ~{.zen,.ipfs,astroport}
sudo chmod -R g+rw ~/{.zen,.ipfs,astroport}
echo ~ | tee ../conf/home_dir.txt
rm ./{astrXbian,astroport,swarm,me}
ln -s ../astrXbian astrXbian
ln -s ../../astroport astroport
ln -s ../ipfs_swarm swarm
ln -s ../ipfs me
sudo rm $NGINX_CONF_FILE
cd /etc/nginx/sites-enabled
sudo ln -s ../sites-available/astroport astroport
sudo dd of=$NGINX_CONF_FILE << EOF
server {
listen 80 default_server;
listen [::]:80 default_server;
root $NGINX_ROOT;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files \$uri \$uri/ =404;
}
index index.php;
# pass PHP scripts to FastCGI server
location ~ \.php$ {
include snippets/fastcgi-php.conf;
# With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
# With php-cgi (or other tcp sockets):
#fastcgi_pass 127.0.0.1:9000;
}
}
EOF
sudo systemctl restart nginx
echo ""
echo "Press any key to finish installation"
read
exit 0

21
ipns_self_publish.sh Executable file
View File

@ -0,0 +1,21 @@
#!/bin/bash
########################################################################
HOME=`cat conf/home_dir.txt`
########################################################################
MY_PATH="`dirname \"$0\"`" # relative
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
ME="${0##*/}"
########################################################################
export IPFSNODEID=$(ipfs id -f='<id>\n')
########################################################################
echo "PUBLISHING ~/.zen/ipfs SELF /ipns/$IPFSNODEID"
MIPFS=$(ipfs add -rHq ~/.zen/ipfs | tail -n 1)
OLDCHAIN=$(cat ~/.zen/ipfs/.${IPFSNODEID}/.chain)
if [[ "$OLDCHAIN" != "$MIPFS" ]] # MODIFY CHAIN only if something was changed
then
echo "$(date -u +%s%N | cut -b1-13)" > ~/.zen/ipfs/.${IPFSNODEID}/.timestamp
echo $MIPFS > ~/.zen/ipfs/.${IPFSNODEID}/.chain
fi
NODEIPNS=$(ipfs name publish --quieter /ipfs/$MIPFS)
########################################################################

230
new_youtube_video_in_astroport.sh Executable file
View File

@ -0,0 +1,230 @@
#!/bin/bash
########################################################################
# Author: Fred (support@qo-op.com)
# Version: 0.3
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
########################################################################
# COPY ~/astroport/* files to IPFS
# Publish INDEX ~/.zen/ipfs/.*/${PREFIX}ASTRXBIAN
######## #### ### ## #
HOME=`cat conf/home_dir.txt`
########################################################################
MY_PATH="`dirname \"$0\"`" # relative
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
ME="${0##*/}"
YOU=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1);
IPFSNODEID=$(ipfs id -f='<id>\n')
G1PUB=$(cat ~/.zen/secret.dunikey | grep 'pub:' | cut -d ' ' -f 2)
# ~/.zen/ipfs/.${IPFSNODEID}/astroport/kodi/vstream/${PREFIX}ASTRXBIAN
# Astropot/Kodi/Vstream source reads ${PREFIX}ASTRXBIAN from http://127.0.0.1:8181/.$IPFNODEID/
# Index File Format (could be enhanced) is using Kodi TMDB enhancement
# https://github.com/Kodi-vStream/venom-xbmc-addons/wiki/Voir-et-partager-sa-biblioth%C3%A8que-priv%C3%A9e#d%C3%A9clarer-des-films
########################################################################
## RUN inotifywait process ~/astroport/ NEW FILE DETECT
# /usr/bin/inotifywait -r -e close_write -m /home/$YOU/astroport | while read dir flags file; do ~/.zen/astrXbian/zen/new_file_in_astroport.sh "$dir" "$file"; done &
# mkdir -p ~/astroport/youtube
# mkdir -p ~/astroport/mp3
########################################################################
path="$1"
# Add trailing / if needed
length=${#path}
last_char=${path:length-1:1}
[[ $last_char != "/" ]] && path="$path/"; :
file="$2"
extension="${file##*.}"
TITLE="${file%.*}"
#echo "~/.zen/www/new_youtube_video_in_astroport.sh PATH/ \"$path\" FILE \"$file\""
echo "Checking if the file exists at :"
echo "$path$file"
echo "in ~/.zen/www/new_youtube_video_in_astroport.sh"
# .part file false flag correcting (inotify mode)
[[ ! -f "${path}${file}" ]] && file="${TITLE%.*}" && extension="${TITLE##*.}" && [[ ! -f "${path}${file}" ]] && echo "NO FILE" && exit 1
# GET XZUID
[[ -f ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_g1.gchange_title ]] && XZUID=$(cat ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_g1.gchange_title) || XZUID=$(cat /etc/hostname)
[[ ! $(echo "$path" | cut -d '/' -f 4 | grep 'astroport') ]] && echo "Les fichiers sont à placer dans ~/astroport/ MERCI" && exit 1
TYPE=$(echo "$path" | cut -d '/' -f 5 ) # ex: /home/$YOU/astroport/... TYPE(film, youtube, mp3)/ REFERENCE /
CAT=$(echo "$TYPE" | awk '{ print tolower($0) }')
PREFIX=$(echo "$TYPE" | head -c 1 | awk '{ print toupper($0) }' ) # ex: F, Y, M ou Y
# File is placed in ROOT ~/astroport ?
if [[ $PREFIX == "" ]]
then
[[ "$USER" != "xbian" ]] && zenity --warning --width 300 --text "Désolé votre fichier ne peut pas être traité"
echo "WARNING. $TYPE is root file UNTREATED" && exit 1
fi
########################################################################
# EXTRACT INDEX REFERENCE : TMDB or YOUTUBE (can be extended with new )
########################################################################
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-)
;;
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_"
REFERENCE=$(echo "$path" | cut -d '/' -f 6 ) # Path contains TMDB id
if ! [[ "$REFERENCE" =~ ^[0-9]+$ ]] # ${REFERENCE} NOT A NUMBER
then
echo "ERROR: $path BAD TMDB code. Get it from https://www.themoviedb.org/ "
exit 1
fi
;;
*)
echo "$CAT inconnu" && exit 1
;;
esac
########################################################################
## CHECK if ${INDEXPREFIX}${REFERENCE} KEY exists
########################################################################
echo "SEARCH for ;$REFERENCE; in ${PREFIX}ASTRXBIAN"
isREFERENCEinINDEX=$(grep ";$REFERENCE;" ~/.zen/ipfs*/.*/astroport/kodi/vstream/${PREFIX}ASTRXBIAN)
if [[ ${isREFERENCEinINDEX} ]]
then
if [[ -d ~/.zen/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB} ]]
then
# 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, 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} | 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
sed -i "/;$REFERENCE;/d" ~/.zen/ipfs/.${IPFSNODEID}/astroport/kodi/vstream/${PREFIX}ASTRXBIAN
# [[ "$USER" != "xbian" ]] && zenity --warning --width 300 --text "DOUBLON ${isREFERENCEinINDEX}"
fi
########################################################################
echo "ADDING ${path}${file} to IPFS and create ${PREFIX}ASTRXBIAN INDEX"
echo "~/.zen/ipfs/.${IPFSNODEID}/astroport/kodi/vstream/${PREFIX}ASTRXBIAN"
echo "-----------------------------------------------------------------"
IPFSREPFILEID=$(ipfs add -wq "${path}${file}" | tail -n 1)
[[ $IPFSREPFILEID == "" ]] && echo "ipfs add ERROR" && exit 1
echo "-----------------------------------------------------------------"
echo "IPFS: $file : ipfs ls /ipfs/$IPFSREPFILEID"
echo "-----------------------------------------------------------------"
echo "New $TYPE INDEX ~/.zen/ipfs/.${IPFSNODEID}/astroport/kodi/vstream/${PREFIX}ASTRXBIAN "
[[ ! -d ~/.zen/ipfs/.${IPFSNODEID}/astroport/kodi/vstream/ ]] && mkdir -p ~/.zen/ipfs/.${IPFSNODEID}/astroport/kodi/vstream/
URLENCODE_FILE_NAME=$(echo ${file} | jq -Rr @uri)
########################################################################
## CREATE NEW ipns KEY : ${INDEXPREFIX}${REFERENCE}
########################################################################
########################################################################
[[ ! -d ~/.zen/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB} ]] && mkdir -p ~/.zen/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB} && KEY=$(ipfs key gen "${INDEXPREFIX}${REFERENCE}") && KEYFILE=$(ls -t ~/.ipfs/keystore/ | head -n 1)
## INIT ipns
if [[ $KEY ]]; then
# memorize IPNS key filename for easiest exchange
echo "$KEYFILE" > ~/.zen/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/.ipns.key.keystore_filename
# Publishing IPNS key
echo "$KEY" > ~/.zen/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/.ipns.link
# .zen could contain ZEN for economic value
touch ~/.zen/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/.zen
################ ENCRYPT keystore/$KEYFILE
$MY_PATH/tools/natools.py encrypt -p $G1PUB -i ~/.ipfs/keystore/$KEYFILE -o ~/.zen/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/.ipns.key.natools.encrypt
else
KEY=$(cat ~/.zen/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/.ipns.link)
KEYFILE=$(cat ~/.zen/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/.ipns.key.keystore_filename)
fi
# CLEAR ipfs link (is then cyphered to manage exchange regulation)
echo "/ipfs/$IPFSREPFILEID/${file}" > ~/.zen/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/.ipfs.filelink
################ ENCRYPT .ipfs.filelink
$MY_PATH/tools/natools.py encrypt -p $G1PUB -i ~/.zen/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/.ipfs.filelink -o ~/.zen/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/.ipfs.filelink.natools.encrypt
rm ~/.zen/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/.ipfs.filelink
echo "${file}" > ~/.zen/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/.ipfs.filename
echo "${TITLE}" > ~/.zen/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/.title
echo "$(date -u +%s%N | cut -b1-13)" > ~/.zen/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/.timestamp
# COPY "ajouter_video.txt" later used
[[ -f ~/astroport/${TYPE}/${REFERENCE}/ajouter_video.txt ]] && cp -f ~/astroport/${TYPE}/${REFERENCE}/ajouter_video.txt ~/.zen/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/
# IPNS index.html Redirect to ipfs streaming link (could be contract or anything else !!)
echo "<meta http-equiv=\"Refresh\" content=\"0;URL=http://127.0.0.1:8181/ipfs/$IPFSREPFILEID/$URLENCODE_FILE_NAME\">" > ~/.zen/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/index.html
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>
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 )
IPNS=$(ipfs name publish --quieter --key="${INDEXPREFIX}${REFERENCE}" $NEWIPFS)
########################################################################
########################################################################
# PUBLISH GCHANGE AD for TMDB film/serie/anime ONLY
########################################################################
if [[ "${CAT}" =~ ^(film|serie|anime)$ ]]
then
if [[ ! -f ~/.zen/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/.gchange.ad ]]
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 --quieter --key="${INDEXPREFIX}${REFERENCE}" $NEWIPFS)
fi
echo "Annonce gchange : $(cat ~/.zen/KEY/${INDEXPREFIX}${REFERENCE}/${G1PUB}/.gchange.ad)"
fi
########################################################################
# 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
# MEMORIZE NEW PIN
mkdir -p ~/.zen/ipfs/.${IPFSNODEID}/PIN/${IPFSREPFILEID}/
touch ~/.zen/ipfs/.${IPFSNODEID}/PIN/${IPFSREPFILEID}/${G1PUB}
# 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 "----------------- 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
########################################################################
./ipns_self_publish.sh
########################################################################
echo "NEW $TYPE ($file) ADDED."
echo "INDEX UPDATED : http://127.0.0.1:8181/ipns/${IPFSNODEID}/.${IPFSNODEID}/${PREFIX}ASTRXBIAN"
echo "VIDEO IPNS LINK : http://127.0.0.1:8181/ipns/$KEY/$G1PUB/"
exit 0

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

View File

@ -0,0 +1,133 @@
:root {
--pink: hsl(338.5, 72.8%, 36.1%);
--light-pink: hsl(338.5, 72.8%, 56.1%);
--canard: hsl(200.8, 100%, 9.6%);
}
body {
background: #121212;
color: white;
margin: 0;
padding: 0;
font-family: Roboto,sans-serif;
}
header {
background: var(--canard);
overflow: hidden;
padding: 1rem 0.666rem 1.333rem;
margin-bottom: 2rem;
}
header a,
header a:visited {
color: white;
text-decoration: none;
}
header a:active {
outline: 0;
}
header > * {
font-size: 1.5rem;
margin: 0;
padding: 0;
}
header > .sitetitle {
margin-bottom: 0.25rem;
}
header > .sitetitle span {
border-bottom: 0.125rem solid var(--pink);
}
header .usp {
color: white;
font-size: 0.95rem;
}
header .usp strong {
font-size: 1em;
font-weight: inherit;
color: var(--light-pink);
}
main {
width: 95%;
margin: auto;
}
#videosList {
display: grid;
grid-gap: 1rem 1rem;
grid-auto-flow: row;
grid-template-columns: 322px 322px 322px;
list-style: none;
margin: 0;
padding: 0;
justify-content: center;
}
#videosList li {
background: var(--canard);
border-color: var(--pink);
border-radius: 0.25rem;
border-width: 1px;
border-style: solid;
overflow: hidden;
}
#videosList .video-title {
padding: 0.5rem 1rem;
}
.video-title,
.video-title a,
.video-title a:visited {
color: white;
font-weight: bold;
text-decoration: none;
}
article {
border-radius: 0.25rem;
background: hsl(200.8, 100%, 9.6%);
width: 58.3%;
margin: auto;
overflow: hidden;
}
article video {
width: 100%;
max-height: calc(100vh - 14rem);
background: black;
}
article .video-title {
font-weight: bold;
padding: 1rem 1rem;
font-size: 1.25rem;
margin: 0;
}

79
swarm_files.php Normal file
View File

@ -0,0 +1,79 @@
<?php
require_once('conf/conf.php');
require_once('functions.php');
$dir = scandir("swarm", SCANDIR_SORT_DESCENDING) or die('fail');
// echo '<pre>'; print_r($dir); echo '</pre>';
array_pop($dir); // .
array_pop($dir); // ..
// echo '<pre>'; print_r($dir); echo '</pre>';
$swarm = array();
foreach ($dir as $d) {
$fst = substr($d, 0, 1);
if ($fst == '.') {
$swarm[] = $d;
}
}
foreach ($swarm as $peer) {
$peerName = file_get_contents('swarm/' . $peer . '/G1SSB/_g1.astroport_title');
echo '<h2>'. $peerName . ' ['. substr($peer, 0, 5) . '…' . substr($peer, -4) . ']</h2>';
$files = scandir('swarm/' . $peer . '/astroport/kodi/vstream', SCANDIR_SORT_DESCENDING);
array_pop($files); // .
array_pop($files); // ..
foreach ($files as $f) {
echo '<h3>' . getCollectionType($f) . '</h3>';
$collection = file_get_contents('swarm/' . $peer . '/astroport/kodi/vstream/' . $f);
$collection = trim($collection);
$videos = explode("\n", $collection);
$videos = array_reverse($videos);
array_pop($videos);
echo '<ul>';
foreach ($videos as $v) {
list($a, $b, $c, $videoName, $e, $g, $h, $m, $videoURI) = explode(";", $v);
$videoURL = 'http://'. HOST. $videoURI;
$mimeType = guessTypeFromFilename($videoURL);
if ($mimeType == 'video/mp4') {
echo '<li>';
echo '
<a href="'. $videoURL . '">' . $videoName . '</a><br />
('. $mimeType . ')<br />
<video controls width="320" height="240" preload="none">
<source src="'. $videoURL .'" type="'. $mimeType .'">
<a href="'. $videoURL . '">' . $videoName . '</a>
</video>';
echo '</li>';
}
}
echo '
</ul>';
}
}

1
test.txt Normal file
View File

@ -0,0 +1 @@
coucou

90
youtube.php Normal file
View File

@ -0,0 +1,90 @@
<?php
require_once('conf/conf.php');
require_once('functions.php');
$videosList = array();
exec("/bin/bash -c './get_youtube_videos.sh'", $videos);
$videos = array_reverse($videos);
foreach ($videos as $v) {
list($a, $youtubeID, $c, $videoName, $e, $src, $h, $quality, $videoURI) = explode(";", $v);
$videoURL = 'http://'. HOST. $videoURI;
$mimeType = guessTypeFromFilename($videoURI);
if ($mimeType == 'video/mp4') {
$videosList[] = [
'mime' => $mimeType,
'url' => $videoURL,
'uri' => $videoURI,
'name' => $videoName,
'youtubeID' => $youtubeID
];
}
}
?><!DOCTYPE html>
<html>
<head>
<title>Astrobunker</title>
<link rel="stylesheet" href="styles/crowdbunker/crowdbunker.css" type="text/css" />
<link rel="icon" type="image/png" href="styles/crowdbunker/astrobunker.png" />
</head>
<body>
<header>
<h1 class="sitetitle">
<a href="youtube.php"><?php echo SITENAME; ?></a>
</h1>
<p class="usp">
<?php echo USP; ?>
</p>
</header>
<main>
<form method="post" action="youtube_add_video.php" class="add-video">
<label>Sauvegarder une vidéo Youtube&nbsp;: <input type="text" name="youtube_url" /></label>
<input type="submit" value="Sauvegarder" />
</form>
<?php
echo '<ul id="videosList">';
foreach ($videosList as $video) {
echo '<li>';
$href = 'youtube_watch.php?uri='. urlencode($video['uri']) . '&amp;name='. urlencode($video['name']) .'&mime='. $video['mime'];
echo '
<a href="'. $href .'">
<img src="'. sprintf(YOUTUBE_THUMB, $video['youtubeID']) . '" alt="'. $video['name'] . '" />
</a>
<p class="video-title">
<a href="'. $href .'">
' . $video['name'] . '
</a>
</p>';
echo '</li>';
}
echo '</ul>';
?>
</main>
</body>
</html>

44
youtube_add_video.php Normal file
View File

@ -0,0 +1,44 @@
<?php
ini_set('max_execution_time', 1000);
require_once('conf/conf.php');
require_once('functions.php');
?><!DOCTYPE html>
<html>
<head>
<title>Astrobunker</title>
<link rel="stylesheet" href="styles/crowdbunker/crowdbunker.css" type="text/css" />
<link rel="icon" type="image/png" href="styles/crowdbunker/astrobunker.png" />
</head>
<body>
<header>
<h1 class="sitetitle">
<a href="youtube.php"><?php echo SITENAME; ?></a>
</h1>
<p class="usp">
<?php echo USP; ?>
</p>
</header>
<main>
<article>
Votre vidéo est en cours de téléchargement.
</article>
</main>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$.ajax({
method: "POST",
url: "youtube_add_video_aux.php",
data: { youtube_url: "<?php echo $_POST['youtube_url']; ?>" }
})
.done(function( response ) {
console.log(response);
});
</script>
</body>
</html>

16
youtube_add_video_aux.php Normal file
View File

@ -0,0 +1,16 @@
<?php
if (isset($_POST['youtube_url'])) {
$youtube_url = $_POST['youtube_url'];
} elseif (isset($_GET['youtube_url'])) {
$youtube_url = $_GET['youtube_url'];
}
exec("/bin/bash -c './ajouter_video_youtube.sh ". $youtube_url ."'", $output);
echo '<pre>'; print_r($output); echo '</pre>';

57
youtube_watch.php Normal file
View File

@ -0,0 +1,57 @@
<?php
require_once('functions.php');
require_once('conf/conf.php');
function astroport_urlencode ($str) {
$str = str_replace('%', '%25', $str);
$str = str_replace('#', '%23', $str);
return $str;
}
$videoURI = urldecode($_GET['uri']);
list($a, $ipfsPath, $videoIPFS_ID, $videoFileName) = explode('/', $videoURI);
$videoURL = 'http://'. HOST. '/' . urlencode($ipfsPath) . '/' . urlencode($videoIPFS_ID) . '/' . astroport_urlencode($videoFileName);
$videoName = htmlentities(urldecode($_GET['name']));
$videoMIME = htmlentities($_GET['mime']);
?><!DOCTYPE html>
<html>
<head>
<title>Astrobunker</title>
<link rel="stylesheet" href="styles/crowdbunker/crowdbunker.css" type="text/css" />
<link rel="icon" type="image/png" href="styles/crowdbunker/astrobunker.png" />
</head>
<body>
<header>
<h6 class="sitetitle">
<a href="youtube.php"><?php echo SITENAME; ?></a>
</h6>
<p class="usp">
<?php echo USP; ?>
</p>
</header>
<main>
<?php
echo '
<article>
<video autoplay="autoplay" controls>
<source src="'. $videoURL .'" type="'. $videoMIME .'">
</video>
<h1 class="video-title">
' . $videoName . '
</h1>
<p>
<a href="'. $videoURL . '">Télécharger</a>
</p>
</article>';
?>
</main>
</body>
</html>