diff --git a/v1/tmdb.py b/v1/tmdb.py old mode 100644 new mode 100755 index adb414a..1b65c89 --- a/v1/tmdb.py +++ b/v1/tmdb.py @@ -7,9 +7,33 @@ from requests import get +plexBaseURL = "http://10.0.0.41:32400/" 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): + plexSearch(query) + requestType = "search/multi?" requestAPI = "api_key=" + "9fa154f5355c37a1b9b57ac06e7d6712" requestQuery = "&query=" + str(query) @@ -17,12 +41,42 @@ def tmdbSearch(query, page=1): requestPage = "&page="+str(page) 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) - print(response.status_code) 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__": - print(tmdbSearch("Big bang")) \ No newline at end of file + 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)) \ No newline at end of file