-
Notifications
You must be signed in to change notification settings - Fork 8
/
ffprobe.go
68 lines (59 loc) · 1.78 KB
/
ffprobe.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
package main
import (
"context"
"fmt"
"gopkg.in/vansante/go-ffprobe.v2"
"os"
"path/filepath"
"slices"
"strconv"
"strings"
)
func handleFfprobe(path string, ctx context.Context) {
if processing {
return
}
extension := filepath.Ext(path)
if !slices.Contains(supportedInput, extension) {
logMessage(fmt.Sprintf("Invalid input file format (supported: %s)! Path: %s", strings.Join(supportedInput, ", "), path), false)
return
}
for _, anime := range animeList {
if anime.Path == path {
logMessage("File is already added to queue, ignoring it", false)
return
}
}
file, err := os.Stat(path)
if err != nil {
handleSoftError("Reading file stats error", err.Error())
return
}
data, err := ffprobe.ProbeURL(ctx, path)
if err != nil {
handleSoftError("FFPROBE error", err.Error())
return
}
videoStream := data.FirstVideoStream()
pathSplit := strings.Split(path, string(os.PathSeparator))
frameRateSplit := strings.Split(videoStream.AvgFrameRate, "/")
base, _ := strconv.ParseFloat(frameRateSplit[0], 64)
divider, _ := strconv.ParseFloat(frameRateSplit[1], 64)
anime := Anime{
Name: pathSplit[len(pathSplit)-1],
Length: int64(data.Format.DurationSeconds * 1000),
Size: file.Size(),
Width: videoStream.Width,
Height: videoStream.Height,
FrameRate: base / divider,
TotalFrames: int((base / divider) * data.Format.DurationSeconds),
HasSubtitlesStream: data.FirstSubtitleStream() != nil,
Path: path,
Streams: data.Streams,
PixelFormat: videoStream.PixFmt,
Status: NotStarted,
}
animeList = append(animeList, anime)
gui.TotalProgress = fmt.Sprintf("%d / %d", calcFinished(), len(animeList))
logMessage("Added file "+path, false)
}