-
Notifications
You must be signed in to change notification settings - Fork 42
/
file.go
79 lines (68 loc) · 1.65 KB
/
file.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
package model
import (
"gorm.io/gorm"
"net/url"
"strings"
)
type FileType uint
const (
FILETYPE_INVALID = iota
// Deprecated: vods can now be downloaded from the edge server using the signed playlist url + ?download=1.
FILETYPE_VOD
FILETYPE_ATTACHMENT
FILETYPE_IMAGE_JPG
FILETYPE_THUMB_COMB
FILETYPE_THUMB_CAM
FILETYPE_THUMB_PRES
FILETYPE_THUMB_LG_COMB
FILETYPE_THUMB_LG_CAM
FILETYPE_THUMB_LG_PRES
FILETYPE_THUMB_LG_CAM_PRES // generated from CAM and PRES, preferred over the others
)
type File struct {
gorm.Model
StreamID uint `gorm:"not null"`
Path string `gorm:"not null"`
Filename string
Type FileType `gorm:"not null; default: 1"`
}
func (f File) GetDownloadFileName() string {
pts := strings.Split(f.Path, "/")
if len(pts) == 0 {
return ""
}
return pts[len(pts)-1]
}
func (f File) GetFriendlyFileName() string {
fn := f.GetDownloadFileName()
if strings.Contains(strings.ToLower(fn), "cam") {
return "Camera-view"
}
if strings.Contains(strings.ToLower(fn), "pres") {
return "Presentation"
}
if f.Filename != "" {
return f.Filename
}
return "Default view"
}
// GetVodTypeByName infers the type of a video file based on its name.
func (f File) GetVodTypeByName() string {
if strings.HasSuffix(f.Path, "CAM.mp4") {
return "CAM"
}
if strings.HasSuffix(f.Path, "PRES.mp4") {
return "PRES"
}
return "COMB"
}
func (f File) IsThumb() bool {
return f.Type == FILETYPE_THUMB_CAM || f.Type == FILETYPE_THUMB_PRES || f.Type == FILETYPE_THUMB_COMB
}
func (f File) IsURL() bool {
parsedUrl, err := url.Parse(f.Path)
if err != nil {
return false
}
return parsedUrl.Scheme == "https://" || parsedUrl.Scheme == "http://"
}