diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c6f9a44 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.vscode/settings.json diff --git a/README.md b/README.md index 3d6db0f..39e2160 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,12 @@ # TwitchToYoutube -Utilidad hecha en bash para subir streams de twitch directamente a youtube. Usando [streamlink](https://github.com/streamlink/streamlink), [youtubeuploader](https://github.com/porjo/youtubeuploader) y cURL +Utilidad hecha en bash para subir streams de twitch directamente a youtube. Usando [streamlink](https://github.com/streamlink/streamlink), [youtubeuploader](https://github.com/porjo/youtubeuploader), [cURL](https://curl.se)/[xh](https://github.com/ducaale/xh) y [jq](https://github.com/stedolan/jq)/[jtc](https://github.com/ldn-softdev/jtc) -Lo recomendado para usar este programa es tener un servidor o una PC que tenga un internet estable y este encendido 24/7. +⚠️ Nota Importante: Este script tiene 2 versiones, una que funciona con **cURL** y **jq** y otra que utiliza **xh** y **jtc**. + +La mejor es la version que utiliza **xh** y **jtc** por ser mas eficiente y rápido. [Vee aquí](./benchmark.md) + + *Lo recomendado para usar este programa es tener un servidor o una PC que tenga un internet estable y este encendido 24/7.* # Funciones @@ -29,11 +33,14 @@ El resto de esta guía esta separada en diferentes partes: -- [Como usarlo [INCOMPLETO]](#como-usarlo-incompleto) - - [Crear una Aplicación de twitch](#crear-una-aplicaci%C3%B3n-de-twitch) +- [TwitchToYoutube](#twitchtoyoutube) +- [Funciones](#funciones) +- [Como usarlo \[INCOMPLETO\]](#como-usarlo-incompleto) + - [Crear una Aplicación de twitch](#crear-una-aplicación-de-twitch) - [Conseguir los tokens de twitch](#conseguir-los-tokens-de-twitch) - [Configurar youtubeuploader](#configurar-youtubeuploader) - [Ejecutar](#ejecutar) + - [Autor y repo original](#autor-y-repo-original) ## Crear una Aplicación de twitch @@ -135,4 +142,4 @@ Para dejarlo en segundo plano, puedes usar `tmux`, un programa bastante util par ### Autor y repo original -https://github.com/jenslys/autovod/ \ No newline at end of file +[jenslys/autovod](https://github.com/jenslys/autovod/) \ No newline at end of file diff --git a/benchmark.md b/benchmark.md new file mode 100644 index 0000000..dbaaae0 --- /dev/null +++ b/benchmark.md @@ -0,0 +1,35 @@ +# cURL/jq o xh/jtc? + +Bueno, quise hacer otra version del script usando diferentes programas, me di cuenta que **jq** usaba mucho CPU para sortear (del ingles *sort*) el archivo .json necesario para detectar si el streamer esta en vivo o no. + + +Entonces busque por alternativas y encontré [xh](https://github.com/ducaale/xh) (Alternativa a **cURL** hecha en Rust 🏳‍⚧️) y [jtc](https://github.com/ldn-softdev/jtc) (Alternativa a **jq** hecha en C++). + +Luego me hice a hacer unos benchmarks usando [hyperfine](https://github.com/sharkdp/hyperfine) y los tiempos y el uso de CPU fueron menores a las herramientas que generalmente se usan por defecto (cURL y jq). + +## ⚙ Benchmarks + +### cURL y jq + +```bash +curl -sS -X GET "https://api.twitch.tv/helix/streams?user_login=Suwie" -H "Authorization: Bearer $twitchauth" -H "Client-Id: $clientid" | jq -r '.data[].type' +``` + +![https://ii.zzls.xyz/NIZPQTI.png](caca) + +### xh y jtc + +```bash +xh GET "https://api.twitch.tv/helix/streams?user_login=Suwie" "Authorization: Bearer $twitchauth" "Client-Id: $clientid" -b | ./jtc -w '[data][:][type]' +``` + +![https://ii.zzls.xyz/AFHFXYI.png](cacacacacaca) + + +--- + +Los tiempos de ejecución y uso de CPU son exponencialmente menores a curl y jq con una diferencia de ~150ms. + +Entonces si vas a usar este script, es mejor usar la nueva version por ser exponencialmente mas efectiva. + +![https://cdn.7tv.app/emote/63065b70be8c19d70f9d6633/3x.webp](ppL) \ No newline at end of file diff --git a/jtc b/jtc new file mode 100755 index 0000000..60c4127 Binary files /dev/null and b/jtc differ diff --git a/twtoyt.sh b/twtoyt-curl-jq.sh similarity index 100% rename from twtoyt.sh rename to twtoyt-curl-jq.sh diff --git a/twtoyt-xh-jtc.sh b/twtoyt-xh-jtc.sh new file mode 100755 index 0000000..f81d613 --- /dev/null +++ b/twtoyt-xh-jtc.sh @@ -0,0 +1,53 @@ +#!/bin/bash +# Carga la configuracion desde ./config.sh +source ./config.sh + +echo "Auth de twitch: $twitchauth" +echo "Client-Id de twitch: $clientid" + +# Coloca aca el nombre del streamer de twitch +TWITCH_USER="" + +while true; do + TIME_DATE=[$(date +"%d/%m/%y")] # Formato de la fecha, usando el comando `date`. Ejemplo de como saldria: [31/12/22] + VIDEO_VISIBILITY="public" # Visibilidad del Video. Opciones disponibles: unlisted, private, public + VIDEO_DURATION="11:59:30" # Duración del video, si dura mas de el valor ingresado, se subira en partes divididas (Youtube solo tiene hasta videos de maximo 12 horas) + + STREAMLINK_OPTIONS="best --hls-duration $VIDEO_DURATION --stream-segment-timeout 30 --hls-playlist-reload-attempts 10 --hls-live-restart --twitch-disable-hosting --twitch-disable-reruns -O --loglevel error" # https://streamlink.github.io/cli.html#twitch + + echo "Checkqueando si $TWITCH_USER esta en vivo" + + # Checkea si el streamer esta en vivo usando la API de twitch + checkstream=$(xh GET "https://api.twitch.tv/helix/streams?user_login=$TWITCH_USER" "Authorization: Bearer $twitchauth" "Client-Id: $clientid" -b | ./jtc -w '[data][:][type]') + + # Si el streamer esta en vivo, empieza a subir a youtube + if [[ $checkstream = *live* ]]; then + STREAMER_NAME=$TWITCH_USER + VIDEO_PLAYLIST="$STREAMER_NAME VODs" + + TWITCH_USER_ID=$(xh GET "https://api.twitch.tv/helix/streams?user_login=$TWITCH_USER" "Authorization: Bearer $twitchauth" "Client-Id: $clientid" -b | ./jtc -w '[data][:][type]') + TWITCH_TITLE=$(xh GET "https://api.twitch.tv/helix/streams?user_login=$TWITCH_USER" "Authorization: Bearer $twitchauth" "Client-Id: $clientid" -b | ./jtc -w '[data][:][type]') + TWITCH_TITLE_CUT=$(echo "$TWITCH_TITLE" | colrm 70 | tr "><" " ") + + VIDEO_DESCRIPTION="Hosteado por Fijxu. https://twitch.tv/$TWITCH_USER \nTitulo Completo: $TWITCH_TITLE \nFecha y hora: $(date +"A las %H:%M horas, día %d/%m/%y") \nDonaciones: https://ko-fi.com/fijxu \nSi eres el streamer que aparece en el VOD y por alguna razon necesitas ocultar o recuperar (nunca borrare los VODs, eso va en contra de mi objetivo, aunque pueden haber excepciones) el VOD, puedes dejar un comentario, enviar un mensaje por Twitch @fijxu o usando el correo de contacto del canal. \n \nEste es un proyecto de caracter personal, me gusta archivar streams de twitch para que nada se pierda, y que todos puedan volver a ver streams del pasado sin problemas. 'Sharing is caring'" # Descripción del video + + echo "Using Twitch user: $TWITCH_USER | ID: $TWITCH_USER_ID" + echo "Titulo del stream: $TWITCH_TITLE" + echo "Titulo del stream cortado: $TWITCH_TITLE_CUT" + echo "" + + # NOMBRE DEL STREAMER (TWITCH) - NOMBRE DEL TITULO CORTADO (por limitaciones de caracteres de youtube) - FECHA + VIDEO_TITLE="$STREAMER_NAME - $TWITCH_TITLE_CUT ~ $TIME_DATE" + + # Crea el archivo JSON usado por youtubeuploader para agregar la información del VOD para Youtube + echo '{"title":"'"$VIDEO_TITLE"'","privacyStatus":"'"$VIDEO_VISIBILITY"'","description":"'"$VIDEO_DESCRIPTION"'","playlistTitles":["'"${VIDEO_PLAYLIST}"'"]}' >/tmp/input."$STREAMER_NAME" + + echo "Titulo actualizado: $VIDEO_TITLE" + echo "En vivo, subiendo a YouTube" + streamlink https://twitch.tv/"$STREAMER_NAME" $STREAMLINK_OPTIONS | youtubeuploader -metaJSON /tmp/input."$STREAMER_NAME" -filename - + else + echo "No hay streams disponibles, reintentando en 10 seg" + fi + sleep 10s + +done