Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

Check if m3u8 contains audio stream before use #185

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions fansly_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,12 +638,15 @@ def download_ts(ts_file: str):

input_container = av.open(io.BytesIO(segment), format='mpegts')
video_stream = input_container.streams.video[0]
audio_stream = input_container.streams.audio[0]
audio_stream = False
if input_container.streams.audio:
audio_stream = input_container.streams.audio[0]

# define output container and streams
output_container = av.open(f"{save_path}.mp4", 'w') # add .mp4 file extension
video_stream = output_container.add_stream(template=video_stream)
audio_stream = output_container.add_stream(template=audio_stream)
if audio_stream:
audio_stream = output_container.add_stream(template=audio_stream)

start_pts = None
for packet in input_container.demux():
Expand All @@ -658,7 +661,7 @@ def download_ts(ts_file: str):

if packet.stream == input_container.streams.video[0]:
packet.stream = video_stream
elif packet.stream == input_container.streams.audio[0]:
elif audio_stream and packet.stream == input_container.streams.audio[0]:
packet.stream = audio_stream
output_container.mux(packet)

Expand Down