-
Notifications
You must be signed in to change notification settings - Fork 230
/
type.go
216 lines (199 loc) · 8.82 KB
/
type.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
package emby
import (
"strings"
"time"
)
type EmbyRecentlyItems struct {
Items []EmbyRecentlyItem `json:"Items,omitempty"`
TotalRecordCount int `json:"TotalRecordCount,omitempty"`
}
type EmbyRecentlyItem struct {
Name string `json:"Name,omitempty"`
Id string `json:"Id,omitempty"`
IndexNumber int `json:"IndexNumber,omitempty"`
ParentIndexNumber int `json:"ParentIndexNumber,omitempty"`
Type string `json:"Type,omitempty"`
UserData struct {
PlaybackPositionTicks int `json:"PlaybackPositionTicks"`
PlayCount int `json:"PlayCount"`
IsFavorite bool `json:"IsFavorite"`
Played bool `json:"Played"`
} `json:"UserData"`
SeriesName string `json:"SeriesName,omitempty"`
}
type EmbyItemsAncestors struct {
Name string `json:"Name,omitempty"`
ID string `json:"Id,omitempty"`
Path string `json:"Path,omitempty"`
Type string `json:"Type,omitempty"`
}
type EmbyVideoInfo struct {
Name string `json:"Name,omitempty"`
OriginalTitle string `json:"OriginalTitle,omitempty"`
Id string `json:"Id,omitempty"`
DateCreated time.Time `json:"DateCreated,omitempty"`
PremiereDate time.Time `json:"PremiereDate,omitempty"`
SortName string `json:"SortName,omitempty"`
Path string `json:"Path"`
MediaSources []struct {
Protocol string `json:"Protocol"`
Id string `json:"Id"`
Path string `json:"Path"`
Type string `json:"Type"`
Container string `json:"Container"`
Size int `json:"Size"`
Name string `json:"Name"`
IsRemote bool `json:"IsRemote"`
RunTimeTicks int64 `json:"RunTimeTicks"`
SupportsTranscoding bool `json:"SupportsTranscoding"`
SupportsDirectStream bool `json:"SupportsDirectStream"`
SupportsDirectPlay bool `json:"SupportsDirectPlay"`
IsInfiniteStream bool `json:"IsInfiniteStream"`
RequiresOpening bool `json:"RequiresOpening"`
RequiresClosing bool `json:"RequiresClosing"`
RequiresLooping bool `json:"RequiresLooping"`
SupportsProbing bool `json:"SupportsProbing"`
MediaStreams []struct {
Codec string `json:"Codec"`
TimeBase string `json:"TimeBase,omitempty"`
CodecTimeBase string `json:"CodecTimeBase,omitempty"`
VideoRange string `json:"VideoRange,omitempty"`
DisplayTitle string `json:"DisplayTitle"`
NalLengthSize string `json:"NalLengthSize,omitempty"`
IsInterlaced bool `json:"IsInterlaced"`
IsAVC bool `json:"IsAVC,omitempty"`
BitRate int `json:"BitRate,omitempty"`
BitDepth int `json:"BitDepth,omitempty"`
RefFrames int `json:"RefFrames,omitempty"`
IsDefault bool `json:"IsDefault"`
IsForced bool `json:"IsForced"`
Height int `json:"Height,omitempty"`
Width int `json:"Width,omitempty"`
AverageFrameRate float64 `json:"AverageFrameRate,omitempty"`
RealFrameRate float64 `json:"RealFrameRate,omitempty"`
Profile string `json:"Profile,omitempty"`
Type string `json:"Type"`
AspectRatio string `json:"AspectRatio,omitempty"`
Index int `json:"Index"`
IsExternal bool `json:"IsExternal"`
IsTextSubtitleStream bool `json:"IsTextSubtitleStream"`
SupportsExternalStream bool `json:"SupportsExternalStream"`
Protocol string `json:"Protocol"`
PixelFormat string `json:"PixelFormat,omitempty"`
Level int `json:"Level,omitempty"`
IsAnamorphic bool `json:"IsAnamorphic,omitempty"`
Language string `json:"Language,omitempty"`
DisplayLanguage string `json:"DisplayLanguage,omitempty"`
ChannelLayout string `json:"ChannelLayout,omitempty"`
Channels int `json:"Channels,omitempty"`
SampleRate int `json:"SampleRate,omitempty"`
Title string `json:"Title,omitempty"`
Path string `json:"Path,omitempty"`
} `json:"MediaStreams"`
Formats []interface{} `json:"Formats"`
Bitrate int `json:"Bitrate"`
RequiredHttpHeaders struct {
} `json:"RequiredHttpHeaders"`
ReadAtNativeFramerate bool `json:"ReadAtNativeFramerate"`
DefaultAudioStreamIndex int `json:"DefaultAudioStreamIndex"`
DefaultSubtitleStreamIndex int `json:"DefaultSubtitleStreamIndex"`
} `json:"MediaSources"`
MediaStreams []struct {
Codec string `json:"Codec"`
Language string `json:"Language"`
DisplayTitle string `json:"DisplayTitle"`
Index int `json:"Index"`
IsExternal bool `json:"IsExternal"`
IsTextSubtitleStream bool `json:"IsTextSubtitleStream"`
SupportsExternalStream bool `json:"SupportsExternalStream"`
Path string `json:"Path"`
Protocol string `json:"Protocol"`
} `json:"MediaStreams"`
ProviderIds struct {
Tmdb string `json:"Tmdb"`
Imdb string `json:"Imdb"`
} `json:"ProviderIds"`
}
type EmbyUsers struct {
Items []struct {
Name string `json:"Name"`
Id string `json:"Id"`
} `json:"Items"`
TotalRecordCount int `json:"TotalRecordCount"`
}
type EmbyVideoInfoByUserId struct {
Name string `json:"Name"`
OriginalTitle string `json:"OriginalTitle"`
Id string `json:"Id"`
DateCreated time.Time `json:"DateCreated,omitempty"`
PremiereDate time.Time `json:"PremiereDate,omitempty"`
SortName string `json:"SortName,omitempty"`
Path string `json:"Path"`
UserData struct {
PlaybackPositionTicks int `json:"PlaybackPositionTicks"`
PlayCount int `json:"PlayCount"`
IsFavorite bool `json:"IsFavorite"`
Played bool `json:"Played"`
} `json:"UserData"`
MediaSources []struct {
Path string `json:"Path"`
DefaultAudioStreamIndex int `json:"DefaultAudioStreamIndex,omitempty"`
DefaultSubtitleStreamIndex int `json:"DefaultSubtitleStreamIndex,omitempty"`
} `json:"MediaSources"`
}
// GetDefaultSubIndex 获取匹配视频字幕的索引,默认值是0,不应该是0,0 就是没有选择或者说关闭
func (info EmbyVideoInfoByUserId) GetDefaultSubIndex() int {
for _, mediaSource := range info.MediaSources {
if info.Path == mediaSource.Path {
return mediaSource.DefaultSubtitleStreamIndex
}
}
return 0
}
type EmbyMixInfo struct {
IMDBId string // 这个视频的 IMDB ID,注意,连续剧一集是没有 IMDB ID 这个概念的,所以会向上获取到 series 这个级别再取拿 IMDB ID 的
TMDBId string // 这个视频的 TMDb ID
VideoFolderName string // 电影就是电影的文件夹名称,连续剧就是对应的剧集的 root 文件夹
VideoFileName string // 视频文件名
PhysicalVideoFileFullPath string // 视频的物理路径(这里指的物理路径是相对于本程序而言,如果是用 docker 使用的话,那么就是映射容器内的路径,如果是用物理机器比如 Windows 使用的话,那么就是相对于物理机器的路径)
PhysicalRootPath string // 不是 Emby 扫描的情况,无需关注。视频在那个物理根目录中(这里指的物理路径是相对于本程序而言,如果是用 docker 使用的话,那么就是映射容器内的路径,如果是用物理机器比如 Windows 使用的话,那么就是相对于物理机器的路径)
PhysicalSeriesRootDir string // 当前视频的连续剧文件夹根目录
Ancestors []EmbyItemsAncestors
VideoInfo EmbyVideoInfo
}
type UserPlayedItems struct {
UserName string
UserID string
Items []EmbyRecentlyItem
}
type Time time.Time
const (
embyTimeFormart = "2006-01-02T15:04:05"
)
func (t *Time) UnmarshalJSON(data []byte) (err error) {
orgString := string(data)
orgString = strings.ReplaceAll(orgString, "\"", "")
fixTimeString := orgString
if strings.Contains(orgString, ".") == true {
strList := strings.Split(orgString, ".")
if len(strList) > 1 {
fixTimeString = strList[0]
}
}
now, err := time.ParseInLocation(embyTimeFormart, fixTimeString, time.Local)
if err != nil {
return err
}
*t = Time(now)
return
}
func (t Time) MarshalJSON() ([]byte, error) {
b := make([]byte, 0, len(embyTimeFormart)+2)
b = append(b, '"')
b = time.Time(t).AppendFormat(b, embyTimeFormart)
b = append(b, '"')
return b, nil
}
func (t Time) String() string {
return time.Time(t).Format(embyTimeFormart)
}