type.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. MediaStreams []struct {
  38. Codec string `json:"Codec"`
  39. Language string `json:"Language"`
  40. DisplayTitle string `json:"DisplayTitle"`
  41. Index int `json:"Index"`
  42. IsExternal bool `json:"IsExternal"`
  43. IsTextSubtitleStream bool `json:"IsTextSubtitleStream"`
  44. SupportsExternalStream bool `json:"SupportsExternalStream"`
  45. Path string `json:"Path"`
  46. Protocol string `json:"Protocol"`
  47. } `json:"MediaStreams"`
  48. }
  49. type EmbyUsers struct {
  50. Items []struct {
  51. Name string `json:"Name"`
  52. Id string `json:"Id"`
  53. } `json:"Items"`
  54. TotalRecordCount int `json:"TotalRecordCount"`
  55. }
  56. type EmbyVideoInfoByUserId struct {
  57. Name string `json:"Name"`
  58. OriginalTitle string `json:"OriginalTitle"`
  59. Id string `json:"Id"`
  60. DateCreated time.Time `json:"DateCreated,omitempty"`
  61. PremiereDate time.Time `json:"PremiereDate,omitempty"`
  62. SortName string `json:"SortName,omitempty"`
  63. Path string `json:"Path"`
  64. MediaSources []struct {
  65. Path string `json:"Path"`
  66. DefaultAudioStreamIndex int `json:"DefaultAudioStreamIndex,omitempty"`
  67. DefaultSubtitleStreamIndex int `json:"DefaultSubtitleStreamIndex,omitempty"`
  68. } `json:"MediaSources"`
  69. }
  70. // GetDefaultSubIndex 获取匹配视频字幕的索引,默认值是0,不应该是0,0 就是没有选择或者说关闭
  71. func (info EmbyVideoInfoByUserId) GetDefaultSubIndex() int {
  72. for _, mediaSource := range info.MediaSources {
  73. if info.Path == mediaSource.Path {
  74. return mediaSource.DefaultSubtitleStreamIndex
  75. }
  76. }
  77. return 0
  78. }
  79. type EmbyMixInfo struct {
  80. VideoFolderName string // 电影就是电影的文件夹名称,连续剧就是对应的剧集的 root 文件夹
  81. VideoFileName string // 视频文件名
  82. VideoFileRelativePath string // 视频文件的相对路径(注意,这里还是需要补齐 x:/电影 这样的 root 路径的,仅仅算相对路径)
  83. VideoFileFullPath string
  84. Ancestors []EmbyItemsAncestors
  85. VideoInfo EmbyVideoInfo
  86. }
  87. type Time time.Time
  88. const (
  89. embyTimeFormart = "2006-01-02T15:04:05"
  90. )
  91. func (t *Time) UnmarshalJSON(data []byte) (err error) {
  92. orgString := string(data)
  93. orgString = strings.ReplaceAll(orgString, "\"", "")
  94. fixTimeString := orgString
  95. if strings.Contains(orgString, ".") == true {
  96. strList := strings.Split(orgString, ".")
  97. if len(strList) > 1 {
  98. fixTimeString = strList[0]
  99. }
  100. }
  101. now, err := time.ParseInLocation(embyTimeFormart, fixTimeString, time.Local)
  102. if err != nil {
  103. return err
  104. }
  105. *t = Time(now)
  106. return
  107. }
  108. func (t Time) MarshalJSON() ([]byte, error) {
  109. b := make([]byte, 0, len(embyTimeFormart)+2)
  110. b = append(b, '"')
  111. b = time.Time(t).AppendFormat(b, embyTimeFormart)
  112. b = append(b, '"')
  113. return b, nil
  114. }
  115. func (t Time) String() string {
  116. return time.Time(t).Format(embyTimeFormart)
  117. }