Skip to content

fix(site): fix broken subTitle selectors for HDArea and PTHome - #1315

Merged
Rhilip merged 3 commits into
masterfrom
copilot/fix-subtitle-selector-hdarea-pthome
Jun 18, 2026
Merged

fix(site): fix broken subTitle selectors for HDArea and PTHome#1315
Rhilip merged 3 commits into
masterfrom
copilot/fix-subtitle-selector-hdarea-pthome

Conversation

Copilot AI commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Both HDArea and PTHome have non-standard subtitle HTML structures that break the default NexusPHP subTitleRemoveExtraElement handler (which splits parent innerHTML on <br> and strips a, span, img).

HDArea

Subtitle lives in div:nth-child(2) — a sibling div of the title div — not after a <br> tag. The <br>-split yields nothing.

// Find the title's enclosing td > div, then read the next sibling div
elementProcess: (element: HTMLElement) => {
  const titleDiv = element.closest("td > div");
  const subtitleEl = titleDiv?.nextElementSibling;
  if (subtitleEl instanceof HTMLElement && subtitleEl.tagName === "DIV") {
    return subtitleEl.textContent?.trim() ?? "";
  }
  return "";
},

PTHome

Subtitle is wrapped in <span style="padding: 2px;line-height: 20px;">…</span> after <br>. The default removeSelectors: ["a, span, img"] removes the span entirely, taking the subtitle text with it.

Fix: override subTitle with subTitleRemoveExtraElement(["a", "img"], true) — drops anchors/images but leaves the subtitle span for extractContent() to unwrap.

Summary by Sourcery

Fix subtitle extraction for HDArea and PTHome torrent search results to align with their non-standard HTML structures.

Bug Fixes:

  • Add a custom subtitle selector and sibling-div extraction for HDArea search rows so subtitles are correctly parsed.
  • Override the default NexusPHP subtitle handler for PTHome to preserve span-wrapped subtitles while still stripping links and images.

Enhancements:

  • Apply minor code style cleanup in HDArea user info processing and upload parsing methods.

Copilot AI requested review from Copilot and removed request for Copilot June 14, 2026 11:23
HDArea: subtitle is in a sibling div (div:nth-child(2)) of the title div,
not after a <br> tag. Added a custom elementProcess that uses
element.closest("td > div") to find the title div and reads the
next sibling div as the subtitle.

PTHome: subtitle is wrapped in a <span> element after <br>. The default
NexusPHP handler removes all span elements which strips the subtitle
content. Changed removeSelectors to ["a", "img"] so that extractContent()
can still retrieve the text from the subtitle span.
Copilot AI requested review from Copilot and removed request for Copilot June 14, 2026 11:31
Replace `as HTMLElement` type assertion with `instanceof HTMLElement`
check for better type safety when reading the subtitle sibling div.
Copilot AI requested review from Copilot and removed request for Copilot June 14, 2026 11:33
Copilot AI changed the title [WIP] Fix subtitle selector for HDArea and PTHome fix(site): fix broken subTitle selectors for HDArea and PTHome Jun 14, 2026
Copilot AI requested a review from Rhilip June 14, 2026 11:33
@Rhilip
Rhilip marked this pull request as ready for review June 18, 2026 09:45
Copilot AI review requested due to automatic review settings June 18, 2026 09:45
@Rhilip
Rhilip merged commit b22cd19 into master Jun 18, 2026
6 checks passed
@Rhilip
Rhilip deleted the copilot/fix-subtitle-selector-hdarea-pthome branch June 18, 2026 09:45
@sourcery-ai

sourcery-ai Bot commented Jun 18, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adjusts site-specific subtitle extraction for HDArea and PTHome to handle their non-standard HTML structures, and performs minor formatting changes in HDArea metadata processing methods.

File-Level Changes

Change Details Files
Add a custom subtitle selector/processor for HDArea to extract subtitles from a sibling div instead of relying on the default
-based handler.
  • Introduce a search.subTitle configuration overriding the default behavior for HDArea.
  • Use CSS selectors targeting the existing title anchors to locate the correct title container for subtitle extraction.
  • Implement an elementProcess function that finds the enclosing td > div for the title, then reads text from its next sibling div, returning trimmed subtitle text or an empty string when not found.
src/packages/site/definitions/hdarea.ts
Override PTHome search subtitle handling to preserve span-wrapped subtitles while still stripping anchors and images.
  • Extend imports to bring in subTitleRemoveExtraElement from the NexusPHP schema utilities.
  • Add a search override for PTHome that customizes the subTitle selector configuration while spreading the base SchemaMetadata.search.
  • Configure subTitle.elementProcess to use subTitleRemoveExtraElement(["a", "img"], true) so only anchors and images are removed, allowing span-wrapped subtitle text to be extracted.
src/packages/site/definitions/pthome.ts
Apply minor code-style/formatting adjustments in HDArea metadata processing logic.
  • Inline the conditional mapping expression in userInfo.process to a single line for readability/consistency.
  • Inline the parseUserInfoForUploads method signature into a single line without changing its logic.
src/packages/site/definitions/hdarea.ts

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've reviewed this pull request using the Sourcery rules engine

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes subtitle extraction for two NexusPHP-based sites whose HTML structures don’t work with the default subTitleRemoveExtraElement() behavior, improving search result parsing consistency across the extension’s site modules.

Changes:

  • PTHome: override search.selectors.subTitle to avoid removing <span> so subtitle text isn’t stripped.
  • HDArea: override search.selectors.subTitle.elementProcess to read subtitle from a sibling <div> rather than relying on <br> splitting.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/packages/site/definitions/pthome.ts Adds a site-specific subTitle handler to preserve subtitle text wrapped in a <span>.
src/packages/site/definitions/hdarea.ts Adds a site-specific subTitle handler that reads subtitle from the next sibling <div> of the title container.

Comment on lines +125 to +137
subTitle: {
// PTHome wraps its subtitle in a <span> element. The default NexusPHP handler removes
// all span elements, which strips the subtitle text. We only remove <a> and <img>
// so that extractContent() can still get the text content from the subtitle span.
text: "",
selector: [
"a[href^='details.php?id='][title]:has(b)",
"a[href*='details.php?id='][href*='hit']",
"a[href*='hit'][title]",
"a[href*='hit']:has(b)",
],
elementProcess: subTitleRemoveExtraElement(["a", "img"], true),
},
Comment on lines +146 to +164
subTitle: {
text: "",
selector: [
"a[href^='details.php?id='][title]:has(b)",
"a[href*='details.php?id='][href*='hit']",
"a[href*='hit'][title]",
"a[href*='hit']:has(b)",
],
// HDArea places the subtitle in a sibling div of the title div,
// rather than after a <br> tag, so we look at the next sibling element.
elementProcess: (element: HTMLElement) => {
const titleDiv = element.closest("td > div");
const subtitleEl = titleDiv?.nextElementSibling;
if (subtitleEl instanceof HTMLElement && subtitleEl.tagName === "DIV") {
return subtitleEl.textContent?.trim() ?? "";
}
return "";
},
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants