diff --git a/pyproject.toml b/pyproject.toml index cc2667e..b949c40 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "structables" -version = "0.2.1" +version = "0.2.2" authors = [ { name="Private.coffee Team", email="support@private.coffee" }, ] diff --git a/src/structables/main.py b/src/structables/main.py index 5c62f39..5262487 100644 --- a/src/structables/main.py +++ b/src/structables/main.py @@ -14,6 +14,7 @@ from urllib.error import HTTPError from traceback import print_exc from urllib.parse import urlparse from argparse import ArgumentParser +from typing import List from werkzeug.exceptions import BadRequest, abort, InternalServerError, NotFound from bs4 import BeautifulSoup @@ -59,6 +60,26 @@ invidious = None unsafe = False +def unslugify(slug: str) -> List[str]: + """Return a list of possible original titles for a slug. + + Args: + slug (str): The slug to unslugify. + + Returns: + List[str]: A list of possible original titles for the slug. + """ + + results = [] + + results.append(slug.replace("-", " ").title()) + + if "and" in slug: + results.append(results[0].replace("And", "&").title()) + + return results + + def projects_search( query="*", category="", @@ -402,9 +423,18 @@ def project_list(head, sort="", per_page=20): category = parts[1] channel = "" if parts[2] == "projects" else parts[2] - project_ibles, total = projects_search( - category=category, channel=channel, per_page=per_page, page=page - ) + channel_names = unslugify(channel) + + for channel_name in channel_names: + project_ibles, total = projects_search( + category=category, + channel=channel_name, + per_page=per_page, + page=page, + ) + + if project_ibles: + break elif "search" in path.split("/"): ibles = [] @@ -492,7 +522,7 @@ def route_sitemap(path=""): for li in main.select("ul.sitemap-listing li"): channel = li.a.text channel_link = li.a["href"] - + if channel_link.startswith("https://"): channel_link = f'/{"/".join(channel_link.split("/")[3:])}' @@ -1275,8 +1305,9 @@ def main(): app.run(port=args.port, host=args.listen_host, debug=debugmode) + if __name__ == "__main__": main() # Initialize data when the server starts -update_data() \ No newline at end of file +update_data()