Live streaming youtube sumber videonya dari youtube dengan python

pip install pytube ffmpeg-python

 


# live video biasa

import subprocess
from pytube import YouTube

def download_video(video_url, filename):
    yt = YouTube(video_url)
    yt.streams.get_highest_resolution().download(filename=filename)

def restream_video(input_file, output_url):
    command = [
        'ffmpeg',
        '-re',
        '-i', input_file,
        '-c:v', 'copy',
        '-c:a', 'copy',
        '-f', 'flv', 
        output_url
    ]
    subprocess.run(command)

def main(video_url, output_url):
    # Download video
    filename = 'video.mp4'
    download_video(video_url, filename)
    
    # Restream video
    restream_video(filename, output_url)

if __name__ == "__main__":
    video_url = 'https://www.youtube.com/watch?v=YOUR_VIDEO_ID'
    output_url = 'rtmp://a.rtmp.youtube.com/live2/YOUR_STREAM_KEY'
    main(video_url, output_url)