type.go 3.9 KB

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