37 lines
954 B
Python
37 lines
954 B
Python
|
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)
|
||
|
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
|