From 93cc0d954c5a36fc42f13d29799090196b082f29 Mon Sep 17 00:00:00 2001 From: "Jakob L. Kreuze" Date: Sun, 16 Jun 2024 15:33:35 -0400 Subject: Fetch video metadata concurrently --- addon.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/addon.py b/addon.py index 3343f7b..c173319 100644 --- a/addon.py +++ b/addon.py @@ -17,6 +17,7 @@ Video plugin for animations posted to Newgrounds. """ +import concurrent.futures import os import sys from urllib.parse import urlencode, parse_qsl @@ -115,7 +116,6 @@ def get_video_url(url): """ TODO """ - xbmc.log("Getting info for {}".format(url), 2) html = requests.get(url).text soup = BeautifulSoup(html, "html.parser") video_id = soup.find("meta", property="og:url")["content"].strip( @@ -141,7 +141,6 @@ def get_addon_video_info(url): """ Scrape metadata from `url`. """ - xbmc.log("Getting info for {}".format(url), 2) html = requests.get(url).text soup = BeautifulSoup(html, "html.parser") return { @@ -192,10 +191,14 @@ def list_videos(genre, category=0, offset=0): :type genre: str :type offset: int """ - videos = [ - get_addon_video_info(url) - for url in get_video_urls(category=category, interval="all", offset=offset) - ] + urls = get_video_urls(category=category, interval="all", offset=offset) + videos = [] + with concurrent.futures.ThreadPoolExecutor(max_workers=20) as executor: + # Start the load operations and mark each future with its URL + future_to_url = {executor.submit(get_addon_video_info, url): url for url in urls} + for future in concurrent.futures.as_completed(future_to_url): + url = future_to_url[future] + videos.append(future.result()) xbmcplugin.setPluginCategory(HANDLE, "Featured") # , genre_info['genre']) xbmcplugin.setContent(HANDLE, "movies") # Get the list of videos in the category. -- cgit v1.3