Actualización video Youtube -> PeerTube

Los vídeos en español son interesantes, pero hay muchos vídeos en ingles que también lo son y no todo el mundo habla este idioma, así que he retomado el script para descargar los vídeos de youtube y cargarlos en peertube, modificando el paso intermedio.

Puedes ver el articulo anterior aquí

Ahora descarga también el subtitulo de la lengua que te interesa (si está disponible) y lo incrusta directamente en el vídeo para luego subirlo a peertube.

#!/bin/bash

# Substitute wrapper for peertube-import-videos.js.
# This script uses youtube-dl and jq to download the youtube videos and upload them to your PeerTube instance
# using the peertube-upload.js script from the PeerTube CLI suite.
#
# Works on Debian10 Not tested on other distributions.
#
# sudo curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl
# sudo chmod a+rx /usr/local/bin/youtube-dl
# sudo apt install jq -y
#
# I suggest you use "screen" to put the script in the background.
# Channel import can take many hours (or days) and if your session is via ssh, it could crash due network problems.
#
# Change variable fields
# IN="Channel URL or PlayList URL"
# resolution="18" # 18 = 360p (640x360 mp4) | 22 = 720p (1280x720 mp4)
# channel="PeerTube Channel"  Please create it before and paste here the sanitize nambre without spaces and lowercase
# server="https://yourPeerTubeInstanceUrl"
# username="username of PeerTube Instance"
# password="yourPassword"
#
# please before run this script install the CLI tools following the documentation
# https://docs.joinpeertube.org/maintain-tools
# ... and then register a remote user with
# peertube auth add -u 'PEERTUBE_URL' -U 'PEERTUBE_USER' --password 'PEERTUBE_PASSWORD'
# peertube auth list.
#
# on 2021-02-21
# maxlinux2000@gmail.com


#############################################################

IN="YourYoutubeChannelUrl"
resolution="18" # preferred resolution - see above
channel="yourchannelname"
server="https://videos.tormentasolar.win" # your server url
username="YourUser"  # (i.e.  maxlinux200)
password="YouPassword"

## force embed subtitles in language of your choice
## if empty no subtitles will be embedded
language=es
#############################################################
# From here do not touch anything unless you know what you are doing. 

PWD=$(pwd)

standard() {
    id=$1
    echo id=$id
    youtube-dl --write-info-json -f "$resolution" $id
    json=$(cat *-$id.info.json)
    title=$(echo $json | jq .fulltitle | tr -d '"')
    file=$(ls *$id.mp4)
    file=$(echo "$PWD/$file")
    echo file=$file
    description=$(echo $json | jq .description | tr -d '"' | sed 's|\\n|\n|g')
    lang=$(echo $json | jq . | grep "lang=" | head -n1 | cut -d '?' -f2 | cut -d '&' -f1 | sed 's|lang=||g')
    node $PWD/dist/server/tools/peertube-upload.js -n "$title" -C "$channel" -d "$description" -L "$lang" -U "$username" -p "$password" -f "$file"
    rm "$file"
    rm *.info.json
}

subtitle() {
    ##youtube-dl -f $resolution --write-info-json --write-auto-sub --write-sub --sub-lang $language -o $id.mp4 $id
    ##ffmpeg -i $id.$language.vtt sub.ass
    ##ffmpeg -i $id.mp4 -vf "ass=sub.ass" $id-$language.mp4
    ##rm sub.ass $id.$language.vtt

    id=$1
    echo id=$id
    youtube-dl --write-info-json -f "$resolution" --write-auto-sub --write-sub --sub-lang $language -o $id.mp4 $id

    file=$PWD/$id-$language.mp4
    json=$(cat $id.info.json)
    title=$(echo $json | jq .fulltitle | tr -d '"')
    echo file=$file
    description=$(echo $json | jq .description | tr -d '"' | sed 's|\\n|\n|g')
    lang=$(echo $json | jq . | grep "lang=" | head -n1 | cut -d '?' -f2 | cut -d '&' -f1 | sed 's|lang=||g')

    if [ -f $id.$language.vtt ]; then
        ffmpeg -hide_banner -loglevel error  -i $id.$language.vtt sub.ass
        ffmpeg -hide_banner -loglevel error  -i $id.mp4 -vf "ass=sub.ass" $id-$language.mp4
        rm sub.ass $id.$language.vtt
        node $PWD/dist/server/tools/peertube-upload.js -n "$title" -C "$channel" -d "$description" -L "$lang" -U "$username" -p "$password" -f "$file"   && rm  $id.mp4  $id-$language.mp4 && rm $id.info.json
    else
        file=$PWD/$id.mp4
        node $PWD/dist/server/tools/peertube-upload.js -n "$title" -C "$channel" -d "$description" -L "$lang" -U "$username" -p "$password" -f "$file"   && rm  $id.mp4  && rm $id.info.json
    fi
}


processLog() {
    cat $channel-yt-list | grep -v -- "$id" > tmp1
    mv tmp1 $channel-yt-list
    echo ok2
    echo "$id" >> $channel-yt-done
}

touch $channel-yt-done

##:> $channel-yt-list
##youtube-dl --playlist-reverse --get-id $IN | tee -a $channel-yt-list


for id in $(cat $channel-yt-list); do
    echo processing $id

    pre=$(cat $channel-yt-done | grep -- "$id")
    echo pre=$pre
    if [ -z "$pre" ]; then pre="0" ; else echo ok; fi  2> /dev/null

        if [ "$id" == "$pre" ]; then
            echo "$id already downloaded"
        else
            if [ -z $language ]; then
                #mode=standard
                standard $id && processLog
            else
                #mode=subtitle
                subtitle $id && processLog
            fi
    fi
    echo "-------------------------"
done

Comentarios cerrados.