Some checks failed
Deploy Backend / deploy (push) Failing after 2m30s
- Remove flask-sse, Redis (unused) - Remove ImageService, file_utils (unused) - Remove /download-posters route (frontend handles download client-side) - Remove LETTERBOXD_API_URL, secure_filename (dead imports) - Fix duplicate TMDBService instantiation - Simplify config.py (remove REDIS_URL) - Fix gunicorn user home dir for control socket - Add .gitignore for __pycache__ - Add .gitea/workflows/deploy.yml for tag-based CI/CD
33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
import os
|
|
import requests
|
|
from dotenv import load_dotenv
|
|
|
|
load_dotenv()
|
|
|
|
class TMDBService:
|
|
def __init__(self):
|
|
self.api_key = os.getenv('TMDB_API_KEY')
|
|
self.access_token = os.getenv('TMDB_ACCESS_TOKEN')
|
|
self.base_url = 'https://api.themoviedb.org/3'
|
|
|
|
def search_movie(self, title, year):
|
|
url = f"{self.base_url}/search/movie"
|
|
params = {
|
|
'api_key': self.api_key,
|
|
'query': title,
|
|
'year': year
|
|
}
|
|
response = requests.get(url, params=params)
|
|
response_data = response.json()
|
|
if response_data['results']:
|
|
return response_data['results'][0]
|
|
return None
|
|
|
|
def get_movie_posters(self, movie_id):
|
|
url = f"{self.base_url}/movie/{movie_id}/images?include_image_language=en,fr,ja,null&language=null"
|
|
headers = {
|
|
"accept": "application/json",
|
|
"Authorization": f"Bearer {self.access_token}"
|
|
}
|
|
response = requests.get(url, headers=headers)
|
|
return response.json().get('posters', []) |