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

Storytel Cloudflare block #137

Open
xzakier opened this issue Dec 21, 2024 · 51 comments
Open

Storytel Cloudflare block #137

xzakier opened this issue Dec 21, 2024 · 51 comments
Labels
bug Something isn't working

Comments

@xzakier
Copy link

xzakier commented Dec 21, 2024

Installation method:
Github repo & pip/pypi (tried 2 times)

Version: 0.7.3
Python version : 3.12

Describe the bug
Finding compatible source
Authenticating with storytel
ERROR: Access blocked by Cloudflare

@xzakier xzakier added the bug Something isn't working label Dec 21, 2024
@fedeD84
Copy link

fedeD84 commented Dec 22, 2024

Same issue for me.

@xdaGari
Copy link

xdaGari commented Dec 26, 2024

Changing the device ID in audiobookdl/sources/storytel.py (Line 173) fixed it for me.

@fedeD84
Copy link

fedeD84 commented Dec 26, 2024

@xdaGari exacty how you changed it?

@ssakkout
Copy link
Contributor

@fedeD84
i have created a pull request to update the device id #138

@freddy36
Copy link
Collaborator

Thank you, included in the latest release:
https://github.com/jo1gi/audiobook-dl/releases/tag/v0.76

@msebastian100
Copy link

msebastian100 commented Dec 31, 2024

@freddy36 not fixed

Finding compatible source
Authenticating with storytel
ERROR: Access blocked by Cloudflare

if you execute the command you get the old version installed.
pip install “git+https://github.com/jo1gi/audiobook-dl.git”

loads the old version

@munchbp
Copy link

munchbp commented Jan 3, 2025

Thank you, included in the latest release: https://github.com/jo1gi/audiobook-dl/releases/tag/v0.76

git command gets v0.7.3 and also I tried downloading the latest zip and it still is v0.7.3

@fedeD84
Copy link

fedeD84 commented Jan 7, 2025

blocked again, same error

@freddy36
Copy link
Collaborator

freddy36 commented Jan 9, 2025

@fedeD84
Copy link

fedeD84 commented Jan 9, 2025

it seems fixed now, thanks

@notavailable-1
Copy link

notavailable-1 commented Jan 10, 2025

Blocked again :( with 0.7.7

@fedeD84
Copy link

fedeD84 commented Jan 10, 2025

i can confirm that blocked again

@dev-O-T
Copy link

dev-O-T commented Jan 11, 2025

If you update user agent with these, it will be fine:

Storytel/24.52
Release/2288809

@fedeD84
Copy link

fedeD84 commented Jan 11, 2025

I have changed user agent but get same error

@dev-O-T
Copy link

dev-O-T commented Jan 11, 2025

Works for me. Just tried again. I don't have other changes.

Without the user agent change I get cloudflare blocked error.

@fedeD84
Copy link

fedeD84 commented Jan 11, 2025

You changed it in storytel.py right it’s only one string

@notavailable-1
Copy link

notavailable-1 commented Jan 11, 2025

Works for me. Just tried again. I don't have other changes.

Without the user agent change I get cloudflare blocked error.

Wich version of audiobook-dl do you use?
In wich file do you make these changes?
where in this file do you make these changes?

thanks for your help :)

@dev-O-T
Copy link

dev-O-T commented Jan 11, 2025

The latest with random uuid.

Installed with:
pip install --user
"git+https://github.com/jo1gi/audiobook-dl.git"

I looked the version numbers from Play Store's latest Storytel release.

storytel.py line 167:
"User-Agent": "Storytel/24.52 (Android 14; Google Pixel 8 Pro) Release/2288809",

@notavailable-1
Copy link

notavailable-1 commented Jan 11, 2025

The latest with random uuid.

Installed with: pip install --user "git+https://github.com/jo1gi/audiobook-dl.git"

I looked the version numbers from Play Store's latest Storytel release.

storytel.py line 167: "User-Agent": "Storytel/24.52 (Android 14; Google Pixel 8 Pro) Release/2288809",

and you have the audiobook in your shelf and copy the link from your browser, and the download works?

@dev-O-T
Copy link

