bestasstosrt does not also remove all sub streams from mkv
parent
b17801060e
commit
44bcc0ba2e
|
|
@ -46,7 +46,31 @@ func deport(ctx context.Context, p string) error {
|
|||
}
|
||||
}
|
||||
|
||||
return BestAssToSRT(ctx, p)
|
||||
if err := BestAssToSRT(ctx, p); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
base := path.Base(p)
|
||||
withoutExt := strings.TrimSuffix(base, path.Ext(base))
|
||||
p2 := path.Join(path.Dir(p), fmt.Sprintf("%s.subless.mkv", withoutExt))
|
||||
args := []string{
|
||||
"-i", p,
|
||||
"-map", "0",
|
||||
}
|
||||
for _, assStream := range assStreams {
|
||||
args = append(args, "-map", "-"+assStream.id)
|
||||
}
|
||||
args = append(args,
|
||||
"-c", "copy",
|
||||
p2,
|
||||
)
|
||||
if err := ffmpeg(ctx, args...); err != nil {
|
||||
return err
|
||||
} else if err := os.Rename(p2, p); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type stream struct {
|
||||
|
|
@ -110,11 +134,6 @@ func execc(ctx context.Context, bin string, args ...string) (string, error) {
|
|||
}
|
||||
|
||||
func BestAssToSRT(ctx context.Context, p string) error {
|
||||
assStreams, err := assStreams(ctx, p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
asses, err := filepath.Glob(path.Join(
|
||||
path.Dir(p),
|
||||
fmt.Sprintf(".%s.*.ass", path.Base(p)),
|
||||
|
|
@ -132,10 +151,7 @@ func BestAssToSRT(ctx context.Context, p string) error {
|
|||
srts = append(srts, srt)
|
||||
}
|
||||
|
||||
srts, err = SRTsByGoodness(ctx, srts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
srts = SRTsByGoodness(srts)
|
||||
|
||||
for i := range srts {
|
||||
if i == 0 {
|
||||
|
|
@ -146,24 +162,6 @@ func BestAssToSRT(ctx context.Context, p string) error {
|
|||
if err := os.Rename(srts[i], srt); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
p2 := path.Join(path.Dir(p), fmt.Sprintf("%s.subless.mkv", withoutExt))
|
||||
args := []string{
|
||||
"-i", p,
|
||||
"-map", "0",
|
||||
}
|
||||
for _, assStream := range assStreams {
|
||||
args = append(args, "-map", "-"+assStream.id)
|
||||
}
|
||||
args = append(args,
|
||||
"-c", "copy",
|
||||
p2,
|
||||
)
|
||||
if err := ffmpeg(ctx, args...); err != nil {
|
||||
return err
|
||||
} else if err := os.Rename(p2, p); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
os.Remove(srts[i])
|
||||
}
|
||||
|
|
@ -199,7 +197,22 @@ func assToSRT(ctx context.Context, ass string) (string, error) {
|
|||
return srt, nil
|
||||
}
|
||||
|
||||
func SRTsByGoodness(ctx context.Context, srts []string) ([]string, error) {
|
||||
func SRTsByGoodness(srts []string) []string {
|
||||
/*
|
||||
1 lat.*amer Lat.*Amer \
|
||||
2 signs \
|
||||
3 rus Rus \
|
||||
4 por Por \
|
||||
5 ita Ita \
|
||||
6 fre Fre \
|
||||
7 spa Spa \
|
||||
8 ger Ger \
|
||||
9 ara Ara \
|
||||
10 jpn Jpn \
|
||||
11 Europ \
|
||||
12 Brazil \
|
||||
13 Deu \
|
||||
*/
|
||||
srts = slices.Clone(srts)
|
||||
slices.SortFunc(srts, func(a, b string) int {
|
||||
// if skip a { return 1 }
|
||||
|
|
@ -207,5 +220,5 @@ func SRTsByGoodness(ctx context.Context, srts []string) ([]string, error) {
|
|||
// return -1 * (wc(a) - wc(b))
|
||||
return strings.Compare(a, b)
|
||||
})
|
||||
return srts, nil
|
||||
return srts
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,29 @@
|
|||
package asses_test
|
||||
|
||||
import (
|
||||
"show-rss/src/asses"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSRTsByGoodness(t *testing.T) {
|
||||
cases := map[string]struct {
|
||||
given []string
|
||||
want string
|
||||
}{
|
||||
"eng": {
|
||||
given: []string{"a", "eng"},
|
||||
want: "eng",
|
||||
},
|
||||
}
|
||||
|
||||
for name, d := range cases {
|
||||
name := name
|
||||
c := d
|
||||
t.Run(name, func(t *testing.T) {
|
||||
got := asses.SRTsByGoodness(c.given)
|
||||
if got[0] != c.want {
|
||||
t.Errorf("expected %s but got %s (%+v)", c.want, got[0], got)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue