Skip to content

Update Packt integration for current Packtpub API/login/claim flows - #213

Draft
luk6xff with Copilot wants to merge 12 commits into
masterfrom
copilot/update-packtpub-version
Draft

Update Packt integration for current Packtpub API/login/claim flows#213
luk6xff with Copilot wants to merge 12 commits into
masterfrom
copilot/update-packtpub-version

Conversation

Copilot AI commented Jun 7, 2026

Copy link
Copy Markdown

Packt’s legacy services.packtpub.com auth/claim flow no longer matches current Packt behavior, causing free-learning claim and owned-download workflows to fail. This change aligns authentication, offer discovery, entitlement retrieval, and download URL construction with current Packt endpoints/page structure.

  • API/client migration

    • Switched auth + session handling to current Packt web APIs:
      • POST /api/login
      • GET /api/entitlements/users/me/owned
      • POST /api/claim-free-learning/offers/{offer_id}
    • Updated product summary/download targets to subscription APIs.
    • Moved request timeout to per-request defaults in the API wrapper.
  • Free-learning claim path update

    • Replaced old offers endpoint logic with extraction of offerId and metaProductId from /free-learning page source.
    • Added parsing safeguards and clearer failure logging when offer metadata is missing.
    • Kept already-claimed handling intact via owned-product cross-check.
  • Owned library + pagination hardening

    • Reworked owned-products fetch to iterative pagination against the new entitlements endpoint.
    • Normalized product ID/title field fallbacks across response variants.
  • Download flow compatibility

    • Updated download URL strategy to current file-type mapping (pdf -> ebook, code -> code_bundle, video -> video_zip).
    • Added response-shape guards and unsupported-format validation.
  • Packaging/docs updates

    • Added curl-cffi==0.15.0 dependency for browser-like session behavior.
    • Bumped package metadata version and tarball URL.
    • Updated README free-learning URL to current path.
# New download mapping used by downloader
PACKT_FILE_FORMAT_MAPPING = {
    "pdf": "ebook",
    "epub": "epub",
    "mobi": "mobi",
    "code": "code_bundle",
    "video": "video_zip",
}

Copilot AI 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.

Pull request overview

This PR updates the Packt integration to match Packt’s current web/API authentication, free-learning claim flow, owned-entitlements retrieval, and download URL patterns so the CLI can claim and download content again.

Changes:

  • Migrates authentication/session handling to Packt’s current /api/login flow using curl-cffi for browser impersonation.
  • Updates free-learning claiming to parse offerId/metaProductId from the /free-learning page and claim via the new endpoint.
  • Updates owned library pagination and download URL construction (including file-type mapping), plus bumps package version/deps and README URL.

Reviewed changes

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

Show a summary per file
File Description
setup.py Bumps package version/url and adds curl-cffi dependency required for the new session behavior.
README.md Updates the documented Free Learning URL to the current Packt path.
packt/api.py Switches to cookie/session-based auth via curl_cffi.requests and adds per-request timeouts.
packt/claimer.py Reworks owned-products pagination and updates free-learning offer discovery + claim call.
packt/downloader.py Adds file-type mapping and updates download URL building and fetch logic.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packt/api.py Outdated
Comment thread packt/claimer.py
Comment thread packt/claimer.py Outdated
luk6xff and others added 3 commits June 11, 2026 00:12
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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