dev-O-T commented Jan 11, 2025

No. I never put them to shelf. I only copy the links from the browser and it works.

@notavailable-1
Copy link

notavailable-1 commented Jan 11, 2025

k. i dont get it. same version here + edit in storytel.py and it gives me blocked by cloudflare

@fedeD84
Copy link

fedeD84 commented Jan 11, 2025

same to me

@dev-O-T
Copy link

dev-O-T commented Jan 11, 2025

I did fresh install on laptop (with python 3.11). With user agent change it started working.

Previous trials were on my phone with python 3.8.

I wonder how have you installed your audiobook-dl. If you cloned with git, did you run the "python3 setup.py install" after changes?

With pip installation "setup.py install" not needed.

@notavailable-1
Copy link

I did fresh install on laptop (with python 3.11). With user agent change it started working.

Previous trials were on my phone with python 3.8.

I wonder how have you installed your audiobook-dl. If you cloned with git, did you run the "python3 setup.py install" after changes?

With pip installation "setup.py install" not needed.

im on Python 3.12.8. install via pip installation

@fedeD84
Copy link

fedeD84 commented Jan 12, 2025

I’ve tryed a fresh install in venv but same result

@dev-O-T
Copy link

dev-O-T commented Jan 12, 2025

Perhaps your IP is blocked due to previous attempts? Can you try to change the IP or use different connection? VPN?

@fedeD84
Copy link

fedeD84 commented Jan 12, 2025

No, not related to IP block, tryed with VPN and have same error. Sure you don't have specific configuration? For example how you donwlod abook without put it in shelf? For me never worked without

@dev-O-T
Copy link

dev-O-T commented Jan 12, 2025

I use following bash script (script name: storytel-dl) as wrapper, and I give link as parameter:

#!/bin/bash
audiobook-dl --username [email protected] --password baz --library Storytel -d $1

Usage example:
bash storytel-dl https://www.storytel.com/fi/books/men-are-from-mars-women-are-from-venus-824493

@dev-O-T
Copy link

dev-O-T commented Jan 13, 2025

Now I'm experiencing strange issue that on one device the access is blocked by cloudflare, and with other device the accesses are not blocked.

The random uuid and my local user agent changes are used on both of them.

Both are in the same local network with the same public IP.

@freddy36
Copy link
Collaborator

freddy36 commented Jan 13, 2025

@dev-O-T can you compare openssl versions (including python version and python openssl module)?
They used TLS fingerprinting in the past to block python requests.

@dev-O-T
Copy link

dev-O-T commented Jan 13, 2025

The working one is with:
Python 3.8.18
OpenSSL 1.1.1v

Blocked:
Python 3.11.2
OpenSSL 3.0.15

@freddy36
Copy link
Collaborator

Probably some newer openssl feature which is only set when using python but not regular browsers.
If you want to continue investigating I would suggest you try different python/openssl version combinations or compare the enabled extensions during the handshakes using wireshark.

@fedeD84
Copy link

fedeD84 commented Jan 13, 2025

@dev-O-T in my situation i've installed OpenSSL 3.3.2 and Python 3.12.6. Until 2/3 days ago no issue with download

@dev-O-T
Copy link

dev-O-T commented Jan 14, 2025

The one I had working is blocked now too.

@piorek
Copy link

piorek commented Jan 15, 2025

Same issue here

@JerukPurut404
Copy link

Still not working

@dev-O-T
Copy link

dev-O-T commented Jan 16, 2025

Got it working locally by migrating from requests to curl_cffi.requests. Very minimal changes required.

@notavailable-1
Copy link

Got it working locally by migrating from requests to curl_cffi.requests. Very minimal changes required.

good to hear :) where do you make these changes or how?

@fedeD84
Copy link

fedeD84 commented Jan 16, 2025

Got it working locally by migrating from requests to curl_cffi.requests. Very minimal changes required.

Good, can you tell us where you make changes? Thanks

@dev-O-T
Copy link

dev-O-T commented Jan 16, 2025

Sure,

audiobookdl/sources/source/init.py:

#import requests
import curl_cffi

