mirror of
				https://github.com/KevinMidboe/Node-Com-Handler.git
				synced 2025-10-29 17:50:27 +00:00 
			
		
		
		
	Added plexpy directory and plex watching script
This commit is contained in:
		
							
								
								
									
										0
									
								
								v1/plexPy/plexPlaying.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								v1/plexPy/plexPlaying.xml
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										55
									
								
								v1/plex_watching.py
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										55
									
								
								v1/plex_watching.py
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,55 @@ | ||||
| #!/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:23:01 | ||||
|  | ||||
| from os import system | ||||
| import xml.etree.ElementTree as ET | ||||
|  | ||||
| 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(os.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__': | ||||
| 	plex_watching() | ||||
		Reference in New Issue
	
	Block a user