add watched_date for _update_by_query mark as watched, #309

This commit is contained in:
simon 2022-10-22 22:00:35 +07:00
parent a5788117de
commit 0bba36cbc3
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
1 changed files with 10 additions and 2 deletions

View File

@ -57,6 +57,14 @@ class WatchState:
print(response)
raise ValueError("failed to mark video as watched")
def _get_source(self):
"""build source line for update_by_query script"""
source = [
"ctx._source.player['watched'] = true",
f"ctx._source.player['watched_date'] = {self.stamp}",
]
return "; ".join(source)
def mark_channel_watched(self):
"""change watched status of every video in channel"""
path = "ta_video/_update_by_query"
@ -67,7 +75,7 @@ class WatchState:
data = {
"query": {"bool": {"must": must_list}},
"script": {
"source": "ctx._source.player['watched'] = true",
"source": self._get_source(),
"lang": "painless",
},
}
@ -87,7 +95,7 @@ class WatchState:
data = {
"query": {"bool": {"must": must_list}},
"script": {
"source": "ctx._source.player['watched'] = true",
"source": self._get_source(),
"lang": "painless",
},
}