mirror of
				https://github.com/KevinMidboe/Node-Com-Handler.git
				synced 2025-10-29 17:50: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:
		| @@ -3,9 +3,10 @@ | ||||
| # @Author: KevinMidboe | ||||
| # @Date:   2017-02-08 14:00:04 | ||||
| # @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/" | ||||
|  | ||||
| @@ -42,21 +43,36 @@ def getShowInfo(item): | ||||
| 	return {"title":title, "year":year, "seasons":seasons, "episodes":episodes, "rating":rating, | ||||
| 		"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 | ||||
| # Seems to be a change in the return obj. | ||||
| # This looks way more like json. Need to re-write all this. | ||||
| # IDEA: Send the size and resolution for comaprison | ||||
| # No this is for a admin page. OR maybe a github project for  | ||||
| # people wanting to update movies. MAJOR IDEA HERE NOW! :D | ||||
| def plexSearch(query): | ||||
| def plexXMLSearch(query): | ||||
| 	print(query) | ||||
| 	requestType = "search?" | ||||
| 	requestQuery = "query=" + str(query) | ||||
| 	header = {'Accept': 'application/json'} | ||||
|  | ||||
| 	url = plexBaseURL + requestType + requestQuery | ||||
| 	response = get(url, headers=header) | ||||
| 	print(response.json()) | ||||
| 	response = requests.get(url, headers=header) | ||||
|  | ||||
| 	pprint(response.json()) | ||||
| 	if response.status_code == 200: | ||||
| 		resContent = response.json() | ||||
| 		media = [] | ||||
| @@ -74,7 +90,4 @@ def plexSearch(query): | ||||
|  | ||||
| if __name__ == "__main__": | ||||
| 	# print(plexSearch("star+wars")) | ||||
| 	tiss = plexSearch("star+wars") | ||||
| 	for al in tiss: | ||||
| 		if (al['year']==2015): | ||||
| 			print('thishsihis') | ||||
| 	pprint(plexSearch("star")) | ||||
|   | ||||
							
								
								
									
										79
									
								
								plex/tmdb.py
									
									
									
									
									
								
							
							
						
						
									
										79
									
								
								plex/tmdb.py
									
									
									
									
									
								
							| @@ -3,77 +3,48 @@ | ||||
| # @Author: KevinMidboe | ||||
| # @Date:   2017-02-08 14:00:04 | ||||
| # @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: | ||||
| 	from plexSearch import plexSearch | ||||
| except ImportError: | ||||
| 	from plex.plexSearch import plexSearch | ||||
|  | ||||
| tmdbBaseURL = "https://api.themoviedb.org/3/" | ||||
|  | ||||
| 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 } | ||||
| apiKey = "9fa154f5355c37a1b9b57ac06e7d6712" | ||||
|  | ||||
|  | ||||
| def tmdbSearch(query, page=1): | ||||
| 	requestType = "search/multi?" | ||||
| 	requestAPI = "api_key=" + "9fa154f5355c37a1b9b57ac06e7d6712" | ||||
| 	requestQuery = "&query=" + str(query) | ||||
| 	requestLanguage = "&language=en.US" | ||||
| 	requestPage = "&page="+str(page) | ||||
| 	payload = {"api_key":apiKey, "query":str(query), "language":"en.US", "page":str(page), } | ||||
| 	header = {'Accept': 'application/json'} | ||||
|  | ||||
| 	url = tmdbBaseURL + requestType + requestAPI + requestQuery + requestLanguage + requestPage | ||||
| 	print(url) | ||||
| 	try: | ||||
| 		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 response.status_code == 200: | ||||
| 		resContent = response.json() | ||||
| 	if r.status_code == 401: | ||||
| 		return {"errors": "api key is not valid."} | ||||
| 	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) | ||||
| 		tmdbSearchRes = createTMDBResultList(resContent) | ||||
|  | ||||
| 		return checkPlexExistance(tmdbSearchRes, plexSearchRes) | ||||
| 	return r.json() | ||||
|  | ||||
|  | ||||
| if __name__ == "__main__": | ||||
| 	import sys | ||||
| 	print(sys.argv) | ||||
| 	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: | ||||
| 		print(tmdbSearch(sys.argv[1])) | ||||
| 		pprint(tmdbSearch(sys.argv[1])) | ||||
| 	else: | ||||
| 		print(tmdbSearch("star+wars",1)) | ||||
| 		pprint(tmdbSearch("star+wars",1)) | ||||
		Reference in New Issue
	
	Block a user