mirror of
https://github.com/KevinMidboe/Node-Com-Handler.git
synced 2025-10-29 09:40:27 +00:00
Changed from the plex scripts doing the comparisson to letting the client or another seperate script to it.
This commit is contained in:
8
app.py
8
app.py
@@ -52,7 +52,7 @@ def get_pw(username):
|
|||||||
# to not match.
|
# to not match.
|
||||||
@auth.error_handler
|
@auth.error_handler
|
||||||
def unauthorized():
|
def unauthorized():
|
||||||
return make_response(jsonify({'error': 'Unauthorized access'}), 401)
|
return make_response(jsonify({'errors': 'Unauthorized access'}), 401)
|
||||||
|
|
||||||
# This would be replaced with a database, but single process and thread
|
# This would be replaced with a database, but single process and thread
|
||||||
# can use local data like this for simplicity.
|
# can use local data like this for simplicity.
|
||||||
@@ -61,10 +61,10 @@ def unauthorized():
|
|||||||
# Want all return data to be JSON so create custom error response
|
# Want all return data to be JSON so create custom error response
|
||||||
@app.errorhandler(404)
|
@app.errorhandler(404)
|
||||||
def not_found(error):
|
def not_found(error):
|
||||||
return make_response(jsonify({'error': 'Not found'}), 404)
|
return make_response(jsonify({'errors': 'Not found'}), 404)
|
||||||
@app.errorhandler(400)
|
@app.errorhandler(400)
|
||||||
def bad_request(error):
|
def bad_request(error):
|
||||||
return make_response(jsonify({'error': 'Bad request'}), 400)
|
return make_response(jsonify({'errors': 'Bad request'}), 400)
|
||||||
|
|
||||||
|
|
||||||
# --- Apollo Activity --- #
|
# --- Apollo Activity --- #
|
||||||
@@ -96,7 +96,7 @@ def get_movieRequest():
|
|||||||
# TODO if list is empty
|
# TODO if list is empty
|
||||||
return jsonify(tmdbSearch(query))
|
return jsonify(tmdbSearch(query))
|
||||||
|
|
||||||
else: return jsonify({ "Error": "Query not defined." })
|
else: return jsonify({ "errors": "Query not defined." })
|
||||||
|
|
||||||
@app.route('/api/v1/plex/movies', methods=['GET'])
|
@app.route('/api/v1/plex/movies', methods=['GET'])
|
||||||
def getPlexMovies():
|
def getPlexMovies():
|
||||||
|
|||||||
@@ -3,9 +3,10 @@
|
|||||||
# @Author: KevinMidboe
|
# @Author: KevinMidboe
|
||||||
# @Date: 2017-02-08 14:00:04
|
# @Date: 2017-02-08 14:00:04
|
||||||
# @Last Modified by: KevinMidboe
|
# @Last Modified by: KevinMidboe
|
||||||
# @Last Modified time: 2017-02-10 01:31:43
|
# @Last Modified time: 2017-02-18 11:37:08
|
||||||
|
|
||||||
from requests import get
|
import requests
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
plexBaseURL = "http://10.0.0.41:32400/"
|
plexBaseURL = "http://10.0.0.41:32400/"
|
||||||
|
|
||||||
@@ -42,21 +43,36 @@ def getShowInfo(item):
|
|||||||
return {"title":title, "year":year, "seasons":seasons, "episodes":episodes, "rating":rating,
|
return {"title":title, "year":year, "seasons":seasons, "episodes":episodes, "rating":rating,
|
||||||
"art":art, "thumb":thumb}
|
"art":art, "thumb":thumb}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def plexSearch(query):
|
||||||
|
payload = {"query":query, "type":"1,2"}
|
||||||
|
header = {'Accept': 'application/json'}
|
||||||
|
r = requests.get(plexBaseURL+"search",params=payload, headers=header)
|
||||||
|
|
||||||
|
rObject = r.json()["MediaContainer"]
|
||||||
|
if (r.status_code != requests.codes.ok or rObject["size"] == 0):
|
||||||
|
return {"errors": "Nothing found for query: " + query}
|
||||||
|
|
||||||
|
return rObject["Metadata"]
|
||||||
|
|
||||||
|
|
||||||
## MAJOR TODO
|
## MAJOR TODO
|
||||||
# Seems to be a change in the return obj.
|
# Seems to be a change in the return obj.
|
||||||
# This looks way more like json. Need to re-write all this.
|
# This looks way more like json. Need to re-write all this.
|
||||||
# IDEA: Send the size and resolution for comaprison
|
# IDEA: Send the size and resolution for comaprison
|
||||||
# No this is for a admin page. OR maybe a github project for
|
# No this is for a admin page. OR maybe a github project for
|
||||||
# people wanting to update movies. MAJOR IDEA HERE NOW! :D
|
# people wanting to update movies. MAJOR IDEA HERE NOW! :D
|
||||||
def plexSearch(query):
|
def plexXMLSearch(query):
|
||||||
|
print(query)
|
||||||
requestType = "search?"
|
requestType = "search?"
|
||||||
requestQuery = "query=" + str(query)
|
requestQuery = "query=" + str(query)
|
||||||
header = {'Accept': 'application/json'}
|
header = {'Accept': 'application/json'}
|
||||||
|
|
||||||
url = plexBaseURL + requestType + requestQuery
|
url = plexBaseURL + requestType + requestQuery
|
||||||
response = get(url, headers=header)
|
response = requests.get(url, headers=header)
|
||||||
print(response.json())
|
|
||||||
|
|
||||||
|
pprint(response.json())
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
resContent = response.json()
|
resContent = response.json()
|
||||||
media = []
|
media = []
|
||||||
@@ -74,7 +90,4 @@ def plexSearch(query):
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# print(plexSearch("star+wars"))
|
# print(plexSearch("star+wars"))
|
||||||
tiss = plexSearch("star+wars")
|
pprint(plexSearch("star"))
|
||||||
for al in tiss:
|
|
||||||
if (al['year']==2015):
|
|
||||||
print('thishsihis')
|
|
||||||
|
|||||||
79
plex/tmdb.py
79
plex/tmdb.py
@@ -3,77 +3,48 @@
|
|||||||
# @Author: KevinMidboe
|
# @Author: KevinMidboe
|
||||||
# @Date: 2017-02-08 14:00:04
|
# @Date: 2017-02-08 14:00:04
|
||||||
# @Last Modified by: KevinMidboe
|
# @Last Modified by: KevinMidboe
|
||||||
# @Last Modified time: 2017-02-08 23:19:53
|
# @Last Modified time: 2017-02-16 17:08:08
|
||||||
|
|
||||||
from requests import get
|
import requests
|
||||||
|
from pprint import pprint
|
||||||
try:
|
try:
|
||||||
from plexSearch import plexSearch
|
from plexSearch import plexSearch
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from plex.plexSearch import plexSearch
|
from plex.plexSearch import plexSearch
|
||||||
|
|
||||||
tmdbBaseURL = "https://api.themoviedb.org/3/"
|
apiKey = "9fa154f5355c37a1b9b57ac06e7d6712"
|
||||||
|
|
||||||
def checkPlexExistance(tmdb, plex):
|
|
||||||
# THIS IS ONLY COMPARED ON YEAR
|
|
||||||
yearList = [movie["year"] for movie in plex]
|
|
||||||
print(yearList)
|
|
||||||
|
|
||||||
for movie in tmdb["movies"]:
|
|
||||||
print(movie["year"])
|
|
||||||
movie["exists"] = movie["year"] in str(yearList)
|
|
||||||
|
|
||||||
return tmdb
|
|
||||||
|
|
||||||
def createTMDBResultList(resContent):
|
|
||||||
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})
|
|
||||||
|
|
||||||
return { "movies": movies, "tvshows": tvshows }
|
|
||||||
|
|
||||||
|
|
||||||
def tmdbSearch(query, page=1):
|
def tmdbSearch(query, page=1):
|
||||||
requestType = "search/multi?"
|
payload = {"api_key":apiKey, "query":str(query), "language":"en.US", "page":str(page), }
|
||||||
requestAPI = "api_key=" + "9fa154f5355c37a1b9b57ac06e7d6712"
|
header = {'Accept': 'application/json'}
|
||||||
requestQuery = "&query=" + str(query)
|
|
||||||
requestLanguage = "&language=en.US"
|
|
||||||
requestPage = "&page="+str(page)
|
|
||||||
|
|
||||||
url = tmdbBaseURL + requestType + requestAPI + requestQuery + requestLanguage + requestPage
|
try:
|
||||||
print(url)
|
r = requests.get("https://api.themoviedb.org/3/search/multi", params=payload, headers=header)
|
||||||
|
except requests.exceptions.ConnectionError:
|
||||||
|
return {"errors": "Could not connecting to: tmdb.com"}
|
||||||
|
except requests.exceptions.Timeout:
|
||||||
|
return {"errors": "Request timed out."}
|
||||||
|
except requests.exceptions.TooManyRedirects:
|
||||||
|
return {"errors": "Too many redirects, do you full network access?"}
|
||||||
|
|
||||||
response = get(url)
|
if r.status_code == 401:
|
||||||
if response.status_code == 200:
|
return {"errors": "api key is not valid."}
|
||||||
resContent = response.json()
|
elif r.status_code == 404:
|
||||||
|
return {"errors": "Please check url. (404)"}
|
||||||
|
elif r.status_code == requests.codes.ok and r.json()['total_results'] == 0:
|
||||||
|
return {"errors": "No results found."}
|
||||||
|
|
||||||
|
|
||||||
plexSearchRes = plexSearch(query)
|
return r.json()
|
||||||
tmdbSearchRes = createTMDBResultList(resContent)
|
|
||||||
|
|
||||||
return checkPlexExistance(tmdbSearchRes, plexSearchRes)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import sys
|
import sys
|
||||||
print(sys.argv)
|
print(sys.argv)
|
||||||
if len(sys.argv) > 2:
|
if len(sys.argv) > 2:
|
||||||
print(tmdbSearch(sys.argv[1], int(sys.argv[2])))
|
pprint(tmdbSearch(sys.argv[1], int(sys.argv[2])))
|
||||||
elif len(sys.argv) > 1:
|
elif len(sys.argv) > 1:
|
||||||
print(tmdbSearch(sys.argv[1]))
|
pprint(tmdbSearch(sys.argv[1]))
|
||||||
else:
|
else:
|
||||||
print(tmdbSearch("star+wars",1))
|
pprint(tmdbSearch("star+wars",1))
|
||||||
Reference in New Issue
Block a user