Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add direct book providers #6585

Merged
merged 23 commits into from
Jul 24, 2024

Conversation

cdrini
Copy link
Collaborator

@cdrini cdrini commented May 25, 2022

Closes #9419

Test with
https://openlibrary.org/books/OL38222427M.json

What we want is:

On https://github.com/internetarchive/openlibrary/blob/master/openlibrary/plugins/upstream/borrow.py#L128C9-L128C40

edition = web.ctx.site.get(key)
provider = get_book_provider(edition)
if provider and provider.ebook_access(edition) == "public":
    raise web.seeother(provider.read_url)

Technical

Testing

Screenshot

Stakeholders

@cdrini cdrini force-pushed the feature/direct-book-provider branch 2 times, most recently from e918d2d to 14f9ffe Compare June 1, 2022 22:15
@cdrini cdrini force-pushed the feature/direct-book-provider branch 2 times, most recently from b27564b to ded8118 Compare October 17, 2022 20:23
Comment on lines 216 to 229
if edition.providers:
return [EbookProvider.from_json(dict(p)) for p in edition.providers]
else:
return []
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if edition.providers:
return [EbookProvider.from_json(dict(p)) for p in edition.providers]
else:
return []
return [EbookProvider.from_json(dict(p)) for p in edition.providers or []]

@cdrini cdrini force-pushed the feature/direct-book-provider branch 3 times, most recently from fd52403 to 58fbdc1 Compare November 24, 2022 22:44
@cdrini cdrini added the State: Blocked Work has stopped, waiting for something (Info, Dependent fix, etc. See comments). [managed] label Nov 24, 2022
@cdrini cdrini force-pushed the feature/direct-book-provider branch 3 times, most recently from cde216c to c287ad7 Compare February 15, 2023 21:19
@mekarpeles mekarpeles added Needs: Special Deploy This PR will need a non-standard deploy to production and removed State: Blocked Work has stopped, waiting for something (Info, Dependent fix, etc. See comments). [managed] labels Jun 10, 2024
@mekarpeles mekarpeles marked this pull request as ready for review June 10, 2024 20:23
@cdrini cdrini force-pushed the feature/direct-book-provider branch from 5fdb8c1 to c7a3fcf Compare June 12, 2024 15:49
@cdrini
Copy link
Collaborator Author

cdrini commented Jun 13, 2024

Notes from rebase:

This code was in AffiliateLinks.html, to add the OPDS buy options to our buy options, but that code has since been updated to no longer take in page as a parameter. Should be an easy fix in some future PR where we want to re-enable this feature.

    $for provider in page.get('providers', []):
      $if provider.get('rel') == 'http://opds-spec.org/acquisition/buy' and provider.get('href'):
        $ name = provider.get('name', _('Official Vendor'))
        $ href = provider.get('href')
        $ price = provider.get('properties', {}).get('price', {}).get('value')
        $if price:
          $ price = '$%.2f' % price
        $:affiliate_link('direct', 'direct', name, href, price)

Comment on lines 135 to 142
if (
action == "borrow"
and (provider := get_book_provider(edition))
and (providers := provider.get_ebook_providers(edition))
and len(providers) >= 1
and providers[0].access == "open-access"
):
Copy link
Member

Choose a reason for hiding this comment

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

This is for action="borrow" which is typically for borrowable books, but given most trusted book providers are for open access materials (and we tend to use "read" for these) we should make sure a case of /borrow?action=read also succeeds

@scottbarnes scottbarnes force-pushed the feature/direct-book-provider branch from 7961494 to 8b806be Compare July 9, 2024 21:02
@codecov-commenter
Copy link

codecov-commenter commented Jul 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 16.21%. Comparing base (ce16a79) to head (84bdb7d).
Report is 55 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6585      +/-   ##
==========================================
+ Coverage   16.06%   16.21%   +0.15%     
==========================================
  Files          90       90              
  Lines        4769     4786      +17     
  Branches      832      829       -3     
==========================================
+ Hits          766      776      +10     
- Misses       3480     3486       +6     
- Partials      523      524       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator Author

@cdrini cdrini left a comment

Choose a reason for hiding this comment

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

Woooohooooo!!! This is so close!! I think this last set of changes, and then merge it up to the github in the sky!

@cdrini cdrini added Needs: Submitter Input Waiting on input from the creator of the issue/pr [managed] and removed Needs: Special Deploy This PR will need a non-standard deploy to production labels Jul 10, 2024
@scottbarnes scottbarnes mentioned this pull request Jul 17, 2024
16 tasks
@scottbarnes scottbarnes force-pushed the feature/direct-book-provider branch from eb0b2f9 to 84bdb7d Compare July 24, 2024 20:20
@cdrini cdrini changed the title Experiment with direct book providers Add direct book providers Jul 24, 2024
@cdrini cdrini merged commit d244fe3 into internetarchive:master Jul 24, 2024
5 checks passed
@cdrini cdrini deleted the feature/direct-book-provider branch July 24, 2024 21:41
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.

Implement basic web book support
5 participants