-
Notifications
You must be signed in to change notification settings - Fork 8
/
utils.go
139 lines (113 loc) · 2.71 KB
/
utils.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package main
import (
"fmt"
g "github.com/AllenDang/giu"
"log"
"os"
"strconv"
"strings"
"time"
)
func formatMegabytes(bytes int64) string {
return fmt.Sprintf("%d MB", bytes/(1024*1024))
}
func durationToMillis(durationStr string) int64 {
parts := strings.Split(durationStr, ":")
hours, err := strconv.Atoi(parts[0])
if err != nil {
return 0
}
minutes, err := strconv.Atoi(parts[1])
if err != nil {
return 0
}
seconds, err := strconv.Atoi(parts[2])
if err != nil {
return 0
}
duration := time.Duration(hours)*time.Hour + time.Duration(minutes)*time.Minute + time.Duration(seconds)*time.Second
milliseconds := duration.Milliseconds()
return milliseconds
}
func formatMillis(millis int64) string {
calc := millis / 1000
seconds := millis / 1000 % 60
minutes := (calc % 3600) / 60
hours := calc / 3600
if hours < 1 {
return fmt.Sprintf("%02d:%02d", minutes, seconds)
}
return fmt.Sprintf("%02d:%02d:%02d", hours, minutes, seconds)
}
func logDebug(message string, additionalLineBefore bool) {
if settings.DebugMode {
logMessage("[Debug] "+message, additionalLineBefore)
}
}
func logMessage(message string, additionalLineBefore bool) {
if additionalLineBefore {
gui.Logs += "\n"
}
line := fmt.Sprintf("[%s] %s\n", time.Now().Format("15:04:05"), message)
gui.Logs += line
fmt.Print(line)
g.Update()
}
func handleSoftError(message string, logs string) {
logMessage("Critical error occurred, upscaling has been stopped", true)
logMessage("Please make issue on GitHub with logs, upscaling settings and your computer specification", false)
logMessage(message, true)
logMessage(logs, false)
for i := 0; i < len(animeList); i++ {
animeList[i].Status = Error
}
gui.CurrentSpeed = "Speed:"
gui.Eta = "ETA:"
g.Update()
}
func handleMinMax(value *int32, minLimit int32, minValue int32, maxLimit int32, maxValue int32) {
if *value > maxLimit {
*value = maxValue
}
if *value < minLimit {
*value = minValue
}
}
func calcFinished() int {
i := 0
for _, anime := range animeList {
if anime.Status == Finished {
i++
}
}
return i
}
func checkDebugParam() {
if len(os.Args) != 0 {
for _, arg := range os.Args {
if arg == "--debug" {
settings.DebugMode = true
break
}
}
}
}
func check(err error) {
if err != nil {
log.Fatal(err)
}
}
func handleStartUpscalingError(outputPath string, animeIndex int, errorMessage string, err error) {
if outputPath != "" {
os.Remove(outputPath)
}
animeList[animeIndex].Status = Error
gui.ButtonLabel = "Start"
processing = false
g.Update()
if err.Error() != "" {
handleSoftError(errorMessage, err.Error())
return
}
logMessage("File "+animeList[animeIndex].Name+" contains subtitles stream, output format must be MKV", false)
}