mirror of
https://github.com/tubearchivist/tubearchivist.git
synced 2025-03-16 19:00:12 +00:00
fix progress inconsistency+
This commit is contained in:
parent
847764e440
commit
3aa41232db
@ -6,15 +6,17 @@ functionality:
|
||||
from datetime import datetime
|
||||
|
||||
from common.src.es_connect import ElasticWrap
|
||||
from common.src.ta_redis import RedisArchivist
|
||||
from common.src.urlparser import Parser
|
||||
|
||||
|
||||
class WatchState:
|
||||
"""handle watched checkbox for videos and channels"""
|
||||
|
||||
def __init__(self, youtube_id, is_watched):
|
||||
def __init__(self, youtube_id: str, is_watched: bool, user_id: int):
|
||||
self.youtube_id = youtube_id
|
||||
self.is_watched = is_watched
|
||||
self.user_id = user_id
|
||||
self.stamp = int(datetime.now().timestamp())
|
||||
self.pipeline = f"_ingest/pipeline/watch_{youtube_id}"
|
||||
|
||||
@ -50,6 +52,8 @@ class WatchState:
|
||||
}
|
||||
}
|
||||
response, status_code = ElasticWrap(path).post(data=data)
|
||||
key = f"{self.user_id}:progress:{self.youtube_id}"
|
||||
RedisArchivist().del_message(key)
|
||||
if status_code != 200:
|
||||
print(response)
|
||||
raise ValueError("failed to mark video as watched")
|
||||
|
@ -75,7 +75,7 @@ class WatchedView(ApiBaseView):
|
||||
message = {"message": "missing id or is_watched"}
|
||||
return Response(message, status=400)
|
||||
|
||||
WatchState(youtube_id, is_watched).change()
|
||||
WatchState(youtube_id, is_watched, request.user.id).change()
|
||||
return Response({"message": "success"}, status=200)
|
||||
|
||||
|
||||
|
@ -126,10 +126,9 @@ class VideoProgressView(ApiBaseView):
|
||||
current_progress = self.response["data"]["player"]
|
||||
|
||||
current_progress.update({"position": position, "youtube_id": video_id})
|
||||
watched = self._check_watched_state(video_id, current_progress)
|
||||
watched = self._check_watched(request, video_id, current_progress)
|
||||
if watched:
|
||||
redis_con.del_message(key)
|
||||
expire = 360
|
||||
expire = 60
|
||||
else:
|
||||
expire = False
|
||||
|
||||
@ -138,7 +137,7 @@ class VideoProgressView(ApiBaseView):
|
||||
|
||||
return Response(current_progress)
|
||||
|
||||
def _check_watched_state(self, video_id, current_progress) -> bool:
|
||||
def _check_watched(self, request, video_id, current_progress) -> bool:
|
||||
"""check watched state"""
|
||||
if current_progress["watched"]:
|
||||
return True
|
||||
@ -147,7 +146,7 @@ class VideoProgressView(ApiBaseView):
|
||||
current_progress["duration"], current_progress["position"]
|
||||
)
|
||||
if watched:
|
||||
WatchState(video_id, watched).change()
|
||||
WatchState(video_id, watched, request.user.id).change()
|
||||
|
||||
return watched
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user