mirror of
https://github.com/KevinMidboe/Node-Com-Handler.git
synced 2025-10-29 17:50:27 +00:00
Code for handling URL and getting search results from themoviedb and returning only valuable data back.
This commit is contained in:
62
v1/tmdb.py
Normal file → Executable file
62
v1/tmdb.py
Normal file → Executable file
@@ -7,9 +7,33 @@
|
|||||||
|
|
||||||
from requests import get
|
from requests import get
|
||||||
|
|
||||||
|
plexBaseURL = "http://10.0.0.41:32400/"
|
||||||
tmdbBaseURL = "https://api.themoviedb.org/3/"
|
tmdbBaseURL = "https://api.themoviedb.org/3/"
|
||||||
|
|
||||||
|
def plexSearch(query):
|
||||||
|
requestType = "search?"
|
||||||
|
requestQuery = "query=" + str(query)
|
||||||
|
header = {'Accept': 'application/json'}
|
||||||
|
|
||||||
|
url = plexBaseURL + requestType + requestQuery
|
||||||
|
response = get(url, headers=header)
|
||||||
|
|
||||||
|
if response.status_code == 200:
|
||||||
|
resContent = response.json()
|
||||||
|
|
||||||
|
for child in resContent["_children"]:
|
||||||
|
cType = child["type"]
|
||||||
|
if cType == "movie" or cType == "show":
|
||||||
|
print(child["title"], child["year"])
|
||||||
|
|
||||||
|
def checkInPlex(query):
|
||||||
|
plexSearch(query)
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def tmdbSearch(query, page=1):
|
def tmdbSearch(query, page=1):
|
||||||
|
plexSearch(query)
|
||||||
|
|
||||||
requestType = "search/multi?"
|
requestType = "search/multi?"
|
||||||
requestAPI = "api_key=" + "9fa154f5355c37a1b9b57ac06e7d6712"
|
requestAPI = "api_key=" + "9fa154f5355c37a1b9b57ac06e7d6712"
|
||||||
requestQuery = "&query=" + str(query)
|
requestQuery = "&query=" + str(query)
|
||||||
@@ -17,12 +41,42 @@ def tmdbSearch(query, page=1):
|
|||||||
requestPage = "&page="+str(page)
|
requestPage = "&page="+str(page)
|
||||||
|
|
||||||
url = tmdbBaseURL + requestType + requestAPI + requestQuery + requestLanguage + requestPage
|
url = tmdbBaseURL + requestType + requestAPI + requestQuery + requestLanguage + requestPage
|
||||||
# url = "https://api.themoviedb.org/3/search/multi?include_adult=false&query=home%20alone&language=en-US&api_key=9fa154f5355c37a1b9b57ac06e7d6712"
|
print(url)
|
||||||
|
|
||||||
response = get(url)
|
response = get(url)
|
||||||
print(response.status_code)
|
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
return response.content
|
resContent = response.json()
|
||||||
|
|
||||||
|
movies = []
|
||||||
|
tvshows = []
|
||||||
|
|
||||||
|
for res in resContent["results"]:
|
||||||
|
if res["media_type"] == "movie":
|
||||||
|
id = res["id"]
|
||||||
|
title = res["original_title"]
|
||||||
|
year = res["release_date"][:4]
|
||||||
|
poster_path = res["poster_path"]
|
||||||
|
|
||||||
|
movies.append( {"id": id, "title": title, "year": year, "poster_path": poster_path} )
|
||||||
|
|
||||||
|
elif res["media_type"] == "tv":
|
||||||
|
id = res["id"]
|
||||||
|
name = res["original_name"]
|
||||||
|
year = res["first_air_date"][:4]
|
||||||
|
poster_path = res["poster_path"]
|
||||||
|
|
||||||
|
tvshows.append( {"id": id, "title": name, "year": year, "poster_path": poster_path} )
|
||||||
|
|
||||||
|
searchResults = { "movies": movies, "tvshows": tvshows }
|
||||||
|
return searchResults
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print(tmdbSearch("Big bang"))
|
import sys
|
||||||
|
print(sys.argv)
|
||||||
|
if len(sys.argv) > 2:
|
||||||
|
print(tmdbSearch(sys.argv[1], int(sys.argv[2])))
|
||||||
|
elif len(sys.argv) > 1:
|
||||||
|
print(tmdbSearch(sys.argv[1]))
|
||||||
|
else:
|
||||||
|
print(tmdbSearch("star+wars",2))
|
||||||
Reference in New Issue
Block a user