Pequeño cambio en el script.

- Ofrecer versión del script con xh y jtc
- Explicación de porque usar la nueva version del script es mejor
- + Ejecutable jtc
- ppL
This commit is contained in:
Fijxu 2022-11-22 16:33:53 -03:00
parent 5dc07ebde5
commit b63cf6d8c4
6 changed files with 101 additions and 5 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
.vscode/settings.json

View file

@ -1,8 +1,12 @@
# TwitchToYoutube # 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 # Funciones
@ -29,11 +33,14 @@ El resto de esta guía esta separada en diferentes partes:
- [Como usarlo [INCOMPLETO]](#como-usarlo-incompleto) - [TwitchToYoutube](#twitchtoyoutube)
- [Crear una Aplicación de twitch](#crear-una-aplicaci%C3%B3n-de-twitch) - [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) - [Conseguir los tokens de twitch](#conseguir-los-tokens-de-twitch)
- [Configurar youtubeuploader](#configurar-youtubeuploader) - [Configurar youtubeuploader](#configurar-youtubeuploader)
- [Ejecutar](#ejecutar) - [Ejecutar](#ejecutar)
- [Autor y repo original](#autor-y-repo-original)
## Crear una Aplicación de twitch ## 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 ### Autor y repo original
https://github.com/jenslys/autovod/ [jenslys/autovod](https://github.com/jenslys/autovod/)

35
benchmark.md Normal file
View file

@ -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)

BIN
jtc Executable file

Binary file not shown.

53
twtoyt-xh-jtc.sh Executable file
View file

@ -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