Otra actualización de youtube->peertube

He mejorado bastante el «descargador» de videos desde youtube. Ahora reduce mucho el tráfico de red hacia youtube así es practicamente imposible que la IA os detecte.

El funcionamiento es simple, pero efectivo. El script descarga un vídeo, y lo pasa a peertube que a su vez hace la «trasncodificación» o sea saca las versiones de baja resolución.

En la versiones anteriores todos los vídeos eran descargadop y puesto en cola a peertube. Ahora el descargador se espera que haya acabado la «trasnscodificación» antes de bajar el vídeo siguiente. Como que según la resolución y la duración, el tiempo varia mucho, el resultado es que la IA de google no puede distinguir entre un uso legítimo (según ellos) de youtube y una descarga.

Aquí os dejo el script

#!/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-08-16
# maxlinux2000@gmail.com


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

IN="YoutubeURLChannel/Videos/List"
resolution="18"
channel="YourChannel"
server="https://YourPeerTubeURL"
username="YourUser"
password="YourUserPassword"


## force embed subtitles in language of your choice, i.e.: fr es de it ru ch
## if empty no subtitles will be embedded
language=""

# proxy
#proxy="--proxy https://136.168.70.90:8888"
proxy=''

#yt_user='' #maxlinux2000@gmail.com
#yt_pass=''

cookies=/root/cookies.txt


#############################################################
# From here do not touch anything unless you know what you are doing. 

PWD=$(pwd)

standard() {
    id=$1
    echo id=$id
    yt_code=$(echo $id | sed 's|^MINUS|-|g')
#    youtube-dl --cookies $cookies -u $yt_user -p $yt_pass $proxy --write-info-json -f "$resolution" "https://www.youtube.com/watch?v=$yt_code"

    while :
    do
        FF=$(ps -A | grep "ffmpeg" | tail -n 1 | tr -d ' ' | tr -d ':')
        if [ -z $FF ]; then
            echo "FFMPEG is not active, continuing..."
            break
        else 
            echo "FFMPEG is running: waiting 60 secs"
            sleep 60
        fi
    done

    youtube-dl --cookies $cookies $proxy --write-info-json --write-thumbnail -f "$resolution" -o $id.mp4 "https://www.youtube.com/watch?v=$yt_code" 

    json=$(cat -- $id.info.json)
    title=$(echo $json | jq .fulltitle | tr -d '"')
    datejson=$(cat --  $id.info.json | less | jq .upload_date | tr -d '"')
    date=$(date -d $datejson  +%Y-%m-%d)
    file=$(ls $PWD/$id.mp4)
    if [ -f $PWD/$id.jpg ]; then
        thumb=$(ls $PWD/$id.jpg)
    fi
    if [ -f $PWD/$id.webp ]; then
        thumb=$(ls $PWD/$id.webp)
    fi
    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" -b $thumb -d "$date - $yt_code - $description" -L "$lang" -U "$username" -p "$password" -f "$file"  && \
    rm   "$file" &&  rm ./$id.info.json && rm ./$id.jpg
}

