country code support

This commit is contained in:
2022-04-24 17:25:47 -04:00
parent 6dff53770a
commit 31ebe358d5
3 changed files with 9 additions and 3 deletions

View File

@@ -18,6 +18,9 @@ Regardless of how you run it, the program expects the above API tokens to be ava
- **TMDB_API_TOKEN**
- **TG_BOT_TOKEN**
Optional environment variables:
- **STREAMING_COUNTRY** (default "us") - Choose any ISO 3166 country code supported by the [Sreaming Availability API](https://rapidapi.com/movie-of-the-night-movie-of-the-night-default/api/streaming-availability/)
### Docker
One-liner:
```
@@ -39,6 +42,7 @@ services:
- TMDB_API_TOKEN=${TMDB_API_TOKEN} # Required
- SA_API_TOKEN=${SA_API_TOKEN} # Required
- TG_BOT_TOKEN=${TG_BOT_TOKEN} # Required
- STREAMING_COUNTRY= # (optional) Default "us"
- TG_BOT_USER= # (optional) Limits access to the bot to a single Telegram user
restart: always
```

View File

@@ -45,9 +45,9 @@ def tmdb_lookup(tmdb_url, tmdb_headers, movie, year=None):
return movie_id, movie_title, movie_year, movie_rating
def sa_lookup(sa_url, sa_headers, movie_id):
def sa_lookup(sa_url, sa_headers, movie_id, country):
sa_params = {
"country": "us",
"country": country,
"tmdb_id": f"movie/{movie_id}",
"output_language": "en"
}

View File

@@ -17,6 +17,7 @@ tmdb_api_token = os.environ.get("TMDB_API_TOKEN")
sa_api_token = os.environ.get("SA_API_TOKEN")
bot_token = os.environ.get("TG_BOT_TOKEN")
country = os.environ.get("STREAMING_COUNTRY") or "us"
filter_user = os.environ.get("TG_BOT_USER")
tmdb_url = "https://api.themoviedb.org/3"
@@ -87,7 +88,7 @@ def movie_lookup(movie):
error_response = True
return tg_reply, similarity, error_response
sa_response, services = movie_check.sa_lookup(sa_url, sa_headers, movie_id)
sa_response, services = movie_check.sa_lookup(sa_url, sa_headers, movie_id, country)
if sa_response == "404":
logger.info('Movie not found by the Streaming Availability API.')
@@ -167,6 +168,7 @@ def main():
print("ERROR: Telegram bot token not provided. Exiting...")
exit()
if filter_user:
start_handler = CommandHandler('start', start,
Filters.user(username=filter_user))