Skip to content

Commit

Permalink
Set stage for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreu LaVelle committed Jan 10, 2024
1 parent ec7f550 commit c57e6a4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion backend/program/scrapers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!"
Expand Down
2 changes: 1 addition & 1 deletion backend/program/scrapers/torrentio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
2 changes: 1 addition & 1 deletion backend/utils/default_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@
"highest_quality": false,
"dual_audio": true,
"av1_audio": false
}
}
}
17 changes: 11 additions & 6 deletions backend/utils/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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."""
Expand All @@ -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):
Expand Down

0 comments on commit c57e6a4

Please sign in to comment.