subtitle() {
    id=$1
    echo id=$id
    yt_code=$(echo $id | sed 's|^MINUS|-|g')

    while :
    do
        FF=$(ps -A | grep "ffmpeg" | tail -n 1 | tr -d ' ' | tr -d ':')
        if [ -z $FF ]; then
            echo "FFMPEG is not active, continuing..."
            break
        else 
            echo "FFMPEG is running: waiting 60 secs"
            sleep 60
        fi
    done
    youtube-dl  --cookies $cookies $proxy --write-info-json --write-thumbnail  -f "$resolution"  --write-auto-sub --sub-lang $language  -o "$id.mp4" "https://www.youtube.com/watch?v=$yt_code" 

    if [ ! -f $id.$language.vtt ]; then
        youtube-dl  --cookies $cookies --write-sub --sub-lang $language  --skip-download "https://www.youtube.com/watch?v=$yt_code" 
    fi

    file=$PWD/$id-$language.mp4
    json=$(cat -- $id.info.json)
    title=$(echo $json | jq .fulltitle | tr -d '"')
    datejson=$(cat --  $id.info.json | less | jq .upload_date | tr -d '"')
    date=$(date -d $datejson  +%Y-%m-%d)
    echo file=$file
    description=$(echo $json | jq .description | tr -d '"' | sed 's|\\n|\n|g')
    if [ -f $PWD/$id.jpg ]; then
        thumb=$(ls $PWD/$id.jpg)
    fi
    if [ -f $PWD/$id.webp ]; then
        thumb=$(ls $PWD/$id.webp)
    fi
    lang=$(echo $json | jq . | grep "lang=" | head -n1 | cut -d '?' -f2 | cut -d '&' -f1 | sed 's|lang=||g')


    if [ -f $id.$language.vtt ]; then
    echo "-----------------------
    Lang=$lang
    "
        ffmpeg -hide_banner -threads 1 -i ./"$id.$language.vtt" sub.ass -y
        ffmpeg -hide_banner -threads 1 -i ./"$id.mp4" -vf "ass=sub.ass" -empty_hdlr_name 1 "$id-$language.mp4" -y
        rm sub.ass ./$id.$language.vtt

echo "----------------------

        echo node $PWD/dist/server/tools/peertube-upload.js -n "$title" -C "$channel" -b $thumb  -d "$date - $id - $description" -L "$lang" -U "$username" -p "$password" -f "$file"   \

---------------------
"

        node $PWD/dist/server/tools/peertube-upload.js -n "$title" -C "$channel" -b $thumb -d "$date - $yt_code - $description" -L "$lang" -U "$username" -p "$password" -f "$file" \
        && rm ./$id.mp4  ./$id-$language.mp4 ./$id.info.json  ./$id.jpg  ./$id.webp
#        && rm ./$id.mp4  ./$id-$language.mp4 && rm ./$id.info.json && rm ./$id.jpg

    echo "----------------------"
    else
    echo "-----------------------
    Lang=en
    skipping. Please at the end, open the $channel-yt-2-translate.txt file go to youtube and generate the translation 
whatching the videos (all) with localized subtitles. Then repeat the process.
    "
        file=$PWD/$id.mp4

        node $PWD/dist/server/tools/peertube-upload.js -n "$title" -C "$channel" -b $thumb -d "$date - $yt_code - $description" -L "$lang" -U "$username" -p "$password" -f "$file" \
        && rm ./$id.mp4 ./$id-$language.mp4  ./$id.info.json  ./$id.jpg  ./$id.webp


        echo $yt_code >> $channel-yt-2-translate.txt
        cat $channel-yt-2-translate.txt | sort | uniq > tmp2
        mv tmp2 $channel-yt-2-translate.txt

    echo "----------------------"
    fi
}


processLog() {
    yt_code=$(echo $id | sed 's|^MINUS|-|g')
    cat -- $channel-yt-list | grep -v -- "$yt_code" > tmp1
    echo "$yt_code" >> ./$channel-yt-done
    mv tmp1 ./$channel-yt-list
}

touch ./$channel-yt-done

:> $channel-yt-list
### old #youtube-dl  --cookies $cookies  -u $yt_user -p $yt_pass --verbose $proxy --playlist-reverse --get-id $IN | tee -a $channel-yt-list

youtube-dl  --cookies $cookies  --verbose $proxy --playlist-reverse --get-id $IN | tee -a $channel-yt-list
cat $channel-yt-list | uniq > tmp
mv tmp $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
            id=$(echo $id | sed 's|^-|MINUS|g')
            if [ -z $language ]; then
                #mode=standard
                standard $id && processLog
            else
                #mode=subtitle
                subtitle $id && processLog
            fi
    fi
    echo "-------------------------"
done

rm *.mp4 *.webp *.jpg *.info.json *.vtt 2>/dev/null

Comentarios cerrados.