Skip to content

Commit

Permalink
Fix persistence in case of no subs
Browse files Browse the repository at this point in the history
  • Loading branch information
xypwn committed May 11, 2024
1 parent 8d34290 commit e4fe276
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions pkg/southpark/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,22 +174,27 @@ func (d *Downloader) Do() error {
}
}

if d.outputSubtitlePath != "" && len(stream.Subs.Segments) > 0 {
if d.outputSubtitlePath != "" {
var out bytes.Buffer
startSeg := len(stream.Video.Segments) + len(stream.Audio.Segments)
endSeg := len(stream.Video.Segments) + len(stream.Audio.Segments) + len(stream.Subs.Segments)
for i := startSeg; i < endSeg; i++ {
data, err := os.ReadFile(getSegFileName(i))
if err != nil {
return fmt.Errorf("read subs fragment: %w", err)
}
if i != startSeg {

if _, err := out.WriteString("WEBVTT\r\n\r\n"); err != nil {
return fmt.Errorf("write subs: %w", err)
}

if len(stream.Subs.Segments) > 0 {
startSeg := len(stream.Video.Segments) + len(stream.Audio.Segments)
endSeg := len(stream.Video.Segments) + len(stream.Audio.Segments) + len(stream.Subs.Segments)
for i := startSeg; i < endSeg; i++ {
data, err := os.ReadFile(getSegFileName(i))
if err != nil {
return fmt.Errorf("read subs fragment: %w", err)
}
data = bytes.TrimPrefix(data, []byte("WEBVTT\r\n\r\n"))
if _, err := out.Write(data); err != nil {
return fmt.Errorf("write subs: %w", err)
}
d.OnStatusChanged(DownloaderStatusPostprocessingSubtitles, float64(i)/float64(endSeg))
}
if _, err := out.Write(data); err != nil {
return fmt.Errorf("write subs: %w", err)
}
d.OnStatusChanged(DownloaderStatusPostprocessingSubtitles, float64(i)/float64(endSeg))
}

if err := os.WriteFile(d.outputSubtitlePath, out.Bytes(), 0666); err != nil {
Expand Down

0 comments on commit e4fe276

Please sign in to comment.