From c57e6a49e8fd24a8a6c5fdf9a580eab5abc12466 Mon Sep 17 00:00:00 2001 From: Dreu LaVelle Date: Wed, 10 Jan 2024 00:46:16 -0500 Subject: [PATCH] Set stage for testing --- backend/program/scrapers/__init__.py | 2 +- backend/program/scrapers/torrentio.py | 2 +- backend/utils/default_settings.json | 2 +- backend/utils/parser.py | 17 +++++++++++------ 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/backend/program/scrapers/__init__.py b/backend/program/scrapers/__init__.py index ae87ac97..96caeb8f 100644 --- a/backend/program/scrapers/__init__.py +++ b/backend/program/scrapers/__init__.py @@ -19,7 +19,7 @@ def __init__(self, _): self.key = "scraping" self.initialized = False self.settings = ScrapingConfig(**settings.get(self.key)) - self.sm = ServiceManager(None, False, Torrentio, Orionoid, Jackett) + self.sm = ServiceManager(None, False, Torrentio) if not any(service.initialized for service in self.sm.services): logger.error( "You have no scraping services enabled, please enable at least one!" diff --git a/backend/program/scrapers/torrentio.py b/backend/program/scrapers/torrentio.py index d3ecc6f6..d16cae76 100644 --- a/backend/program/scrapers/torrentio.py +++ b/backend/program/scrapers/torrentio.py @@ -87,5 +87,5 @@ def api_scrape(self, item): } # TODO: Sort data using parser and user preferences if len(data) > 0: - return data + return parser.sort_and_filter_streams(data) return {} diff --git a/backend/utils/default_settings.json b/backend/utils/default_settings.json index cd650062..8efb6116 100644 --- a/backend/utils/default_settings.json +++ b/backend/utils/default_settings.json @@ -54,5 +54,5 @@ "highest_quality": false, "dual_audio": true, "av1_audio": false -} + } } diff --git a/backend/utils/parser.py b/backend/utils/parser.py index 4e452566..888fbae8 100644 --- a/backend/utils/parser.py +++ b/backend/utils/parser.py @@ -29,7 +29,7 @@ def __init__(self): "Nickelodeon", "YouTube Premium", "Disney Plus", "DisneyNOW", "HBO Max", "HBO", "Hulu Networks", "DC Universe", "Adult Swim", "Comedy Central", - "Peacock", "AMC", "PBS", "Crunchyroll"] + "Peacock", "AMC", "PBS", "Crunchyroll"] # Will probably be used later in `Versions` self.validate_settings() def validate_settings(self): @@ -108,7 +108,12 @@ def sort_dual_audio(self, string): """Check if content has dual audio.""" # TODO: This could use improvement.. untested. parse = self._parse(string) - return parse["audio"] == "Dual" or re.search(r"((dual.audio)|(english|eng)\W+(dub|audio))", string, flags=re.IGNORECASE) + if parse["audio"] == "Dual": + return True + elif re.search(r"((dual.audio)|(english|eng)\W+(dub|audio))", string, flags=re.IGNORECASE): + return True + else: + return False def remove_unwanted(self, string): """Filter out unwanted content.""" @@ -124,12 +129,12 @@ def sort_and_filter_streams(self, streams: dict) -> dict: # TODO: Sort scraped data based on user preferences # instead of scraping one item at a time. filtered_sorted_streams = [] - for info_hash, stream_details in streams.items(): - title = stream_details.get("name", "") + for info_hash, filename in streams.items(): + title = filename.get("name", "") if self.remove_unwanted(title): - filtered_sorted_streams.append((info_hash, stream_details, self.has_dual_audio(title))) + filtered_sorted_streams.append((info_hash, filename, self.has_dual_audio(title))) filtered_sorted_streams.sort(key=lambda x: x[2], reverse=True) - sorted_data = {info_hash: details for info_hash, details, _ in filtered_sorted_streams} + sorted_data = {info_hash: name for info_hash, name, _ in filtered_sorted_streams} return sorted_data def parse(self, string):