handle is_watched state in backend

This commit is contained in:
Simon
2025-01-30 22:02:48 +07:00
parent 43bd5359ba
commit 87b65caf8a
4 changed files with 72 additions and 8 deletions

View File

@@ -275,3 +275,19 @@ def get_channel_overwrites() -> dict[str, dict[str, Any]]:
overwrites = {i["channel_id"]: i["channel_overwrites"] for i in result}
return overwrites
def calc_is_watched(duration: float, position: float) -> bool:
"""considered watched based on duration position"""
if not duration or duration <= 0:
return False
if duration < 60:
threshold = 0.5
elif duration > 900:
threshold = 1 - (180 / duration)
else:
threshold = 0.9
return position >= duration * threshold

View File

@@ -45,7 +45,11 @@ class SearchProcess:
if not all_positions:
return None
pos_index = {i["youtube_id"]: i["position"] for i in all_positions}
pos_index = {
i["youtube_id"]: i["position"]
for i in all_positions
if not i.get("watched")
}
return pos_index
def _process_result(self, result):