Skip to content
This repository was archived by the owner on Jun 14, 2026. It is now read-only.

PTP: fix poster rehosting - #1375

Merged
Audionut merged 2 commits into
masterfrom
ptp-poster
May 21, 2026
Merged

PTP: fix poster rehosting#1375
Audionut merged 2 commits into
masterfrom
ptp-poster

Conversation

@Audionut

@Audionut Audionut commented May 21, 2026

Copy link
Copy Markdown
Owner

fixes #1369

Summary by CodeRabbit

  • New Features
    • Enhanced PTP cover image rehosting: selects a target image host, avoids reuploading if already hosted there, and uploads posters to the selected host (falls back to original on failure).
    • Improved poster upload flow: string covers rehost immediately; when missing, users are prompted for a valid poster URL before upload.

Review Change Stack

@github-actions

Copy link
Copy Markdown

Thanks for taking the time to contribute to this project. Upload Assistant is currently in a complete rewrite, and no new development is being conducted on this python source at this time.

If you have come this far, please feel free to leave open, any pull requests regarding new sites being added to the source, as these can serve as the baseline for later conversion.

If your pull request relates to a critical bug, this will be addressed in this code base, and a new release published as needed.

If your pull request only addresses a quite minor bug, it is not likely to be addressed in this code base.

Details for the new code base will follow at a later date.

@coderabbitai

coderabbitai Bot commented May 21, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d8600cd9-9f1f-4a70-a8a9-30c0adc9d0c4

📥 Commits

Reviewing files that changed from the base of the PR and between f56cbc9 and b1384e2.

📒 Files selected for processing (1)
  • src/trackers/PTP.py

📝 Walkthrough

Walkthrough

PTP poster/cover rehosting was refactored to replace deprecated ptpimg-specific logic with configurable host selection. New helper methods determine the target imghost from metadata or config, detect existing host matches via alias rules, derive file extensions, and orchestrate rehosting. The cover acquisition flow now validates user-provided poster URLs and rehosts to the selected host.

Changes

Poster Rehosting Infrastructure and Integration

Layer / File(s) Summary
Poster rehosting helper methods
src/trackers/PTP.py
_selected_poster_host() determines target imghost from meta/config; _poster_already_on_selected_host() checks host alias matches; _poster_extension() derives file extension from URL/Content-Type; rehost_poster_to_selected_host() downloads to a temp file, temporarily overrides meta['imghost'], uploads via UploadScreensManager, and returns the uploaded URL (falls back on error).
Cover handling in upload form preparation
src/trackers/PTP.py
Cover acquisition now rehosts string cover values immediately; when cover is missing it prompts for a poster URL constrained to .jpg/.jpeg/.png/.webp, then rehosts to the selected host (removing prior ptpimg-specific logic).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Audionut/Upload-Assistant#1033: PTP changes to introduce configurable image host rehosting are directly related to PR #1033's work on approved_image_hosts and check_image_hosts validation for PTP poster/cover image providers.

Suggested reviewers

  • wastaken7

Poem

🐰 I nibbled code, traced each host and name,

Chose where covers land and kept their frame.
Temp files cradled pixels soft and bright,
Then uploads hopped to the configured light.
A tiny rabbit cheers your poster's flight! 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'PTP: fix poster rehosting' directly and concisely describes the main change: fixing the poster rehosting functionality in the PTP tracker class.
Linked Issues check ✅ Passed The PR addresses issue #1369 by implementing new poster rehosting logic that uses the configured imghost target instead of requiring ptpimg_api, eliminating the KeyError and restoring correct cover image rehosting functionality.
Out of Scope Changes check ✅ Passed All changes are focused on fixing the poster rehosting functionality as specified in issue #1369; no out-of-scope modifications were introduced.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ptp-poster

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/trackers/PTP.py`:
- Around line 480-482: _selected_poster_host currently returns any configured
imghost/default (e.g., img_host_1) but must be constrained to only PTP-approved
hosts; change _selected_poster_host to validate the chosen host against
self.approved_image_hosts and only return it when it is present in that
set/list, otherwise return an empty string (or None) so callers won’t rehost to
an unapproved host; apply the same membership check to the analogous poster-host
selection logic around the other block referenced (lines ~516-535) so both
places only accept hosts in self.approved_image_hosts.
- Around line 1578-1587: The code treats an empty string as a valid poster
string causing rehost_poster_to_selected_host to return '' and the subsequent
while cover is None loop never runs; update the branch around cover and the call
to rehost_poster_to_selected_host so blank/whitespace-only strings are treated
as missing: change the condition to check for a non-empty string (e.g., if
isinstance(cover, str) and cover.strip():) before calling
rehost_poster_to_selected_host(meta, cover), otherwise set cover = None so the
while cover is None loop will prompt for cover_input and
rehost_poster_to_selected_host is only called with a non-empty URL.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9b8670e5-d014-4436-b051-84343dbf978a

📥 Commits

Reviewing files that changed from the base of the PR and between 0f827e3 and f56cbc9.

📒 Files selected for processing (1)
  • src/trackers/PTP.py

Comment thread src/trackers/PTP.py
Comment on lines +480 to +482
def _selected_poster_host(self, meta: dict[str, Any]) -> str:
default_config = cast(dict[str, Any], self.config.get('DEFAULT', {}))
return str(meta.get('imghost') or default_config.get('img_host_1') or '').strip()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Constrain poster rehosting to PTP-approved hosts.

_selected_poster_host() accepts any global/default imghost, but this tracker only approves self.approved_image_hosts. With a config like img_host_1=imgbb, this path will upload the poster to an unsupported host and then submit that URL in image, which regresses uploads for users whose global host is not PTP-safe.

Suggested guard
 def _selected_poster_host(self, meta: dict[str, Any]) -> str:
     default_config = cast(dict[str, Any], self.config.get('DEFAULT', {}))
-    return str(meta.get('imghost') or default_config.get('img_host_1') or '').strip()
+    for candidate in (
+        str(meta.get('imghost') or '').strip().lower(),
+        str(default_config.get('img_host_1') or '').strip().lower(),
+    ):
+        if candidate in self.approved_image_hosts:
+            return candidate
+    return ''

Also applies to: 516-535

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/trackers/PTP.py` around lines 480 - 482, _selected_poster_host currently
returns any configured imghost/default (e.g., img_host_1) but must be
constrained to only PTP-approved hosts; change _selected_poster_host to validate
the chosen host against self.approved_image_hosts and only return it when it is
present in that set/list, otherwise return an empty string (or None) so callers
won’t rehost to an unapproved host; apply the same membership check to the
analogous poster-host selection logic around the other block referenced (lines
~516-535) so both places only accept hosts in self.approved_image_hosts.

Comment thread src/trackers/PTP.py Outdated
@Audionut
Audionut merged commit 3e39d5d into master May 21, 2026
5 checks passed
@Audionut
Audionut deleted the ptp-poster branch May 21, 2026 22:52
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PTP Cover rehost resulting in error

1 participant