import feedparser import wx from Channel import Channel from Items import Item from Utils import (add_video, get_default_logo, get_latest_video_timestamp, hash_string, make_bitmap_from_url, video_exists) #from youtubesearchpython.search import VideosSearch class YouTube(Channel): def __init__(self, channel_id: str, name: str) -> None: self.m_name = name rss_url = 'https://www.youtube.com/feeds/videos.xml?channel_id={}'.format( channel_id) self.m_logo = get_default_logo('YouTube') self.m_items: list[Item] = list() super().__init__(channel_id, 'YouTube', rss_url, self.m_logo, name) def parse_feed(self) -> None: feed = feedparser.parse(self.get_feed()) entries = feed['entries'] for entry in entries: video_id = hash_string(entry['id']) if video_exists(video_id, self.m_id): continue title = str(entry['title']) thumbnail_link = str(entry['media_thumbnail'][0]['url']) description = str(entry['description']) #video_search = VideosSearch(entry['id'], limit = 1).result()['result'][0] resolved_link = entry['link'] print(resolved_link) published_parsed = entry['published_parsed'] if not resolved_link: continue thumbnail = make_bitmap_from_url(thumbnail_link, wx.Size(self.m_screen_width, 150)) item = Item(description, resolved_link, self.m_provider_name, published_parsed, thumbnail, title) self.m_items.append(item) add_video(video_id, self.m_id, self.m_provider_name, description, resolved_link, published_parsed, thumbnail, title, 0)