type.go 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. package emby
  2. import (
  3. "strings"
  4. "time"
  5. )
  6. type EmbyRecentlyItems struct {
  7. Items []EmbyRecentlyItem `json:"Items,omitempty"`
  8. TotalRecordCount int `json:"TotalRecordCount,omitempty"`
  9. }
  10. type EmbyRecentlyItem struct {
  11. Name string `json:"Name,omitempty"`
  12. Id string `json:"Id,omitempty"`
  13. IndexNumber int `json:"IndexNumber,omitempty"`
  14. ParentIndexNumber int `json:"ParentIndexNumber,omitempty"`
  15. Type string `json:"Type,omitempty"`
  16. UserData struct {
  17. PlaybackPositionTicks int `json:"PlaybackPositionTicks"`
  18. PlayCount int `json:"PlayCount"`
  19. IsFavorite bool `json:"IsFavorite"`
  20. Played bool `json:"Played"`
  21. } `json:"UserData"`
  22. SeriesName string `json:"SeriesName,omitempty"`
  23. }
  24. type EmbyItemsAncestors struct {
  25. Name string `json:"Name,omitempty"`
  26. ID string `json:"Id,omitempty"`
  27. Path string `json:"Path,omitempty"`
  28. Type string `json:"Type,omitempty"`
  29. }
  30. type EmbyVideoInfo struct {
  31. Name string `json:"Name,omitempty"`
  32. OriginalTitle string `json:"OriginalTitle,omitempty"`
  33. Id string `json:"Id,omitempty"`
  34. DateCreated time.Time `json:"DateCreated,omitempty"`
  35. PremiereDate time.Time `json:"PremiereDate,omitempty"`
  36. SortName string `json:"SortName,omitempty"`
  37. Path string `json:"Path"`
  38. MediaSources []struct {
  39. Protocol string `json:"Protocol"`
  40. Id string `json:"Id"`
  41. Path string `json:"Path"`
  42. Type string `json:"Type"`
  43. Container string `json:"Container"`
  44. Size int `json:"Size"`
  45. Name string `json:"Name"`
  46. IsRemote bool `json:"IsRemote"`
  47. RunTimeTicks int64 `json:"RunTimeTicks"`
  48. SupportsTranscoding bool `json:"SupportsTranscoding"`
  49. SupportsDirectStream bool `json:"SupportsDirectStream"`
  50. SupportsDirectPlay bool `json:"SupportsDirectPlay"`
  51. IsInfiniteStream bool `json:"IsInfiniteStream"`
  52. RequiresOpening bool `json:"RequiresOpening"`
  53. RequiresClosing bool `json:"RequiresClosing"`
  54. RequiresLooping bool `json:"RequiresLooping"`
  55. SupportsProbing bool `json:"SupportsProbing"`
  56. MediaStreams []struct {
  57. Codec string `json:"Codec"`
  58. TimeBase string `json:"TimeBase,omitempty"`
  59. CodecTimeBase string `json:"CodecTimeBase,omitempty"`
  60. VideoRange string `json:"VideoRange,omitempty"`
  61. DisplayTitle string `json:"DisplayTitle"`
  62. NalLengthSize string `json:"NalLengthSize,omitempty"`
  63. IsInterlaced bool `json:"IsInterlaced"`
  64. IsAVC bool `json:"IsAVC,omitempty"`
  65. BitRate int `json:"BitRate,omitempty"`
  66. BitDepth int `json:"BitDepth,omitempty"`
  67. RefFrames int `json:"RefFrames,omitempty"`
  68. IsDefault bool `json:"IsDefault"`
  69. IsForced bool `json:"IsForced"`
  70. Height int `json:"Height,omitempty"`
  71. Width int `json:"Width,omitempty"`
  72. AverageFrameRate float64 `json:"AverageFrameRate,omitempty"`
  73. RealFrameRate float64 `json:"RealFrameRate,omitempty"`
  74. Profile string `json:"Profile,omitempty"`
  75. Type string `json:"Type"`
  76. AspectRatio string `json:"AspectRatio,omitempty"`
  77. Index int `json:"Index"`
  78. IsExternal bool `json:"IsExternal"`
  79. IsTextSubtitleStream bool `json:"IsTextSubtitleStream"`
  80. SupportsExternalStream bool `json:"SupportsExternalStream"`
  81. Protocol string `json:"Protocol"`
  82. PixelFormat string `json:"PixelFormat,omitempty"`
  83. Level int `json:"Level,omitempty"`
  84. IsAnamorphic bool `json:"IsAnamorphic,omitempty"`
  85. Language string `json:"Language,omitempty"`
  86. DisplayLanguage string `json:"DisplayLanguage,omitempty"`
  87. ChannelLayout string `json:"ChannelLayout,omitempty"`
  88. Channels int `json:"Channels,omitempty"`
  89. SampleRate int `json:"SampleRate,omitempty"`
  90. Title string `json:"Title,omitempty"`
  91. Path string `json:"Path,omitempty"`
  92. } `json:"MediaStreams"`
  93. Formats []interface{} `json:"Formats"`
  94. Bitrate int `json:"Bitrate"`
  95. RequiredHttpHeaders struct {
  96. } `json:"RequiredHttpHeaders"`
  97. ReadAtNativeFramerate bool `json:"ReadAtNativeFramerate"`
  98. DefaultAudioStreamIndex int `json:"DefaultAudioStreamIndex"`
  99. DefaultSubtitleStreamIndex int `json:"DefaultSubtitleStreamIndex"`
  100. } `json:"MediaSources"`
  101. MediaStreams []struct {
  102. Codec string `json:"Codec"`
  103. Language string `json:"Language"`
  104. DisplayTitle string `json:"DisplayTitle"`
  105. Index int `json:"Index"`
  106. IsExternal bool `json:"IsExternal"`
  107. IsTextSubtitleStream bool `json:"IsTextSubtitleStream"`
  108. SupportsExternalStream bool `json:"SupportsExternalStream"`
  109. Path string `json:"Path"`
  110. Protocol string `json:"Protocol"`
  111. } `json:"MediaStreams"`
  112. ProviderIds struct {
  113. Tmdb string `json:"Tmdb"`
  114. Imdb string `json:"Imdb"`
  115. } `json:"ProviderIds"`
  116. }
  117. type EmbyUsers struct {
  118. Items []struct {
  119. Name string `json:"Name"`
  120. Id string `json:"Id"`
  121. } `json:"Items"`
  122. TotalRecordCount int `json:"TotalRecordCount"`
  123. }
  124. type EmbyVideoInfoByUserId struct {
  125. Name string `json:"Name"`
  126. OriginalTitle string `json:"OriginalTitle"`
  127. Id string `json:"Id"`
  128. DateCreated time.Time `json:"DateCreated,omitempty"`
  129. PremiereDate time.Time `json:"PremiereDate,omitempty"`
  130. SortName string `json:"SortName,omitempty"`
  131. Path string `json:"Path"`
  132. UserData struct {
  133. PlaybackPositionTicks int `json:"PlaybackPositionTicks"`
  134. PlayCount int `json:"PlayCount"`
  135. IsFavorite bool `json:"IsFavorite"`
  136. Played bool `json:"Played"`
  137. } `json:"UserData"`
  138. MediaSources []struct {
  139. Path string `json:"Path"`
  140. DefaultAudioStreamIndex int `json:"DefaultAudioStreamIndex,omitempty"`
  141. DefaultSubtitleStreamIndex int `json:"DefaultSubtitleStreamIndex,omitempty"`
  142. } `json:"MediaSources"`
  143. }
  144. // GetDefaultSubIndex 获取匹配视频字幕的索引,默认值是0,不应该是0,0 就是没有选择或者说关闭
  145. func (info EmbyVideoInfoByUserId) GetDefaultSubIndex() int {
  146. for _, mediaSource := range info.MediaSources {
  147. if info.Path == mediaSource.Path {
  148. return mediaSource.DefaultSubtitleStreamIndex
  149. }
  150. }
  151. return 0
  152. }
  153. type EmbyMixInfo struct {
  154. IMDBId string // 这个视频的 IMDB ID,注意,连续剧一集是没有 IMDB ID 这个概念的,所以会向上获取到 series 这个级别再取拿 IMDB ID 的
  155. TMDBId string // 这个视频的 TMDb ID
  156. VideoFolderName string // 电影就是电影的文件夹名称,连续剧就是对应的剧集的 root 文件夹
  157. VideoFileName string // 视频文件名
  158. PhysicalVideoFileFullPath string // 视频的物理路径(这里指的物理路径是相对于本程序而言,如果是用 docker 使用的话,那么就是映射容器内的路径,如果是用物理机器比如 Windows 使用的话,那么就是相对于物理机器的路径)
  159. PhysicalRootPath string // 不是 Emby 扫描的情况,无需关注。视频在那个物理根目录中(这里指的物理路径是相对于本程序而言,如果是用 docker 使用的话,那么就是映射容器内的路径,如果是用物理机器比如 Windows 使用的话,那么就是相对于物理机器的路径)
  160. PhysicalSeriesRootDir string // 当前视频的连续剧文件夹根目录
  161. Ancestors []EmbyItemsAncestors
  162. VideoInfo EmbyVideoInfo
  163. }
  164. type UserPlayedItems struct {
  165. UserName string
  166. UserID string
  167. Items []EmbyRecentlyItem
  168. }
  169. type Time time.Time
  170. const (
  171. embyTimeFormart = "2006-01-02T15:04:05"
  172. )
  173. func (t *Time) UnmarshalJSON(data []byte) (err error) {
  174. orgString := string(data)
  175. orgString = strings.ReplaceAll(orgString, "\"", "")
  176. fixTimeString := orgString
  177. if strings.Contains(orgString, ".") == true {
  178. strList := strings.Split(orgString, ".")
  179. if len(strList) > 1 {
  180. fixTimeString = strList[0]
  181. }
  182. }
  183. now, err := time.ParseInLocation(embyTimeFormart, fixTimeString, time.Local)
  184. if err != nil {
  185. return err
  186. }
  187. *t = Time(now)
  188. return
  189. }
  190. func (t Time) MarshalJSON() ([]byte, error) {
  191. b := make([]byte, 0, len(embyTimeFormart)+2)
  192. b = append(b, '"')
  193. b = time.Time(t).AppendFormat(b, embyTimeFormart)
  194. b = append(b, '"')
  195. return b, nil
  196. }
  197. func (t Time) String() string {
  198. return time.Time(t).Format(embyTimeFormart)
  199. }