flask-server/kinolist/imdb.py

58 lines
1.7 KiB
Python
Raw Normal View History

2024-10-10 17:44:47 -04:00
#
# Copyright (c) 2024 bartholin
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
2024-10-08 13:20:00 -04:00
from flask import current_app
from requests import get
from kinolist import posters
base_url = "http://www.omdbapi.com/"
def params(k,v):
return {
"apikey": current_app.config["OMDB_KEY"],
k: v,
"type": "movie"
}
def imdbid(imdbid):
data = get(base_url, params=params("i", imdbid)).json()
if data['Response'] == 'True':
movie = {
"title": data["Title"],
"year": data["Year"],
"language": data["Language"],
"plot": data["Plot"]
}
poster = data["Poster"]
if poster != "N/A":
img = get(poster)
if img.status_code == 200:
movie["poster"] = posters.save(poster, img.content)
else:
movie["poster"] = None
else:
movie["poster"] = None
2024-10-08 13:20:00 -04:00
return movie
else:
return None
def title(name):
data = get(base_url, params=params("s", name)).json()
if data["Response"] == "True":
return data["Search"]
else:
return None