From 8e791f7e8b506b0aa14edc96a46681395e954044 Mon Sep 17 00:00:00 2001 From: bytedream Date: Sat, 26 Mar 2022 19:10:02 +0100 Subject: [PATCH] Fix unnecessary subtitle removing (#18) and add option to enable custom subtitle sorting --- cmd/crunchyroll-go/cmd/archive.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/cmd/crunchyroll-go/cmd/archive.go b/cmd/crunchyroll-go/cmd/archive.go index 17072eb..f94d20a 100644 --- a/cmd/crunchyroll-go/cmd/archive.go +++ b/cmd/crunchyroll-go/cmd/archive.go @@ -385,13 +385,15 @@ func archiveInfo(info formatInformation, writeCloser io.WriteCloser, filename st } sort.Sort(utils.SubtitlesByLocale(info.format.Subtitles)) - if len(archiveLanguagesFlag) > 0 && archiveLanguagesFlag[0] != "all" { - for j, language := range archiveLanguagesFlag { - locale := crunchyroll.LOCALE(language) - for k, subtitle := range info.format.Subtitles { - if subtitle.Locale == locale { - info.format.Subtitles = append(info.format.Subtitles[:k], info.format.Subtitles[k+1:]...) - info.format.Subtitles = append(info.format.Subtitles[:j], append([]*crunchyroll.Subtitle{subtitle}, info.format.Subtitles[j:]...)...) + + sortSubtitles, _ := strconv.ParseBool(os.Getenv("SORT_SUBTITLES")) + if sortSubtitles && len(archiveLanguagesFlag) > 0 { + // this sort the subtitle locales after the languages which were specified + // with the `archiveLanguagesFlag` flag + for _, language := range archiveLanguagesFlag { + for i, subtitle := range info.format.Subtitles { + if subtitle.Locale == crunchyroll.LOCALE(language) { + info.format.Subtitles = append([]*crunchyroll.Subtitle{subtitle}, append(info.format.Subtitles[:i], info.format.Subtitles[i+1:]...)...) break } }