Bläddra i källkod

修复emby 获取所有用户没有看过的列表,有一个人看过的都认为字幕是没得问题的 fix #35

Signed-off-by: allan716 <[email protected]>
allan716 4 år sedan
förälder
incheckning
c4628facf9
2 ändrade filer med 50 tillägg och 12 borttagningar
  1. 33 3
      internal/pkg/emby_helper/emby.go
  2. 17 9
      internal/types/emby/type.go

+ 33 - 3
internal/pkg/emby_helper/emby.go

@@ -94,6 +94,9 @@ func (em EmbyApi) RefreshRecentlyVideoInfo() error {
 func (em EmbyApi) GetRecentlyItems() (emby.EmbyRecentlyItems, error) {
 
 	var recItems emby.EmbyRecentlyItems
+	recItems.Items = make([]emby.EmbyRecentlyItem, 0)
+	var recItemMap = make(map[string]emby.EmbyRecentlyItem)
+	var recItemExsitMap = make(map[string]emby.EmbyRecentlyItem)
 	var err error
 	if em.embyConfig.SkipWatched == false {
 		// 默认是不指定某一个User的视频列表
@@ -129,7 +132,7 @@ func (em EmbyApi) GetRecentlyItems() (emby.EmbyRecentlyItems, error) {
 					"Recursive":        "true",
 					"SortOrder":        "Descending",
 					"IncludeItemTypes": "Episode,Movie",
-					"Filters":          "IsNotFolder,IsUnplayed",
+					"Filters":          "IsNotFolder",
 					"SortBy":           "DateCreated",
 				}).
 				SetResult(&tmpRecItems).
@@ -138,11 +141,38 @@ func (em EmbyApi) GetRecentlyItems() (emby.EmbyRecentlyItems, error) {
 			if err != nil {
 				return emby.EmbyRecentlyItems{}, err
 			}
+			// 相同的视频项目,需要判断是否已经看过了,看过的需要排除
+			// 项目是否相同可以通过 Id 判断
+			for _, recentlyItem := range tmpRecItems.Items {
+				// 这个视频是否已经插入过了,可能会进行删除
+				_, bFound := recItemMap[recentlyItem.Id]
+				if bFound == false {
+					// map 中不存在
+					// 如果没有播放过,则插入
+					if recentlyItem.UserData.Played == false {
+						recItemMap[recentlyItem.Id] = recentlyItem
+					}
+				} else {
+					// map 中存在
+					// 既然存在,则可以理解为其他人是没有看过的,但是,如果当前的用户看过了,那么就要删除这一条
+					if recentlyItem.UserData.Played == true {
+						// 先记录下来,然后再删除这一条
+						recItemExsitMap[recentlyItem.Id] = recentlyItem
+					}
+				}
+				recItemMap[recentlyItem.Id] = recentlyItem
+			}
+		}
+
+		for id := range recItemExsitMap {
+			delete(recItemMap, id)
+		}
 
-			recItems.Items = append(recItems.Items, tmpRecItems.Items...)
-			recItems.TotalRecordCount += tmpRecItems.TotalRecordCount
+		for _, item := range recItemMap {
+			recItems.Items = append(recItems.Items, item)
 		}
 
+		recItems.TotalRecordCount = len(recItemMap)
 	}
 
 	return recItems, nil

+ 17 - 9
internal/types/emby/type.go

@@ -6,15 +6,23 @@ import (
 )
 
 type EmbyRecentlyItems struct {
-	Items []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"`
-		SeriesName        string `json:"SeriesName,omitempty"`
-	} `json:"Items,omitempty"`
-	TotalRecordCount int `json:"TotalRecordCount,omitempty"`
+	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 {