-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ugoira.go
64 lines (57 loc) · 1.55 KB
/
ugoira.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package ugoira
import (
"fmt"
"strings"
"github.com/KJHJason/Cultured-Downloader-Logic/api"
cdlerrors "github.com/KJHJason/Cultured-Downloader-Logic/errors"
)
// UgoiraDlOptions is the struct that contains the
// configs for the processing of the ugoira images after downloading from Pixiv.
type UgoiraOptions struct {
DeleteZip bool
Quality int
OutputFormat string
}
var UGOIRA_ACCEPTED_EXT = []string{
".gif",
".apng",
".webp",
".webm",
".mp4",
}
// ValidateArgs validates the arguments of the ugoira process options.
//
// Should be called after initialising the struct.
func (u *UgoiraOptions) ValidateArgs() error {
u.OutputFormat = strings.ToLower(u.OutputFormat)
// u.Quality is only for .mp4 and .webm
if u.OutputFormat == ".mp4" && u.Quality < 0 || u.Quality > 51 {
return fmt.Errorf(
"pixiv error %d: Ugoira quality of %d is not allowed\nUgoira quality for FFmpeg must be between 0 and 51 for .mp4",
cdlerrors.INPUT_ERROR,
u.Quality,
)
} else if u.OutputFormat == ".webm" && u.Quality < 0 || u.Quality > 63 {
return fmt.Errorf(
"pixiv error %d: Ugoira quality of %d is not allowed\nUgoira quality for FFmpeg must be between 0 and 63 for .webm",
cdlerrors.INPUT_ERROR,
u.Quality,
)
}
u.OutputFormat = strings.ToLower(u.OutputFormat)
_, err := api.ValidateStrArgs(
u.OutputFormat,
UGOIRA_ACCEPTED_EXT,
[]string{
fmt.Sprintf(
"pixiv error %d: Output extension %q is not allowed for ugoira conversion",
cdlerrors.INPUT_ERROR,
u.OutputFormat,
),
},
)
if err != nil {
return err
}
return nil
}