From 0bba36cbc33dad41a653509a022ad92f8ac5aa82 Mon Sep 17 00:00:00 2001 From: simon Date: Sat, 22 Oct 2022 22:00:35 +0700 Subject: [PATCH] add watched_date for _update_by_query mark as watched, #309 --- tubearchivist/home/src/frontend/watched.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tubearchivist/home/src/frontend/watched.py b/tubearchivist/home/src/frontend/watched.py index 85aa1abe..88f694f8 100644 --- a/tubearchivist/home/src/frontend/watched.py +++ b/tubearchivist/home/src/frontend/watched.py @@ -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", }, }