And in the end of file:

    def create_session(self, options: Any) -> curl_cffi.requests.Session:
        session = curl_cffi.requests.Session()
#        ssl_context: SSLContext = self.create_ssl_context(options)
        # session.adapters.pop("https://", None)
#        session.mount("https://", CustomSSLContextHTTPAdapter(ssl_context))
        return session

audiobookdl/sources/storytel.py:1
from curl_cffi.requests.models import Response

audiobookdl/utils/audiobook.py:3:
from curl_cffi import requests

I think thats all.

I get one warning while running, but the downloaded file is ok:
download.py:187: UserWarning: chunk_size is ignored, there is no way to tell curl that.
for chunk in request.iter_content(chunk_size=1024):

I don't know will this break other sources. It was just quick and dirty trial, and luckily the first download with Storytel worked.

@notavailable-1
Copy link

notavailable-1 commented Jan 16, 2025

Sure,

audiobookdl/sources/source/init.py:

#import requests
import curl_cffi

And in the end of file:

    def create_session(self, options: Any) -> curl_cffi.requests.Session:
        session = curl_cffi.requests.Session()
#        ssl_context: SSLContext = self.create_ssl_context(options)
        # session.adapters.pop("https://", None)
#        session.mount("https://", CustomSSLContextHTTPAdapter(ssl_context))
        return session

audiobookdl/sources/storytel.py:1 from curl_cffi.requests.models import Response

audiobookdl/utils/audiobook.py:3: from curl_cffi import requests

I think thats all.

I get one warning while running, but the downloaded file is ok: download.py:187: UserWarning: chunk_size is ignored, there is no way to tell curl that. for chunk in request.iter_content(chunk_size=1024):

I don't know will this break other sources. It was just quick and dirty trial, and luckily the first download with Storytel worked.

its working. thank you so much :)

maybe because of the forced ssl/tls connection? :)

@fedeD84
Copy link

fedeD84 commented Jan 16, 2025

Sure,

audiobookdl/sources/source/init.py:

#import requests
import curl_cffi

And in the end of file:

    def create_session(self, options: Any) -> curl_cffi.requests.Session:
        session = curl_cffi.requests.Session()
#        ssl_context: SSLContext = self.create_ssl_context(options)
        # session.adapters.pop("https://", None)
#        session.mount("https://", CustomSSLContextHTTPAdapter(ssl_context))
        return session

audiobookdl/sources/storytel.py:1 from curl_cffi.requests.models import Response

audiobookdl/utils/audiobook.py:3: from curl_cffi import requests

I think thats all.

I get one warning while running, but the downloaded file is ok: download.py:187: UserWarning: chunk_size is ignored, there is no way to tell curl that. for chunk in request.iter_content(chunk_size=1024):

I don't know will this break other sources. It was just quick and dirty trial, and luckily the first download with Storytel worked.

I've made changes but i get this errore while trying download:
"/audiobookdl/utils/audiobook.py", line 3, in
from curl_cffi import requests

@notavailable-1
Copy link

do you have curl_cffi installed? pip install curl_cffi

@fedeD84
Copy link

fedeD84 commented Jan 16, 2025

pip install curl_cffi

I'm stupid... sorry now it works

@dev-O-T
Copy link

dev-O-T commented Jan 16, 2025

I did a Python script for sniffing the TLS fingerprints, and got some values while opening the latest official Android client.

Just in case someone wants to try with the same fingerprints:

IPv6:
JA3 Fingerprint: 771,4865,4866,4867,49195,49196,52393,49199,49200,52392,49171,49172,156,157,47,53,, Hash: 59fad7e58fa57d3f0545624f6814de3a

IPv4:
JA3 Fingerprint: 771,4865,4866,4867,49195,49196,52393,49199,49200,52392,49161,49162,49171,49172,156,157,47,53,, Hash: aef0bb248d17ef28d4dee53e4f0485c7

IPv4 is slightly different.

@rickyspanish8
Copy link

