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

Commit

Permalink
Fix subtitle styling and size (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
bytedream committed Oct 31, 2022
1 parent 0572af4 commit 95b66c3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
34 changes: 33 additions & 1 deletion cli/commands/archive/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ var (
archiveResolutionFlag string

archiveGoroutinesFlag int

archiveNoSubtitleOptimizations bool
)

var Cmd = &cobra.Command{
Expand Down Expand Up @@ -203,6 +205,11 @@ func init() {
"g",
runtime.NumCPU(),
"Number of parallel segment downloads")

Cmd.Flags().BoolVar(&archiveNoSubtitleOptimizations,
"no-subtitle-optimizations",
false,
"Disable subtitle optimizations. See https://github.com/crunchy-labs/crunchy-cli/issues/66 for more information")
}

func archive(urls []string) error {
Expand Down Expand Up @@ -540,13 +547,38 @@ func archiveDownloadSubtitles(filename string, subtitles ...*crunchyroll.Subtitl
}
files = append(files, f.Name())

if err := subtitle.Save(f); err != nil {
buffer := &bytes.Buffer{}

if err := subtitle.Save(buffer); err != nil {
f.Close()
for _, file := range files {
os.Remove(file)
}
return nil, err
}

if !archiveNoSubtitleOptimizations {
buffer2 := &bytes.Buffer{}
var scriptInfo bool
for _, line := range strings.Split(buffer.String(), "\n") {
if scriptInfo && strings.HasPrefix(strings.TrimSpace(line), "[") {
buffer2.WriteString("ScaledBorderAndShadows: yes\n")
scriptInfo = false
} else if strings.TrimSpace(line) == "[Script Info]" {
scriptInfo = true
}
buffer2.WriteString(line + "\n")
}

if _, err = io.Copy(f, buffer2); err != nil {
return nil, err
}
} else {
if _, err = io.Copy(f, buffer); err != nil {
return nil, err
}
}

f.Close()

utils.Log.Debug("Downloaded '%s' subtitles", subtitle.Locale)
Expand Down
4 changes: 4 additions & 0 deletions crunchy-cli.1
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ The video resolution. Can either be specified via the pixels (e.g. 1920x1080), t

\fB-g, --goroutines GOROUTINES\fR
Sets the number of parallel downloads for the segments the final video is made of. Default is the number of cores the computer has.
.TP

\fB--no-subtitle-optimizations DISABLE\fR
Disable subtitle optimizations which caused subtitle sizing and layout issues (https://github.com/crunchy-labs/crunchy-cli/issues/66).

.SH UPDATE COMMAND
Checks if a newer version is available.
Expand Down

0 comments on commit 95b66c3

Please sign in to comment.