diff --git a/.build/prod/compose.yml b/.build/prod/compose.yml new file mode 100644 index 0000000..dc2af36 --- /dev/null +++ b/.build/prod/compose.yml @@ -0,0 +1,7 @@ +services: + yt-restream: + build: + context: ../../ + dockerfile: .build/prod/yt-restream.Dockerfile + hostname: yt-restream + image: git.shihaam.dev/sarlink/tv/yt-restream diff --git a/.build/prod/yt-restream.Dockerfile b/.build/prod/yt-restream.Dockerfile new file mode 100644 index 0000000..7311e99 --- /dev/null +++ b/.build/prod/yt-restream.Dockerfile @@ -0,0 +1,12 @@ +FROM debian:latest + +WORKDIR /root/ + +RUN apt update \ + && apt install -y python3-pip curl ffmpeg \ + && pip install yt-dlp --break-system-packages + +COPY yt-restream.sh . +WORKDIR /var/www/html + +CMD python3 -m http.server -d live/ & /root/yt-restream.sh diff --git a/yt-restream.sh b/yt-restream.sh new file mode 100755 index 0000000..82545f6 --- /dev/null +++ b/yt-restream.sh @@ -0,0 +1,20 @@ +#!/bin/bash + + +if [ -n "$1" ]; then + CHANNEL_ID="$1" +elif [ -n "$CHANNEL_ID" ]; then + CHANNEL_ID="$CHANNEL_ID" +else + echo "Error: No channel ID provided. Use as argument or set CHANNEL_ID environment variable." + exit 1 +fi + +while true; do + VIDEO_ID=$(curl -sL https://www.youtube.com/@$CHANNEL_ID/streams | grep "Tap to watch live" | sed 's/.*\/watch?v=\([^\\]*\).*/\1/') + M3U8_STREAM_URL=$(yt-dlp -g -f b $(echo https://www.youtube.com/watch?v=$VIDEO_ID)) + + mkdir -p live + timeout 21555 ffmpeg -i $M3U8_STREAM_URL -c copy -f hls -hls_time 6 -hls_list_size 10 -hls_flags delete_segments live/$CHANNEL_ID.m3u + rm -rf live/* +done