diff --git a/CHANGELOG.md b/CHANGELOG.md index 7aea9ac..b9e2480 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## v3.12.2 + +### Fixes + +* Fix selectors for submission folder (gallery/scraps), next submission, and previous submission in submission pages + that did not work with the "minigallery" navigation turned on + * Fix issue [#27](https://github.com/FurryCoders/FAAPI/issues/27) + ## v3.12.1 ### Fixes diff --git a/faapi/__version__.py b/faapi/__version__.py index 555cdb2..e2257b3 100644 --- a/faapi/__version__.py +++ b/faapi/__version__.py @@ -1 +1 @@ -__version__ = "3.12.1" +__version__ = "3.12.2" diff --git a/faapi/parse.py b/faapi/parse.py index 6a41653..f644bb4 100644 --- a/faapi/parse.py +++ b/faapi/parse.py @@ -524,11 +524,20 @@ def parse_submission_page(sub_page: BeautifulSoup) -> dict[str, Any]: tag_category2: Optional[Tag] = tag_info.select_one("span.type-name") tag_species: Optional[Tag] = tag_info.select("span")[bool(tag_category1) + bool(tag_category2)] tag_description: Optional[Tag] = sub_page.select_one("div.submission-description") - tag_folder: Optional[Tag] = sub_page.select_one("a.button[href^='/scraps/'],a.button[href^='/gallery/']") + tag_folder: Optional[Tag] = ( + sub_page.select_one('.favorite-nav a[href^="/scraps/"], .favorite-nav a[href^="/gallery/"]') + or sub_page.select_one('#minigallery a[href^="/scraps/"], #minigallery a[href^="/gallery/"]') + ) tag_file_url: Optional[Tag] = sub_page.select_one("div.download a") tag_thumbnail_url: Optional[Tag] = sub_page.select_one("img#submissionImg") - tag_prev: Optional[Tag] = sub_page.select_one("div.submission-content div.favorite-nav a:nth-child(1)") - tag_next: Optional[Tag] = sub_page.select_one("div.submission-content div.favorite-nav a:last-child") + tag_prev: Optional[Tag] = ( + sub_page.select_one('div.submission-content div.favorite-nav a:nth-child(1)[href^="/view/"]') + or sub_page.select_one(".minigallery-container > div:nth-child(1) figure:last-child a") + ) + tag_next: Optional[Tag] = ( + sub_page.select_one('div.submission-content div.favorite-nav a:last-child[href^="/view/"]') + or sub_page.select_one(".minigallery-container > div:last-child figure:nth-child(1) a") + ) assert tag_id is not None, _raise_exception(ParsingError("Missing id tag")) assert tag_title is not None, _raise_exception(ParsingError("Missing title tag")) @@ -581,10 +590,10 @@ def parse_submission_page(sub_page: BeautifulSoup) -> dict[str, Any]: if thumbnail_url else "" prev_sub: Optional[int] = int( get_attr(tag_prev, "href").strip("/").split("/")[-1] - ) if tag_prev and tag_prev.text.lower() == "newer" else None + ) if tag_prev else None next_sub: Optional[int] = int( get_attr(tag_next, "href").strip("/").split("/")[-1] - ) if tag_next and tag_next.text.lower() == "older" else None + ) if tag_next else None fav_link: Optional[str] = f"{root}{href}" if (href := get_attr(tag_fav, "href")).startswith("/fav/") else None unfav_link: Optional[str] = f"{root}{href}" if (href := get_attr(tag_fav, "href")).startswith("/unfav/") else None user_folders: list[tuple[str, str, str]] = [] diff --git a/pyproject.toml b/pyproject.toml index 0cbefd4..b36e43d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "faapi" -version = "3.12.1" +version = "3.12.2" description = "Python module to implement API-like functionality for the FurAffinity.net website." authors = ["Matteo Campinoti "] license = "EUPL-1.2" diff --git a/tests/test_faapi.py b/tests/test_faapi.py index 23c411c..c1f3d71 100644 --- a/tests/test_faapi.py +++ b/tests/test_faapi.py @@ -47,9 +47,11 @@ def submission_test_data() -> dict: def journal_test_data() -> dict: return load((__root__ / "test_journal.json").open()) + def compare_dates(a: datetime, b: datetime, max_variance: int) -> bool: return (b - timedelta(hours=max_variance)) <= a <= (b + timedelta(hours=max_variance)) + def remove_user_icons(html: str) -> str: return sub(r"a\.furaffinity\.net/\d{8}/[^. ]+.gif", "", html) @@ -139,7 +141,8 @@ def test_submission(cookies: RequestsCookieJar, submission_test_data: dict): assert submission.id == submission_dict["id"] == submission_test_data["id"] assert submission.title == submission_dict["title"] == submission_test_data["title"] - assert submission.author.name.lower() == submission_dict["author"]["name"].lower() == submission_test_data["author"]["name"].lower() + assert submission.author.name.lower() == submission_dict["author"]["name"].lower() == \ + submission_test_data["author"]["name"].lower() assert submission.author.avatar_url == submission_dict["author"]["avatar_url"] != "" assert compare_dates(submission.date, submission_dict["date"], 1) assert compare_dates(submission.date, datetime.fromisoformat(submission_test_data["date"]), 1) @@ -156,6 +159,11 @@ def test_submission(cookies: RequestsCookieJar, submission_test_data: dict): assert submission.type == submission_dict["type"] == submission_test_data["type"] assert submission.mentions == submission_dict["mentions"] == submission_test_data["mentions"] assert submission.folder == submission_dict["folder"] == submission_test_data["folder"] + assert ( + [f._asdict() for f in submission.user_folders] == + submission_dict["user_folders"] == + submission_test_data["user_folders"] + ) assert submission.file_url == submission_dict["file_url"] != "" assert submission.thumbnail_url == submission_dict["thumbnail_url"] != "" assert submission.prev == submission_dict["prev"] == submission_test_data["prev"] @@ -199,7 +207,8 @@ def test_journal(cookies: RequestsCookieJar, journal_test_data: dict): assert journal.id == journal_dict["id"] == journal_test_data["id"] assert journal.title == journal_dict["title"] == journal_test_data["title"] - assert journal.author.name.lower() == journal_dict["author"]["name"].lower() == journal_test_data["author"]["name"].lower() + assert journal.author.name.lower() == journal_dict["author"]["name"].lower() == journal_test_data["author"][ + "name"].lower() assert compare_dates(journal.author.join_date, journal_dict["author"]["join_date"], 1) assert compare_dates(journal.author.join_date, datetime.fromisoformat(journal_test_data["author"]["join_date"]), 1) assert journal.author.avatar_url == journal_dict["author"]["avatar_url"] != "" diff --git a/tests/test_parse.py b/tests/test_parse.py index 441727f..6b933b4 100644 --- a/tests/test_parse.py +++ b/tests/test_parse.py @@ -138,7 +138,7 @@ def test_parse_submission_page(session: Session, submission_test_data: dict): assert result["type"] == submission_test_data["type"] assert result["mentions"] == submission_test_data["mentions"] assert result["folder"] == submission_test_data["folder"] - assert [list(f) for f in result["user_folders"]] == submission_test_data["user_folders_tuples"] + assert result["user_folders"] == [tuple(f.values()) for f in submission_test_data["user_folders"]] assert result["file_url"] != "" assert result["thumbnail_url"] != "" assert result["prev"] == submission_test_data["prev"]