Skip to content

Commit

Permalink
Fix episodes with no available subs (fix #15)
Browse files Browse the repository at this point in the history
  • Loading branch information
xypwn committed May 11, 2024
1 parent 075a626 commit 8d34290
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions pkg/southpark/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ func getHLSStream(ctx context.Context, uriPrefix, hlsURI string) (HLSStream, err
type EpisodeStream struct {
Video HLSStream
Audio HLSStream
Subs HLSStream
Subs HLSStream // subs are not available if len(Subs.Segments) == 0
}

func GetEpisodeStream(ctx context.Context, e Episode, selectFormat func([]HLSFormat) (HLSFormat, error)) (EpisodeStream, error) {
Expand All @@ -407,40 +407,48 @@ func GetEpisodeStream(ctx context.Context, e Episode, selectFormat func([]HLSFor
return EpisodeStream{}, fmt.Errorf("parseMasterM3U8: %w", err)
}

if len(hlsMaster.VideoFormats) == 0 || hlsMaster.AudioURI == "" {
return EpisodeStream{}, fmt.Errorf("master M3U8 does not contain a video or audio track")
}

videoFormat, err := selectFormat(hlsMaster.VideoFormats)
if err != nil {
return EpisodeStream{}, fmt.Errorf("selectFormat: %w", err)
}

videoStream, err := getHLSStream(ctx, uriPrefix, videoFormat.URI)
if err != nil {
return EpisodeStream{}, fmt.Errorf("getHLSStream: %w", err)
return EpisodeStream{}, fmt.Errorf("get video HLS stream: %w", err)
}
if videoStream.Key == nil || videoStream.Key.Method != "AES-128" {
return EpisodeStream{}, fmt.Errorf("unable to decrypt '%v'; only AES-128 decryption is supported", videoStream.Key.Method)
return EpisodeStream{}, fmt.Errorf("unable to decrypt video with method '%v', only AES-128 decryption is supported", videoStream.Key.Method)
}

audioStream, err := getHLSStream(ctx, uriPrefix, hlsMaster.AudioURI)
if err != nil {
return EpisodeStream{}, fmt.Errorf("getHLSStream: %w", err)
return EpisodeStream{}, fmt.Errorf("get audio HLS stream: %w", err)
}
if audioStream.Key == nil || audioStream.Key.Method != "AES-128" {
return EpisodeStream{}, fmt.Errorf("unable to decrypt '%v'; only AES-128 decryption is supported", videoStream.Key.Method)
return EpisodeStream{}, fmt.Errorf("unable to decrypt audio with method '%v', only AES-128 decryption is supported", videoStream.Key.Method)
}

subsStream, err := getHLSStream(ctx, uriPrefix, hlsMaster.SubsURI)
if err != nil {
return EpisodeStream{}, fmt.Errorf("getHLSStream: %w", err)
res := EpisodeStream{
Video: videoStream,
Audio: audioStream,
}
if subsStream.Key != nil {
return EpisodeStream{}, fmt.Errorf("expected subs to be unencrypted, but found '%v' key", subsStream.Key.Method)

if hlsMaster.SubsURI != "" {
subsStream, err := getHLSStream(ctx, uriPrefix, hlsMaster.SubsURI)
if err != nil {
return EpisodeStream{}, fmt.Errorf("get subtitle HLS stream: %w", err)
}
if subsStream.Key != nil {
return EpisodeStream{}, fmt.Errorf("expected subs to be unencrypted, but found '%v' key", subsStream.Key.Method)
}
res.Subs = subsStream
}

return EpisodeStream{
Video: videoStream,
Audio: audioStream,
Subs: subsStream,
}, nil
return res, nil
}

// Download order: video, audio, subs. Does not interleave different media types.
Expand Down

0 comments on commit 8d34290

Please sign in to comment.