fix empty channel_subs parsing

This commit is contained in:
simon 2023-05-02 12:42:35 +07:00
parent 2b66786728
commit b95a659396
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4

View File

@ -56,13 +56,14 @@ class YoutubeChannel(YouTubeItem):
def _process_youtube_meta(self):
"""extract relevant fields"""
self.youtube_meta["thumbnails"].reverse()
channel_subs = self.youtube_meta.get("channel_follower_count") or 0
self.json_data = {
"channel_active": True,
"channel_description": self.youtube_meta.get("description", False),
"channel_id": self.youtube_id,
"channel_last_refresh": int(datetime.now().timestamp()),
"channel_name": self.youtube_meta["uploader"],
"channel_subs": self.youtube_meta.get("channel_follower_count", 0),
"channel_subs": channel_subs,
"channel_subscribed": False,
"channel_tags": self._parse_tags(self.youtube_meta.get("tags")),
"channel_banner_url": self._get_banner_art(),
@ -96,7 +97,7 @@ class YoutubeChannel(YouTubeItem):
return i["url"]
if not i.get("width"):
continue
if i["width"] // i["height"] < 2:
if i["width"] // i["height"] < 2 and not i["width"] == i["height"]:
return i["url"]
return False
@ -164,6 +165,8 @@ class YoutubeChannel(YouTubeItem):
# add ingest pipeline
processors = []
for field, value in self.json_data.items():
if not value:
continue
line = {"set": {"field": "channel." + field, "value": value}}
processors.append(line)
data = {"description": self.youtube_id, "processors": processors}