How can the API be used to select the best stream object from a list that contains multiple stream objects? #5988
-
DescriptionI initially retrieved the list of stream objects - video_streams via DASHStream.parse_manifest. Next, I filtered the video_streams, and chose the stream objects that fit the stream.video_representation.mimeType == "video/mp2t" criteria to form the filtered_streams.Is it possible to carry out this filtering operation using an API? I attempted to select the stream object with the highest video_representation.bandwidth from the filtered_streams, but I used my own method to do this.Can the operation of filtering be done using the streamlink API? For object, if I put in filtered_streams and best as the parameters, can the API return the best_stream? Which specific API do I use and how does it work? The following is the code I used. import streamlink
from streamlink_cli.output import FileOutput
from streamlink_cli.main import open_stream
from streamlink_cli.streamrunner import StreamRunner
from streamlink.stream import StreamIO, HTTPStream, HLSStream, DASHStream
url = f"https://apis.naver.com/neonplayer/vodplay/v2/playback/{video_id}?key={in_key}"
session = streamlink.session.Streamlink({
'stream-segment-timeout': 60
})
video_streams = DASHStream.parse_manifest(session, url, headers={"Accept": "application/dash+xml"})
for name in video_streams:
print(f"Stream name: {name}, Stream object: {video_streams[name]},Stream mimeType: {video_streams[name].video_representation.mimeType}")
filtered_streams = {name: stream for name, stream in video_streams.items() if stream.video_representation.mimeType == "video/mp2t"}
best_stream_name = max(filtered_streams, key=lambda name: filtered_streams[name].video_representation.bandwidth,
default=None)
best_stream = filtered_streams[best_stream_name] if best_stream_name else None
stream_writer(best_stream, filename, output_path) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Why are you doing this custom stuff when the Also,
This whole design will be reworked at some point in the future, because it was developed during the early livestreamer days and has never been improved upon. It's very limiting today. Sorting streams via a public interface is tied to the plugins systems. |
Beta Was this translation helpful? Give feedback.
Why are you doing this custom stuff when the
chzzk
plugin has just been merged into master?https://github.com/streamlink/streamlink/commits/fef6fd66d1a4499cadd13c4ae76ffe1d8f427805/
Also,
streamlink_cli
is not a public interface. You can't rely on its stability. So whatever you're doing with it, you're on your own and won't receive any support in third party implementations.DASHStream.parse_manifest()
returns adict[str, DASHStream]
object where the keys are the "quality names" defined by the DASH implementation (limiting - see below).DASHStream
instances have avideo_representation
and anaudio_representation
which both have different attributes. If you want to get the "best" stream f…