forked from makebyte/localflix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metadata.go
108 lines (90 loc) · 1.79 KB
/
metadata.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
package main
import "fmt"
type MediaFile struct {
Path string
Title string
Length int
TotalLength int
Cast []string
Directors []string
Desc string
Rating float32
Uploaded bool
IsManual bool
}
type Movie MediaFile
type Episode MediaFile
type Season struct {
Title string // Path of the season folder
Episodes []*Episode // Episode files in the folder
IsManual bool
}
type Series struct {
Title string // Path of TV series folder (containing season folders)
Seasons []*Season
IsManual bool
}
func NewMovie(title string) *Movie {
m := &Movie{Title: title}
return m
}
func NewSeries(title string) *Series {
s := &Series{Title: title}
return s
}
func NewSeason() *Season {
s := &Season{}
return s
}
func NewEpisode() *Episode {
e := &Episode{}
return e
}
func CheckSeries(s *Series) bool {
if cap(s.Seasons) != 0 {
return false
}
return true
}
func CheckSeasons(s *Season) bool {
if cap(s.Episodes) != 0 {
return false
}
return true
}
func (s *Series) AddSeason(season *Season) {
if CheckSeries(s) {
s.Seasons = make([]*Season, 1)
s.Seasons[0] = season
} else {
s.Seasons = append(s.Seasons, season)
}
}
func (s *Season) AddEpisode(episode *Episode) {
if CheckSeasons(s) {
s.Episodes = make([]*Episode, 1)
s.Episodes[0] = episode
} else {
s.Episodes = append(s.Episodes, episode)
}
}
func (s *Series) DisplayTree() {
fmt.Println(s.Title)
for _, season := range s.Seasons {
fmt.Println(" ", season.Title)
for _, episodes := range season.Episodes {
fmt.Println(" ", episodes.Title)
fmt.Println(" ", episodes.Path)
}
}
}
func main() {
x := NewSeries("Mr Robot")
y := NewSeason()
y.Title = "Season 1"
e := NewEpisode()
e.Title = "Pilot"
y.AddEpisode(e)
x.AddSeason(y)
x.DisplayTree()
}