type.go 8.4 KB

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