Skip to content

Commit a5aebae

Browse files
Add ScraperAPI as an option besides Zenrows
Co-authored-by: Luuk Timmermans <[email protected]>
1 parent db58c75 commit a5aebae

File tree

3 files changed

+32
-18
lines changed

3 files changed

+32
-18
lines changed

README.md

+18-9
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,24 @@ Podimo is a proprietary podcasting player that enables you to listen to various
66
This tool allows you to stream Podimo podcasts with your preferred podcast player, without having to use the Podimo app.
77
</div>
88

9-
109
## Usage
11-
The easiest way to use it is via [podimo.thijs.sh](https://podimo.thijs.sh). You can also host it yourself by following the instructions below. It's necessary to create a Zenrows account to bypass Podimo's anti-bot mechanisms.
10+
The easiest way to use it is via [podimo.thijs.sh](https://podimo.thijs.sh). You can also host it yourself by following the instructions below. It's necessary to either create a Zenrows or ScraperAPI account to bypass Podimo's anti-bot mechanisms.
1211

13-
## Setting up a Zenrows account
12+
### Setting up a Zenrows account
1413
You can create a free account, which gives you 1000 free api credits.
1514

1615
1. Go to [app.zenrows.com/register](https://app.zenrows.com/register) and create a free account
1716
2. Copy your API key and make sure to add it to the `ZENROWS_API` environment variable (`-e`) in the Docker run command
1817

18+
### Setting up a ScraperAPI account
19+
20+
You can create a free account, which gives you 1000 free API credits per month.
21+
22+
1. Go to [dashboard.scraperapi.com/signup](https://dashboard.scraperapi.com/signup) and create a free account
23+
2. Copy your API key and make sure to add it to the `SCRAPER_API` environment variable (`-e`) in the Docker run command
24+
1925
## Instructions for self-hosting (with Docker)
26+
2027
1. Clone this repository and enter the newly created directory
2128
```sh
2229
git clone https://github.com/ThijsRay/podimo
@@ -28,10 +35,13 @@ cd podimo
2835
docker build -t podimo:latest .
2936
```
3037

31-
3. Run the Docker image
38+
3. Run the Docker image.
39+
Make sure you set the correct environment variables, and to add the API keys for
40+
ZenRows or ScraperAPI if you decide to use those services.
3241
```sh
33-
docker run --rm -e PODIMO_HOSTNAME=yourip:12104 -e PODIMO_BIND_HOST=0.0.0.0:12104 -e PODIMO_PROTOCOL=http -e ZENROWS_API=APIKEY -p 12104:12104 podimo:latest
42+
docker run --rm -e PODIMO_HOSTNAME=yourip:12104 -e PODIMO_BIND_HOST=0.0.0.0:12104 -e PODIMO_PROTOCOL=http -p 12104:12104 podimo:latest
3443
```
44+
3545
For an explaination of what each environmental variable (`-e`) does, see the section on [configuration with environmental variables](#configuration).
3646

3747
4. Visit http://yourip:12104. You should see the site now!
@@ -60,16 +70,15 @@ pip install -r requirements.txt
6070
```sh
6171
python main.py
6272
```
63-
4. Visit http://localhost:12104. You should see the site now!
64-
73+
5. Visit http://localhost:12104. You should see the site now!
6574

6675
## Configuration
6776
There are a few environmental variables that can configure this tool
6877
- `PODIMO_HOSTNAME` Sets the hostname that is displayed in the interface to a custom value, defaults to `podimo.thijs.sh`
6978
- `PODIMO_BIND_HOST` Sets the IP and port to which this tool should bind, defaults to `127.0.0.1:12104`.
70-
- `PODIMO_PROTOCOL` Sets the protocol that is displayed in the interface. For local
71-
deployments it can be useful to set this to `http`. Defaults to `https`.
79+
- `PODIMO_PROTOCOL` Sets the protocol that is displayed in the interface. For local deployments it can be useful to set this to `http`. Defaults to `https`.
7280
- `ZENROWS_API` Sets the Zenrows API key for it to be used.
81+
- `SCRAPER_API` Sets the ScraperAPI API key for it to be used.
7382
- `DEBUG` Shows a bit more information that can be useful while debugging
7483
- `HTTP_PROXY` A URL for an HTTP proxy that can be used to rotate IP addresses to avoid being blocked by CloudFlare.
7584

podimo/client.py

+13-9
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
# See the Licence for the specific language governing
1818
# permissions and limitations under the Licence.
1919

20-
from podimo.config import GRAPHQL_URL, ZENROWS_API
20+
from podimo.config import GRAPHQL_URL, SCRAPER_API, ZENROWS_API
2121
from podimo.utils import (is_correct_email_address, token_key,
2222
randomFlyerId, generateHeaders as gHdrs, debug,
2323
async_wrap)
2424
from podimo.cache import insertIntoPodcastCache, getCacheEntry, podcast_cache
2525
from time import time
26-
from os import getenv
27-
from zenrows import ZenRowsClient
2826
import sys
27+
if ZENROWS_API is not None:
28+
from zenrows import ZenRowsClient
2929

3030
class PodimoClient:
3131
def __init__(self, username: str, password: str, region: str, locale: str):
@@ -41,21 +41,26 @@ def __init__(self, username: str, password: str, region: str, locale: str):
4141
raise ValueError("Username or password are too long")
4242
if not is_correct_email_address(username):
4343
return ValueError("Email is not in the correct format")
44-
44+
4545
self.key = token_key(username, password)
4646
self.token = None
4747

4848
def generateHeaders(self, authorization):
49-
return gHdrs(authorization, self.locale)
49+
return gHdrs(authorization, self.locale)
5050

5151
async def post(self, headers, query, variables, scraper):
52-
if ZENROWS_API is not None:
52+
if SCRAPER_API is not None:
53+
POST_URL = f"https://api.scraperapi.com?api_key={SCRAPER_API}&url={GRAPHQL_URL}&keep_headers=true"
54+
elif ZENROWS_API is not None:
5355
scraper = ZenRowsClient(ZENROWS_API)
54-
response = await async_wrap(scraper.post)(GRAPHQL_URL,
56+
POST_URL = GRAPHQL_URL
57+
else:
58+
POST_URL = GRAPHQL_URL
59+
response = await async_wrap(scraper.post)(POST_URL,
5560
headers=headers,
5661
cookies=self.cookie_jar,
5762
json={"query": query, "variables": variables},
58-
timeout=(6.05, 12.05)
63+
timeout=(6.05, 30)
5964
)
6065
if response is None:
6166
raise RuntimeError(f"Could not receive response for query: {query.strip()[:30]}...")
@@ -70,7 +75,6 @@ async def post(self, headers, query, variables, scraper):
7075
# as an anonymous user
7176
async def getPreregisterToken(self, scraper):
7277
headers = self.generateHeaders(None)
73-
7478
debug("AuthorizationPreregisterUser")
7579
query = """
7680
query AuthorizationPreregisterUser($locale: String!, $referenceUser: String, $countryCode: String, $appsFlyerId: String) {

podimo/config.py

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
PODIMO_BIND_HOST = os.environ.get("PODIMO_BIND_HOST", "0.0.0.0:12104")
3131
PODIMO_PROTOCOL = os.environ.get("PODIMO_PROTOCOL", "http")
3232
ZENROWS_API = os.environ.get("ZENROWS_API", None)
33+
SCRAPER_API = os.environ.get("SCRAPER_API", None)
3334

3435
# Enable extra logging in debugging mode
3536
DEBUG = os.environ.get("DEBUG", False)

0 commit comments

Comments
 (0)