diff --git a/tubearchivist/home/src/index.py b/tubearchivist/home/src/index.py index b7d0452..d3f51d3 100644 --- a/tubearchivist/home/src/index.py +++ b/tubearchivist/home/src/index.py @@ -384,6 +384,16 @@ class WatchState: print(f"marked {self.youtube_id} as watched") + def mark_as_unwatched(self): + """revert watched state to false""" + url_type = self.dedect_type() + if url_type == "video": + self.mark_vid_watched(revert=True) + elif url_type == "channel": + self.mark_channel_watched(revert=True) + + print(f"revert {self.youtube_id} as unwatched") + def dedect_type(self): """find youtube id type""" url_process = process_url_list([self.youtube_id]) @@ -391,18 +401,21 @@ class WatchState: return url_type - def mark_vid_watched(self): + def mark_vid_watched(self, revert=False): """change watched status of single video""" url = self.ES_URL + "/ta_video/_update/" + self.youtube_id data = { "doc": {"player": {"watched": True, "watched_date": self.stamp}} } + if revert: + data["doc"]["player"]["watched"] = False + payload = json.dumps(data) request = requests.post(url, data=payload, headers=self.HEADERS) if not request.ok: print(request.text) - def mark_channel_watched(self): + def mark_channel_watched(self, revert=False): """change watched status of every video in channel""" es_url = self.ES_URL headers = self.HEADERS @@ -415,6 +428,9 @@ class WatchState: {"set": {"field": "player.watched_date", "value": self.stamp}}, ], } + if revert: + data["processors"][0]["set"]["value"] = False + payload = json.dumps(data) url = f"{es_url}/_ingest/pipeline/{youtube_id}" request = requests.put(url, data=payload, headers=headers) diff --git a/tubearchivist/home/templates/home/channel_id.html b/tubearchivist/home/templates/home/channel_id.html index 4255007..d17423c 100644 --- a/tubearchivist/home/templates/home/channel_id.html +++ b/tubearchivist/home/templates/home/channel_id.html @@ -84,7 +84,7 @@
Last refreshed: {{ video.vid_last_refresh }}
Watched:
{% if video.player.watched %}
-
+
{% else %}
{% endif %}
diff --git a/tubearchivist/home/views.py b/tubearchivist/home/views.py
index 9e20a45..afa8098 100644
--- a/tubearchivist/home/views.py
+++ b/tubearchivist/home/views.py
@@ -489,6 +489,7 @@ class PostData:
"""map dict key and return function to execute"""
exec_map = {
"watched": self.watched,
+ "un_watched": self.un_watched,
"change_view": self.change_view,
"rescan_pending": self.rescan_pending,
"ignore": self.ignore,
@@ -515,6 +516,11 @@ class PostData:
WatchState(self.exec_val).mark_as_watched()
return {"success": True}
+ def un_watched(self):
+ """mark as unwatched"""
+ WatchState(self.exec_val).mark_as_unwatched()
+ return {"success": True}
+
def change_view(self):
"""process view changes in home, channel, and downloads"""
origin, new_view = self.exec_val.split(":")
diff --git a/tubearchivist/static/css/style.css b/tubearchivist/static/css/style.css
index 3a48a5c..af78eef 100644
--- a/tubearchivist/static/css/style.css
+++ b/tubearchivist/static/css/style.css
@@ -440,15 +440,12 @@ button:hover {
}
.unseen-icon,
+.seen-icon,
.close-button {
cursor: pointer;
filter: var(--img-filter);
}
-.seen-icon {
- filter: var(--img-filter);
-}
-
.video-more {
text-decoration: underline;
text-align: right;
diff --git a/tubearchivist/static/script.js b/tubearchivist/static/script.js
index 550e11f..8b916a6 100644
--- a/tubearchivist/static/script.js
+++ b/tubearchivist/static/script.js
@@ -15,10 +15,25 @@ function isWatched(youtube_id) {
seenIcon.setAttribute('src', "/static/img/icon-seen.svg");
seenIcon.setAttribute('alt', 'seen-icon');
seenIcon.setAttribute('id', youtube_id);
+ seenIcon.setAttribute('title', "Mark as unwatched");
+ seenIcon.setAttribute('onclick', "isUnwatched(this.id)");
seenIcon.classList = 'seen-icon';
document.getElementById(youtube_id).replaceWith(seenIcon);
}
+function isUnwatched(youtube_id) {
+ var payload = JSON.stringify({'un_watched': youtube_id});
+ sendPost(payload);
+ var unseenIcon = document.createElement('img');
+ unseenIcon.setAttribute('src', "/static/img/icon-unseen.svg");
+ unseenIcon.setAttribute('alt', 'unseen-icon');
+ unseenIcon.setAttribute('id', youtube_id);
+ unseenIcon.setAttribute('title', "Mark as watched");
+ unseenIcon.setAttribute('onclick', "isWatched(this.id)");
+ unseenIcon.classList = 'unseen-icon';
+ document.getElementById(youtube_id).replaceWith(unseenIcon);
+}
+
function unsubscribe(channel_id) {
var payload = JSON.stringify({'unsubscribe': channel_id});
sendPost(payload);