@@ -374,18 +374,25 @@ struct Video
374374 json.array do
375375 self .adaptive_fmts.each do |fmt |
376376 json.object do
377- json.field " index" , " #{ fmt[" indexRange" ][" start" ] } -#{ fmt[" indexRange" ][" end" ] } "
378- json.field " bitrate" , fmt[" bitrate" ].as_i.to_s
379- json.field " init" , " #{ fmt[" initRange" ][" start" ] } -#{ fmt[" initRange" ][" end" ] } "
377+ # Only available on regular videos, not livestreams/OFT streams
378+ if init_range = fmt[" initRange" ]?
379+ json.field " init" , " #{ init_range[" start" ] } -#{ init_range[" end" ] } "
380+ end
381+ if index_range = fmt[" indexRange" ]?
382+ json.field " index" , " #{ index_range[" start" ] } -#{ index_range[" end" ] } "
383+ end
384+
385+ # Not available on MPEG-4 Timed Text (`text/mp4`) streams (livestreams only)
386+ json.field " bitrate" , fmt[" bitrate" ].as_i.to_s if fmt[" bitrate" ]?
387+
380388 json.field " url" , fmt[" url" ]
381389 json.field " itag" , fmt[" itag" ].as_i.to_s
382390 json.field " type" , fmt[" mimeType" ]
383- json.field " clen" , fmt[" contentLength" ]
391+ json.field " clen" , fmt[" contentLength" ]? || " -1 "
384392 json.field " lmt" , fmt[" lastModified" ]
385393 json.field " projectionType" , fmt[" projectionType" ]
386394
387- fmt_info = itag_to_metadata?(fmt[" itag" ])
388- if fmt_info
395+ if fmt_info = itag_to_metadata?(fmt[" itag" ])
389396 fps = fmt_info[" fps" ]?.try & .to_i || fmt[" fps" ]?.try & .as_i || 30
390397 json.field " fps" , fps
391398 json.field " container" , fmt_info[" ext" ]
@@ -612,6 +619,7 @@ struct Video
612619 fmt[" url" ] = JSON ::Any .new(" #{ fmt[" url" ] } &host=#{ URI .parse(fmt[" url" ].as_s).host} " )
613620 fmt[" url" ] = JSON ::Any .new(" #{ fmt[" url" ] } ®ion=#{ self .info[" region" ]} " ) if self .info[" region" ]?
614621 end
622+
615623 fmt_stream.sort_by! { |f | f[" width" ]?.try & .as_i || 0 }
616624 @fmt_stream = fmt_stream
617625 return @fmt_stream .as(Array (Hash (String , JSON ::Any )))
@@ -631,9 +639,7 @@ struct Video
631639 fmt[" url" ] = JSON ::Any .new(" #{ fmt[" url" ] } &host=#{ URI .parse(fmt[" url" ].as_s).host} " )
632640 fmt[" url" ] = JSON ::Any .new(" #{ fmt[" url" ] } ®ion=#{ self .info[" region" ]} " ) if self .info[" region" ]?
633641 end
634- # See https://github.com/TeamNewPipe/NewPipe/issues/2415
635- # Some streams are segmented by URL `sq/` rather than index, for now we just filter them out
636- fmt_stream.reject! { |f | ! f[" indexRange" ]? }
642+
637643 fmt_stream.sort_by! { |f | f[" width" ]?.try & .as_i || 0 }
638644 @adaptive_fmts = fmt_stream
639645 return @adaptive_fmts .as(Array (Hash (String , JSON ::Any )))
0 commit comments