Watched state improvement, #build

Changed:
- Fixed watched state date tracking
- Fixed channel fallback extraction error handling
This commit is contained in:
Simon 2025-05-13 06:41:01 +07:00
commit 56f5c6bc4b
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
6 changed files with 28 additions and 12 deletions

View File

@ -5,6 +5,13 @@
# Docker # Docker
.docker .docker
# Backend development
backend/static
backend/staticfiles
# Frontend development
frontend/node_modules
# Python # Python
tubearchivist/__pycache__/ tubearchivist/__pycache__/
tubearchivist/*/__pycache__/ tubearchivist/*/__pycache__/

1
.gitignore vendored
View File

@ -4,6 +4,7 @@ __pycache__
# django testing # django testing
backend/static backend/static
backend/staticfiles
backend/.env backend/.env
# vscode custom conf # vscode custom conf

View File

@ -56,12 +56,13 @@ class YoutubeChannel(YouTubeItem):
def process_youtube_meta(self): def process_youtube_meta(self):
"""extract relevant fields""" """extract relevant fields"""
self.youtube_meta["thumbnails"].reverse() self.youtube_meta["thumbnails"].reverse()
channel_name = self.youtube_meta["uploader"] or self.youtube_meta["id"]
self.json_data = { self.json_data = {
"channel_active": True, "channel_active": True,
"channel_description": self.youtube_meta.get("description", ""), "channel_description": self.youtube_meta.get("description", ""),
"channel_id": self.youtube_id, "channel_id": self.youtube_id,
"channel_last_refresh": int(datetime.now().timestamp()), "channel_last_refresh": int(datetime.now().timestamp()),
"channel_name": self.youtube_meta["uploader"], "channel_name": channel_name,
"channel_subs": self.youtube_meta.get("channel_follower_count", 0), "channel_subs": self.youtube_meta.get("channel_follower_count", 0),
"channel_subscribed": False, "channel_subscribed": False,
"channel_tags": self.youtube_meta.get("tags", []), "channel_tags": self.youtube_meta.get("tags", []),
@ -157,8 +158,18 @@ class YoutubeChannel(YouTubeItem):
# add ingest pipeline # add ingest pipeline
processors = [] processors = []
for field, value in self.json_data.items(): for field, value in self.json_data.items():
line = {"set": {"field": "channel." + field, "value": value}} if value is None:
line = {
"script": {
"lang": "painless",
"source": f"ctx['{field}'] = null;",
}
}
else:
line = {"set": {"field": "channel." + field, "value": value}}
processors.append(line) processors.append(line)
data = {"description": self.youtube_id, "processors": processors} data = {"description": self.youtube_id, "processors": processors}
ingest_path = f"_ingest/pipeline/{self.youtube_id}" ingest_path = f"_ingest/pipeline/{self.youtube_id}"
_, _ = ElasticWrap(ingest_path).put(data) _, _ = ElasticWrap(ingest_path).put(data)

View File

@ -43,14 +43,9 @@ class WatchState:
def change_vid_state(self): def change_vid_state(self):
"""change watched state of video""" """change watched state of video"""
path = f"ta_video/_update/{self.youtube_id}" path = f"ta_video/_update/{self.youtube_id}"
data = { data = {"doc": {"player": {"watched": self.is_watched}}}
"doc": { if self.is_watched:
"player": { data["doc"]["player"]["watched_date"] = self.stamp
"watched": self.is_watched,
"watched_date": self.stamp,
}
}
}
response, status_code = ElasticWrap(path).post(data=data) response, status_code = ElasticWrap(path).post(data=data)
key = f"{self.user_id}:progress:{self.youtube_id}" key = f"{self.user_id}:progress:{self.youtube_id}"
RedisArchivist().del_message(key) RedisArchivist().del_message(key)

View File

@ -49,7 +49,9 @@ const ChannelList = ({ channelList, refreshChannelList }: ChannelListProps) => {
<h3> <h3>
<Link to={Routes.Channel(channel.channel_id)}>{channel.channel_name}</Link> <Link to={Routes.Channel(channel.channel_id)}>{channel.channel_name}</Link>
</h3> </h3>
<FormattedNumber text="Subscribers:" number={channel.channel_subs} /> {channel.channel_subs !== null && (
<FormattedNumber text="Subscribers:" number={channel.channel_subs} />
)}
</div> </div>
</div> </div>
<div className="info-box-item"> <div className="info-box-item">

View File

@ -38,7 +38,7 @@ const ChannelOverview = ({
<Link to={Routes.ChannelVideo(channelId)}>{channelname}</Link> <Link to={Routes.ChannelVideo(channelId)}>{channelname}</Link>
</h3> </h3>
<FormattedNumber text="Subscribers:" number={channelSubs} /> {channelSubs !== null && <FormattedNumber text="Subscribers:" number={channelSubs} />}
{isAdmin && ( {isAdmin && (
<> <>