update
This commit is contained in:
@@ -5,13 +5,13 @@ VIDEOS_DIR = "/videos"
|
||||
CHUNK_SIZE = 64 * 1024
|
||||
|
||||
|
||||
def _get_stream_urls(youtube_url: str):
|
||||
def _getStreamUrls(youtubeUrl: str):
|
||||
result = subprocess.run(
|
||||
[
|
||||
"yt-dlp",
|
||||
"-f", "bestvideo[ext=mp4][vcodec^=avc]+bestaudio[ext=m4a]/best[ext=mp4]",
|
||||
"--print", "urls",
|
||||
youtube_url,
|
||||
youtubeUrl,
|
||||
],
|
||||
capture_output=True, text=True, timeout=30,
|
||||
)
|
||||
@@ -26,24 +26,24 @@ def _get_stream_urls(youtube_url: str):
|
||||
return None, None
|
||||
|
||||
|
||||
def stream_video_live(video_id: int, youtube_url: str):
|
||||
output_path = f"{VIDEOS_DIR}/{video_id}.mp4"
|
||||
def streamVideoLive(videoId: int, youtubeUrl: str):
|
||||
outputPath = f"{VIDEOS_DIR}/{videoId}.mp4"
|
||||
|
||||
video_url, audio_url = _get_stream_urls(youtube_url)
|
||||
if not video_url:
|
||||
videoUrl, audioUrl = _getStreamUrls(youtubeUrl)
|
||||
if not videoUrl:
|
||||
return
|
||||
|
||||
if audio_url:
|
||||
if audioUrl:
|
||||
cmd = [
|
||||
"ffmpeg",
|
||||
"-reconnect", "1",
|
||||
"-reconnect_streamed", "1",
|
||||
"-reconnect_delay_max", "5",
|
||||
"-i", video_url,
|
||||
"-i", videoUrl,
|
||||
"-reconnect", "1",
|
||||
"-reconnect_streamed", "1",
|
||||
"-reconnect_delay_max", "5",
|
||||
"-i", audio_url,
|
||||
"-i", audioUrl,
|
||||
"-c:v", "copy",
|
||||
"-c:a", "aac",
|
||||
"-movflags", "frag_keyframe+empty_moov+default_base_moof",
|
||||
@@ -56,7 +56,7 @@ def stream_video_live(video_id: int, youtube_url: str):
|
||||
"-reconnect", "1",
|
||||
"-reconnect_streamed", "1",
|
||||
"-reconnect_delay_max", "5",
|
||||
"-i", video_url,
|
||||
"-i", videoUrl,
|
||||
"-c", "copy",
|
||||
"-movflags", "frag_keyframe+empty_moov+default_base_moof",
|
||||
"-f", "mp4",
|
||||
@@ -70,7 +70,7 @@ def stream_video_live(video_id: int, youtube_url: str):
|
||||
)
|
||||
|
||||
try:
|
||||
with open(output_path, "wb") as f:
|
||||
with open(outputPath, "wb") as f:
|
||||
while True:
|
||||
chunk = process.stdout.read(CHUNK_SIZE)
|
||||
if not chunk:
|
||||
@@ -86,6 +86,6 @@ def stream_video_live(video_id: int, youtube_url: str):
|
||||
if process.stdout:
|
||||
process.stdout.close()
|
||||
|
||||
path = Path(output_path)
|
||||
path = Path(outputPath)
|
||||
if process.returncode != 0 and path.exists():
|
||||
path.unlink()
|
||||
|
||||
Reference in New Issue
Block a user