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

Audiobooks not downloading as the URL is now too long #118

Open
geekylou opened this issue Aug 22, 2024 · 5 comments
Open

Audiobooks not downloading as the URL is now too long #118

geekylou opened this issue Aug 22, 2024 · 5 comments
Labels
bug Something isn't working needs_reproduction Steps to reproduce bug are unclear.

Comments

@geekylou
Copy link

Before you open an issue
Please make sure you've upgraded to the latest version of kobodl on pypi or docker. Also read through the troubleshooting guide. Try running with --debug enabled and see what comes up in the debug log.

Do not erase this template, it's here to help you.

Describe the issue
It looks like now kobodl is failing due to the URL returned from the kobo servers being too long for something in the python libraries. I receive a 403 Client error in __DownloadAudiobook but copying the URL manually to firefox loads the manifest. I can then copy then also copy the audiotracks from the manifest into firefox and the audiofile will load correctly.

To Reproduce
Steps to reproduce the behavior:
just call kobodl book get

@geekylou geekylou added the bug Something isn't working label Aug 22, 2024
@subdavis
Copy link
Owner

subdavis commented Aug 22, 2024

You erased some important parts of the issue template, so I can't help as much as I'd like to. To make sure this isn't an issue with the file path being too long:

kobodl book get -f '{ShortRevisionId}' UUID

If that doesn't work, please share the error you're seeing.

Possibly related: #95

@subdavis subdavis added the needs_reproduction Steps to reproduce bug are unclear. label Aug 22, 2024
@geekylou
Copy link
Author

geekylou commented Aug 22, 2024

With -f '{ShortRevisionId}' I get:

ownloading f2e31e75-864d-4eb4-b105-0559fe9e7f27 to /home/louise/kobo_downloads/f2e31e75
Traceback (most recent call last):
  File "/home/louise/kobodl/bin/kobodl", line 8, in <module>
    sys.exit(cli())
  File "/home/louise/kobodl/lib/python3.10/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/louise/kobodl/lib/python3.10/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/louise/kobodl/lib/python3.10/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/louise/kobodl/lib/python3.10/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/louise/kobodl/lib/python3.10/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/louise/kobodl/lib/python3.10/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/louise/kobodl/lib/python3.10/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context().obj, *args, **kwargs)
  File "/home/louise/kobodl/lib/python3.10/site-packages/kobodl/commands/book.py", line 83, in get
    actions.GetBookOrBooks(usercls, output_dir, formatStr=format_str, productId=pid)
  File "/home/louise/kobodl/lib/python3.10/site-packages/kobodl/actions.py", line 231, in GetBookOrBooks
    kobo.Download(bookMetadata, book_type == BookType.AUDIOBOOK, outputFilePath)
  File "/home/louise/kobodl/lib/python3.10/site-packages/kobodl/kobo.py", line 349, in Download
    self.__DownloadAudiobook(downloadUrl, outputPath)
  File "/home/louise/kobodl/lib/python3.10/site-packages/kobodl/kobo.py", line 277, in __DownloadAudiobook
    response.raise_for_status()
  File "/home/louise/kobodl/lib/python3.10/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://storedownloads.kobo.com/download?downloadToken= \<redacted\>

Loading the url into firefox though gives me the metadata and I can then download it manually. Curiously using curl gives me cloudflare error about being blocked so maybe something else is going on.

@jljusten
Copy link

jljusten commented Sep 3, 2024

Loading the url into firefox though gives me the metadata and I can then download it manually. Curiously using curl gives me cloudflare error about being blocked so maybe something else is going on.

Here's a potentially related comment saying that using the urllib module instead of the requests module might help some 403 responses: https://stackoverflow.com/a/74674276

@leela1255
Copy link

leela1255 commented Oct 21, 2024

I've also run into this problem - the original stack looks like this:

Traceback (most recent call last):
  File "kobodl\__main__.py", line 5, in <module>
  File "click\core.py", line 829, in __call__
  File "click\core.py", line 782, in main
  File "click\core.py", line 1259, in invoke
  File "click\core.py", line 1259, in invoke
  File "click\core.py", line 1066, in invoke
  File "click\core.py", line 610, in invoke
  File "click\decorators.py", line 33, in new_func
  File "kobodl\commands\book.py", line 83, in get
  File "kobodl\actions.py", line 231, in GetBookOrBooks
  File "kobodl\kobo.py", line 346, in Download
  File "kobodl\kobo.py", line 276, in __DownloadAudiobook
  File "requests\models.py", line 1021, in raise_for_status
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://storedownloads.kobo.com/download?downloadToken=
[11580] Failed to execute script '__main__' due to unhandled exception!

This appears to match the stack above after using -f '{ShortRevisionId}'. I also retried with -f '{ShortRevisionId}' and got the same stack again. This happened for 3 separate audiobooks I was attempting to download, so definitely seems to be a problem with them.

As noted, I could load the json and download each track individually so the ability to get the content still seems to be there, just needs some tweaking.

@geekylou
Copy link
Author

geekylou commented Oct 23, 2024

Using cloudscraper fixed this issue for me. Replacing all references to self.Session.get(url) with scraper.get(url) in __DownloadAudiobook stopped the forbidden 403 error from being generated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs_reproduction Steps to reproduce bug are unclear.
Projects
None yet
Development

No branches or pull requests

4 participants