Skip to content

Commit

Permalink
Merge pull request #28 from luuktimmermans/main
Browse files Browse the repository at this point in the history
Added Zenrows functionality
  • Loading branch information
ThijsRay authored Nov 20, 2023
2 parents 940a7a9 + 5e93ed4 commit db58c75
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ This tool allows you to stream Podimo podcasts with your preferred podcast playe


## Usage
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.
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.

## Setting up a Zenrows account
You can create a free account, which gives you 1000 free api credits.

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

## Instructions for self-hosting (with Docker)
1. Clone this repository and enter the newly created directory
Expand All @@ -24,11 +30,11 @@ docker build -t podimo:latest .

3. Run the Docker image
```sh
docker run --rm -e PODIMO_HOSTNAME=localhost -e PODIMO_BIND_HOST=0.0.0.0:12104 -e PODIMO_PROTOCOL=http -p 12104:12104 podimo:latest
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
```
For an explaination of what each environmental variable (`-e`) does, see the section on [configuration with environmental variables](#configuration).

4. Visit http://localhost:12104. You should see the site now!
4. Visit http://yourip:12104. You should see the site now!

## Installation for self-hosting (without Docker)
Make sure you have a recent Python 3 version installed, as this is required for the steps below.
Expand Down Expand Up @@ -63,6 +69,7 @@ There are a few environmental variables that can configure this tool
- `PODIMO_BIND_HOST` Sets the IP and port to which this tool should bind, defaults to `127.0.0.1:12104`.
- `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`.
- `ZENROWS_API` Sets the Zenrows API key for it to be used.
- `DEBUG` Shows a bit more information that can be useful while debugging
- `HTTP_PROXY` A URL for an HTTP proxy that can be used to rotate IP addresses to avoid being blocked by CloudFlare.

Expand Down
5 changes: 4 additions & 1 deletion podimo/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
# See the Licence for the specific language governing
# permissions and limitations under the Licence.

from podimo.config import GRAPHQL_URL
from podimo.config import GRAPHQL_URL, ZENROWS_API
from podimo.utils import (is_correct_email_address, token_key,
randomFlyerId, generateHeaders as gHdrs, debug,
async_wrap)
from podimo.cache import insertIntoPodcastCache, getCacheEntry, podcast_cache
from time import time
from os import getenv
from zenrows import ZenRowsClient
import sys

class PodimoClient:
Expand All @@ -48,6 +49,8 @@ def generateHeaders(self, authorization):
return gHdrs(authorization, self.locale)

async def post(self, headers, query, variables, scraper):
if ZENROWS_API is not None:
scraper = ZenRowsClient(ZENROWS_API)
response = await async_wrap(scraper.post)(GRAPHQL_URL,
headers=headers,
cookies=self.cookie_jar,
Expand Down
9 changes: 5 additions & 4 deletions podimo/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
# Defaults to "127.0.0.1:12104"
# - `PODIMO_PROTOCOL`: what protocol is being used for all links that are
# displayed to the user. Defaults to "https".
PODIMO_HOSTNAME = os.environ.get("PODIMO_HOSTNAME", "podimo.thijs.sh")
PODIMO_BIND_HOST = os.environ.get("PODIMO_BIND_HOST", "127.0.0.1:12104")
PODIMO_PROTOCOL = os.environ.get("PODIMO_PROTOCOL", "https")
PODIMO_HOSTNAME = os.environ.get("PODIMO_HOSTNAME", "yourip:12104")
PODIMO_BIND_HOST = os.environ.get("PODIMO_BIND_HOST", "0.0.0.0:12104")
PODIMO_PROTOCOL = os.environ.get("PODIMO_PROTOCOL", "http")
ZENROWS_API = os.environ.get("ZENROWS_API", None)

# Enable extra logging in debugging mode
DEBUG = os.environ.get("DEBUG", False)
Expand All @@ -41,7 +42,7 @@
TOKEN_TIMEOUT = 3600 * 24 * 5 # seconds = 5 days

# The time that a podcast feed is stored in cache
PODCAST_CACHE_TIME = 15 * 60 # seconds = 15 minutes
PODCAST_CACHE_TIME = 43200 # seconds = 12 hours

# The time that the content information is cached
HEAD_CACHE_TIME = 7 * 60 * 60 * 24 # seconds = 7 days
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ quart~=0.18.4
hypercorn~=0.14.4
cloudscraper~=1.2.71
werkzeug~=2.3.7
zenrows~=1.3.2

0 comments on commit db58c75

Please sign in to comment.