forked from viewscreen/viewscreen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile.go
More file actions
57 lines (48 loc) · 932 Bytes
/
file.go
File metadata and controls
57 lines (48 loc) · 932 Bytes
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
package main
import (
"os"
"path/filepath"
"strings"
)
type File struct {
ID string
Info os.FileInfo
Path string
}
func (f File) Transcoding() bool {
return ActiveTranscode(f.Path)
}
func (f File) Clickable() bool {
switch f.Ext() {
case "jpg", "jpeg", "gif", "png", "txt", "pdf":
return true
}
return false
}
func (f File) Base() string {
return filepath.Base(f.Info.Name())
}
func (f File) Ext() string {
return strings.TrimPrefix(strings.ToLower(filepath.Ext(f.Info.Name())), ".")
}
func (f File) Viewable() bool {
if strings.Contains(f.Base(), "sample") {
return false
}
switch f.Ext() {
case "mp4", "m4v", "m4a", "m4b", "mp3":
return true
}
return false
}
func (f File) Convertible() bool {
switch f.Ext() {
case "avi", "flv", "mov", "mkv", "webm", "wma":
return true
}
return false
}
func (f File) Thumbnail() bool {
_, err := os.Stat(f.Path + ".thumbnail.png")
return err == nil
}