not working for me. :(

@fedeD84
Copy link

fedeD84 commented Jan 16, 2025

not working for me. :(

have you change all files?

@rickyspanish8
Copy link

Yes I did. Do I need to reinstall after that? with sudo python3 setup.py install?

@notavailable-1
Copy link

Yes I did. Do I need to reinstall after that? with sudo python3 setup.py install?

nope.
do you have curl_cffi installed? pip install curl_cffi

wich version did you use?
wich changes have you applied?

@rickyspanish8
Copy link

rickyspanish8 commented Jan 17, 2025

im using the last version, pulled from github.

my utils/audiobook.py file https://pastebin.com/k5C1g1s9
my sources/source init.py https://pastebin.com/qzw05BfT
and my sources/storytel.py https://pastebin.com/KGgXiyL4

I did install curl_cffi and Im using the command audiobook-dl -c <here I put the name of the cookies file that its in the same directory of audiobook-dl> <and here I paste the url from storytel>
I have no idea what can I be doing wrong.

@iamthehoot
Copy link

iamthehoot commented Jan 18, 2025

All releases of audiobook-dl since version 0.7.3 still say version 0.7.3, which is very annoying when you have issues allegedly resolved in more recent versions.

In anyhoot, I tried to follow your suggestion @dev-O-T, but to no avail.

%AppData%\..\Local\Programs\Python\Python312\Lib\site-packages\audiobookdl\sources\source\__init__.py

8:#import requests
9:import curl_cffi

[...]

196: def create_session(self, options: Any) -> curl_cffi.requests.Session:
197: session = curl_cffi.requests.Session()
198:# ssl_context: SSLContext = self.create_ssl_context(options)
199: # session.adapters.pop("https://", None)
200:# session.mount("https://", CustomSSLContextHTTPAdapter(ssl_context))
201: return session

%AppData%\..\Local\Programs\Python\Python312\Lib\site-packages\audiobookdl\sources\storytel.py

1:#from requests.models import Response
2:from curl_cffi.requests.models import Response

%AppData%\..\Local\Programs\Python\Python312\Lib\site-packages\audiobookdl\utils\audiobook.py

2:#import requests
3:from curl_cffi import requests

Installed the new requirement: pip install curl_cffi

But I get the same error message:

DEBUG audiobook-dl 0.7.3
DEBUG python 3.12.8 (tags/v3.12.8:2dc476b, Dec 3 2024, 19:30:04) [MSC v.1942 64 bit (AMD64)]
INFO Finding compatible source
INFO Authenticating with storytel
DEBUG Logging in
ERROR: Access blocked by Cloudflare

Traceback:

Traceback (most recent call last):
File "%AppData%..\Local\Programs\Python\Python312\Lib\site-packages\audiobookdl_main_.py", line 33, in main process_url(url, options, config)
File "%AppData%..\Local\Programs\Python\Python312\Lib\site-packages\audiobookdl_main_.py", line 53, in process_url authenticate(url, source, options, config)
File "%AppData%..\Local\Programs\Python\Python312\Lib\site-packages\audiobookdl_main_.py", line 143, in authenticate login(url, source, options, source_config)
File "%AppData%..\Local\Programs\Python\Python312\Lib\site-packages\audiobookdl_main_.py", line 123, in login source.login(url, **login_data)
File "%AppData%..\Local\Programs\Python\Python312\Lib\site-packages\audiobookdl\sources\source_init_.py", line 96, in login self._login(url, **kwargs)
File "%AppData%..\Local\Programs\Python\Python312\Lib\site-packages\audiobookdl\sources\storytel.py", line 171, in _login self._do_login()
File "%AppData%..\Local\Programs\Python\Python312\Lib\site-packages\audiobookdl\sources\storytel.py", line 190, in _do_login self.check_cloudflare_blocked(resp)
File "%AppData%..\Local\Programs\Python\Python312\Lib\site-packages\audiobookdl\sources\storytel.py", line 160, in check_cloudflare_blocked raise CloudflareBlocked audiobookdl.exceptions.CloudflareBlocked

Thank you for trying to help.

Edit: I am on Windows, and I need to run audiobook from python with the -m flag to run the module as a script, or it won't work.

Full CLI command: python -m audiobookdl -d -- username <email> --password <password> <audiobook url>

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

No branches or pull requests