diff --git a/ASTROBOT/TUBE.copy.sh b/ASTROBOT/TUBE.copy.sh index b2c21ee8..7bb0ca82 100755 --- a/ASTROBOT/TUBE.copy.sh +++ b/ASTROBOT/TUBE.copy.sh @@ -1,6 +1,6 @@ #!/bin/bash ######################################################################## -# Version: 0.3 +# Version: 0.4 # License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/) ######################################################################## MY_PATH="`dirname \"$0\"`" # relative @@ -19,50 +19,53 @@ INDEX="$1" [[ ! $INDEX ]] && echo "Please provide path to source TW index.html" && exit 1 [[ ! -f $INDEX ]] && echo "Fichier TW absent. $INDEX" && exit 1 -WISHKEY="$2" +WISHKEY="$2" ## IPNS KEY NAME - G1PUB - PLAYER ... [[ ! $WISHKEY ]] && echo "Please provide IPFS publish key" && exit 1 -WNS=$(ipfs key list -l | grep -w $WISHKEY | cut -d ' ' -f1) +TWNS=$(ipfs key list -l | grep -w $WISHKEY | cut -d ' ' -f1) -# Extract tag=tube from TW +# Extract tag=tube from TW into ~/.zen/tmp/tube.json rm -f ~/.zen/tmp/tube.json tiddlywiki --verbose --load ${INDEX} --output ~/.zen/tmp --render '.' 'tube.json' 'text/plain' '$:/core/templates/exporters/JsonFile' 'exportFilter' '[tag[tube]]' ## Extract URL from text field -for yurl in $(cat ~/.zen/tmp/tube.json | jq -r '.[].text' | grep 'http'); do - echo "Detected $yurl" +for YURL in $(cat ~/.zen/tmp/tube.json | jq -r '.[].text' | grep 'http'); do + echo "Detected $YURL" echo "Start Downloading" mkdir -p ~/.zen/tmp/tube ### GETTING ALL VIDEO IDs (for playlist copy) - yt-dlp --print "%(id)s" "${yurl}" > ~/.zen/tmp/ytids + yt-dlp --print "%(id)s" "${YURL}" > ~/.zen/tmp/ytids - for yid in "$(cat ~/.zen/tmp/ytids)"; + for YID in "$(cat ~/.zen/tmp/ytids)"; do - - # SINGLE VIDEO yurl - yurl="https://www.youtube.com/watch?v=$yid"; - TITLE="$(yt-dlp --print "%(title)s" "${yurl}")" + # SINGLE VIDEO YURL + ZYURL="https://www.youtube.com/watch?v=$YID"; + TITLE="$(yt-dlp --print "%(title)s" "${ZYURL}")" TITLE=${TITLE//[^A-zÀ-ÿ0-9 ]/} + echo "OK! Going to download $TITLE.mp4 from $ZYURL" # https://github.com/yt-dlp/yt-dlp#format-selection-examples # SUBS ? --write-subs --write-auto-subs --sub-langs "fr, en, en-orig" --embed-subs # TODO : DELAY COPY OPERATION... Astro can download quicker at 03:00 AM - echo "yt-dlp -f \"bv*[ext=mp4][height<=480]+ba/b[height<=480] / bv*[ext=mp4][height<=720]+ba/b[height<=720]\" --no-mtime --embed-thumbnail --add-metadata -o \"$HOME/.zen/tmp/tube/$TITLE.%(ext)s\" ${yurl}" + echo "yt-dlp -f \"bv*[ext=mp4][height<=480]+ba/b[height<=480] / bv*[ext=mp4][height<=720]+ba/b[height<=720]\" --no-mtime --embed-thumbnail --add-metadata -o \"$HOME/.zen/tmp/tube/$TITLE.%(ext)s\" ${ZYURL}" + + ############################################################################# + ## COPY FROM YOUTUBE yt-dlp -f "bv*[ext=mp4][height<=480]+ba/b[height<=480] / bv*[ext=mp4][height<=720]+ba/b[height<=720]" \ -S "filesize:700M" --no-mtime --embed-thumbnail --add-metadata \ --write-subs --write-auto-subs --sub-langs "fr, en, en-orig" --embed-subs \ - -o "$HOME/.zen/tmp/tube/$TITLE.%(ext)s" ${yurl} - + -o "$HOME/.zen/tmp/tube/$TITLE.%(ext)s" ${ZYURL} + ################################################################################ + ### ADAPT TO TW RYTHM (DELAY COPY?) echo - # Get last writen file... TODO: Could we do better ? - # ZFILE=$(ls -t ~/.zen/tmp/tube/*.mp4 | head -n 1) - ZFILE="$TITLE.mp4" echo "$ZFILE" + ############################################################################ + ### CHECK RESULT CONVERT MKV TO MP4 [[ ! -f "$HOME/.zen/tmp/tube/$ZFILE" ]] && ffmpeg -i "$HOME/.zen/tmp/tube/$TITLE.mkv" -c:v libx264 -c:a aac "$HOME/.zen/tmp/tube/$TITLE.mp4" # TRY TO CONVERT MKV TO MP4 - [[ ! -f "$HOME/.zen/tmp/tube/$ZFILE" ]] && echo "No FILE -- EXIT --" && exit 1 + [[ ! -f "$HOME/.zen/tmp/tube/$ZFILE" ]] && echo "No FILE -- EXIT --" && continue echo echo "FOUND : ~/.zen/tmp/tube/$ZFILE" @@ -74,11 +77,11 @@ for yurl in $(cat ~/.zen/tmp/tube.json | jq -r '.[].text' | grep 'http'); do MIME=$(file --mime-type "$HOME/.zen/tmp/tube/$ZFILE" | rev | cut -d ' ' -f 1 | rev) ## ADD TAGS - EXTRATAG=$(yt-dlp --print "crea_%(creator)s chan_%(channel)s sec_%(duration)s list_%(playlist)s" "${yurl}") + EXTRATAG=$(yt-dlp --print "crea_%(creator)s chan_%(channel)s sec_%(duration)s list_%(playlist)s" "${ZYURL}") ## PREPARE VIDEO HTML5 CODE TEXT="