mirror of
https://github.com/KevinMidboe/Node-Com-Handler.git
synced 2025-10-29 09:40:27 +00:00
Major cleanup, added all old files (python2) to 'old_v0.1' folder
This commit is contained in:
83
plex/plexMovies.py
Executable file
83
plex/plexMovies.py
Executable file
@@ -0,0 +1,83 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Author: KevinMidboe
|
||||
# @Date: 2017-01-28 23:21:22
|
||||
# @Last Modified by: KevinMidboe
|
||||
# @Last Modified time: 2017-02-06 11:58:31
|
||||
|
||||
from os import system
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
import sys
|
||||
|
||||
from time import time
|
||||
|
||||
def getLibraryXML():
|
||||
# Every call saves the info of session.xml to a file named plexPlaying
|
||||
system('curl --silent http://10.0.0.41:32400/library/sections/1/all > xmlMovieLib.xml')
|
||||
# XML parsing, creates a tree and saves the root node as root
|
||||
try:
|
||||
parser = ET.parse('xmlMovieLib.xml')
|
||||
xmlTreeRoot = parser.getroot()
|
||||
return xmlTreeRoot
|
||||
|
||||
except xml.etree.ElementTree.ParseError:
|
||||
return None
|
||||
|
||||
def getMovieExistance():
|
||||
pass
|
||||
|
||||
def getSpecificMovieInfo(movieTitle, movieYear=None):
|
||||
xmlTreeRoot = getLibraryXML()
|
||||
|
||||
try:
|
||||
treeSize = int(xmlTreeRoot.get('size'))
|
||||
except TypeError:
|
||||
return None
|
||||
|
||||
|
||||
if (treeSize > 0):
|
||||
for video in xmlTreeRoot.findall('Video'):
|
||||
if video.get('title') == movieTitle:
|
||||
title = movieTitle
|
||||
year = video.get('year')
|
||||
if movieYear == None or movieYear == year:
|
||||
mediaInfo = video.find('Media')
|
||||
bitrate = mediaInfo.get('bitrate')
|
||||
width = mediaInfo.get('width')
|
||||
height = mediaInfo.get('height')
|
||||
|
||||
return { 'title':title, 'year': year, 'bitrate':bitrate,
|
||||
'width':width, 'height':height }
|
||||
else:
|
||||
# field: 404?
|
||||
return { 'Error': 'Movie matching that year does not exist, did '\
|
||||
'you mean ' + title + ' (' + year + ')?'}
|
||||
|
||||
# Return none
|
||||
|
||||
def plexMovies(xmlTreeRoot, query='title'):
|
||||
test = int(xmlTreeRoot.get('size'))
|
||||
sys.exit()
|
||||
# The root node named MediaContainer has a size variable that holds number of active processes.
|
||||
# If this is '0' then there are none playing, no need to compute.
|
||||
if (root.get('size') != '0'):
|
||||
# Goes through all the 'video' elements in MediaContainer
|
||||
for video in root.findall('Video'):
|
||||
if query=='title' or query=='year':
|
||||
result = video.get(query)
|
||||
print(result)
|
||||
|
||||
elif query=='bitrate' or query=='width' or query=='height':
|
||||
mediaInfo = video.find('Media')
|
||||
result = mediaInfo.get(query)
|
||||
print(result)
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Query: !title, !year, bitrate, width, height
|
||||
start_time = time()
|
||||
# xmlTreeRoot = getLibraryXML()
|
||||
# plexMovies(xmlTreeRoot)
|
||||
|
||||
print(getSpecificMovieInfo('10 Cloverfield Lane'))
|
||||
print("--- %s seconds ---" % (time() - start_time))
|
||||
69
plex/plexSearch.py
Executable file
69
plex/plexSearch.py
Executable file
@@ -0,0 +1,69 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Author: KevinMidboe
|
||||
# @Date: 2017-02-08 14:00:04
|
||||
# @Last Modified by: KevinMidboe
|
||||
# @Last Modified time: 2017-02-08 14:06:48
|
||||
|
||||
from requests import get
|
||||
|
||||
plexBaseURL = "http://10.0.0.41:32400/"
|
||||
|
||||
def getMovieInfo(item):
|
||||
title = item["title"]
|
||||
year = item["year"]
|
||||
rating = item["rating"]
|
||||
art = item["art"]
|
||||
thumb = item["thumb"]
|
||||
|
||||
for mediaInfo in item["_children"]:
|
||||
if mediaInfo["_elementType"] == "Media":
|
||||
container = mediaInfo["container"]
|
||||
resolution = mediaInfo["videoResolution"]
|
||||
bitrate = mediaInfo["bitrate"]
|
||||
videoCodec = mediaInfo["videoCodec"]
|
||||
videoFrameRate = mediaInfo["videoFrameRate"]
|
||||
|
||||
return {"title":title, "year":year, "rating":rating, "container":container,
|
||||
"resolution":resolution, "bitrate":bitrate, "videoCodec":videoCodec,
|
||||
"videoFrameRate":videoFrameRate, "art":art, "thumb":thumb}
|
||||
|
||||
def getShowInfo(item):
|
||||
media = []
|
||||
|
||||
title = item["title"]
|
||||
year = item["year"]
|
||||
rating = item["rating"]
|
||||
art = item["art"]
|
||||
thumb = item["thumb"]
|
||||
seasons = item["childCount"]
|
||||
episodes = item["leafCount"]
|
||||
|
||||
return {"title":title, "year":year, "seasons":seasons, "episodes":episodes, "rating":rating,
|
||||
"art":art, "thumb":thumb}
|
||||
|
||||
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()
|
||||
media = []
|
||||
|
||||
for child in resContent["_children"]:
|
||||
cType = child["type"]
|
||||
if cType == "movie":
|
||||
media.append(getMovieInfo(child))
|
||||
elif cType == "show":
|
||||
media.append(getShowInfo(child))
|
||||
|
||||
return media
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(plexSearch("star+wars"))
|
||||
56
plex/plex_watching.py
Executable file
56
plex/plex_watching.py
Executable file
@@ -0,0 +1,56 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Author: KevinMidboe
|
||||
# @Date: 2017-01-28 23:21:22
|
||||
# @Last Modified by: KevinMidboe
|
||||
# @Last Modified time: 2017-01-28 23:35:04
|
||||
|
||||
from os import system, popen
|
||||
import xml.etree.ElementTree as ET
|
||||
from unicodedata import normalize
|
||||
|
||||
def plex_watching():
|
||||
# Every call saves the info of session.xml to a file named plexPlaying
|
||||
system('curl --silent 10.0.0.41:32400/status/sessions > plexPy/plexPlaying.xml')
|
||||
|
||||
# XML parsing, creates a tree and saves the root node as root
|
||||
tree = ET.parse('plexPy/plexPlaying.xml')
|
||||
root = tree.getroot()
|
||||
|
||||
# The root node named MediaContainer has a size variable that holds number of active processes.
|
||||
# If this is '0' then there are none playing, no need to compute.
|
||||
if (root.get('size') != '0'):
|
||||
|
||||
# Get load of CPU and I/O
|
||||
return_text = '\n\t' + str(popen('cat /proc/loadavg').read())
|
||||
return_text += '\tCur: \t' + str(root.get('size')) + '\n'
|
||||
|
||||
# Goes through all the 'video' elements in MediaContainer
|
||||
for video in root.findall('Video'):
|
||||
if (video.get('type') == 'movie'):
|
||||
name = video.get('title')
|
||||
return_text += '\n\tTitle: \t' + name
|
||||
|
||||
elif (video.get('type') == 'episode'):
|
||||
parentName = video.get('grandparentTitle')
|
||||
name = video.get('title')
|
||||
return_text += '\n\tTitle: \t' + name + \
|
||||
'\n\tSeries: ' + parentName
|
||||
|
||||
progress = "{0:0.1f}".format(float(video.find('TranscodeSession').get('progress')))
|
||||
state = video.find('Player').get('state')
|
||||
player = video.find('Player').get('platform')
|
||||
user = video.find('User').get('title')
|
||||
|
||||
return_text += str('\n\tProg : \t' + str(progress) + '\n\tPlayer: ' + player + \
|
||||
'\n\tState: \t' + state + '\n\tUser: \t' + user + '\n')
|
||||
|
||||
try:
|
||||
return normalize('NFKD', return_text).encode('ascii', 'ignore')
|
||||
except TypeError:
|
||||
return return_text
|
||||
else:
|
||||
return 'Null playing'
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(plex_watching())
|
||||
58
plex/tmdb.py
Executable file
58
plex/tmdb.py
Executable file
@@ -0,0 +1,58 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Author: KevinMidboe
|
||||
# @Date: 2017-02-08 14:00:04
|
||||
# @Last Modified by: KevinMidboe
|
||||
# @Last Modified time: 2017-02-08 14:06:48
|
||||
|
||||
from requests import get
|
||||
|
||||
tmdbBaseURL = "https://api.themoviedb.org/3/"
|
||||
|
||||
def tmdbSearch(query, page=1):
|
||||
requestType = "search/multi?"
|
||||
requestAPI = "api_key=" + "9fa154f5355c37a1b9b57ac06e7d6712"
|
||||
requestQuery = "&query=" + str(query)
|
||||
requestLanguage = "&language=en.US"
|
||||
requestPage = "&page="+str(page)
|
||||
|
||||
url = tmdbBaseURL + requestType + requestAPI + requestQuery + requestLanguage + requestPage
|
||||
print(url)
|
||||
|
||||
response = get(url)
|
||||
if response.status_code == 200:
|
||||
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__":
|
||||
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