a liitle bit of PEP8
This commit is contained in:
parent
70e5096563
commit
5951b3d840
1 changed files with 21 additions and 15 deletions
|
|
@ -4,28 +4,32 @@ import time
|
||||||
class kodi():
|
class kodi():
|
||||||
def __init__(self,url):
|
def __init__(self,url):
|
||||||
self.kodiurl="http://"+url+"/jsonrpc?request=%7B%22jsonrpc%22:%20%222.0%22,%20%22method%22:%20%22Player.GetItem%22,%20%22params%22:%20%7B%20%22properties%22:%20%5B%22title%22,%20%22album%22,%20%22artist%22,%20%22season%22,%20%22episode%22,%20%22duration%22,%20%22showtitle%22,%20%22tvshowid%22,%20%22thumbnail%22,%20%22file%22,%20%22fanart%22,%20%22streamdetails%22%5D,%20%22playerid%22:%201%20%7D,%20%22id%22:%20%22VideoGetItem%22%7D"
|
self.kodiurl="http://"+url+"/jsonrpc?request=%7B%22jsonrpc%22:%20%222.0%22,%20%22method%22:%20%22Player.GetItem%22,%20%22params%22:%20%7B%20%22properties%22:%20%5B%22title%22,%20%22album%22,%20%22artist%22,%20%22season%22,%20%22episode%22,%20%22duration%22,%20%22showtitle%22,%20%22tvshowid%22,%20%22thumbnail%22,%20%22file%22,%20%22fanart%22,%20%22streamdetails%22%5D,%20%22playerid%22:%201%20%7D,%20%22id%22:%20%22VideoGetItem%22%7D"
|
||||||
print("Kodi-Objekt erzeugt")
|
self.jsonString = self.JSON_holen
|
||||||
self.a = self.JSON_holen()
|
|
||||||
|
|
||||||
|
|
||||||
|
@property
|
||||||
def JSON_holen(self):
|
def JSON_holen(self):
|
||||||
try:
|
try:
|
||||||
antwort = urllib.request.urlopen(self.kodiurl)
|
antwort = urllib.request.urlopen(self.kodiurl)
|
||||||
b = (antwort.read())
|
b = (antwort.read())
|
||||||
a = b.decode("utf-8")
|
self.jsonString = b.decode("utf-8")
|
||||||
return a
|
return self.jsonString
|
||||||
except:
|
except:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def Suchen_nach(self, suchstring, json=""):
|
def Suchen_nach(self, suchstring, json=""):
|
||||||
|
if json=="":
|
||||||
|
self.jsonString=self.JSON_holen
|
||||||
|
print("neues JSON geholt")
|
||||||
|
else:
|
||||||
|
self.jsonString=json
|
||||||
start = len(suchstring) + 3 # berechnet die Anfangsposition des Wertes
|
start = len(suchstring) + 3 # berechnet die Anfangsposition des Wertes
|
||||||
ende = len(self.a) # gibt die Gesamtlänge der URL Antwort an
|
ende = len(self.jsonString) # gibt die Gesamtlänge der URL Antwort an
|
||||||
position = self.a.find("\"" + suchstring, 46,
|
position = self.jsonString.find("\"" + suchstring, 46,
|
||||||
ende) # sucht in der gesamten URL Antwort nach dem Suchbegriff und ermittelt dessen Position im String (Anfang)
|
ende) # sucht in der gesamten URL Antwort nach dem Suchbegriff und ermittelt dessen Position im String (Anfang)
|
||||||
if position > 0:
|
if position > 0:
|
||||||
position2 = self.a.find(",\"", position,
|
position2 = self.jsonString.find(",\"", position,
|
||||||
ende) # sucht anhand der Anfangspos. des Suchstrings nach dem Ende des dazugehörigen Wertes (endet mit ,")
|
ende) # sucht anhand der Anfangspos. des Suchstrings nach dem Ende des dazugehörigen Wertes (endet mit ,")
|
||||||
wert = (self.a[position + start:position2]) # gibt den Wert des Suchbegriffes aus
|
wert = (self.jsonString[position + start:position2]) # gibt den Wert des Suchbegriffes aus
|
||||||
x = 0
|
x = 0
|
||||||
while wert.isalnum() is False and x < 2:
|
while wert.isalnum() is False and x < 2:
|
||||||
wert = wert.strip("\"}][{")
|
wert = wert.strip("\"}][{")
|
||||||
|
|
@ -33,9 +37,10 @@ class kodi():
|
||||||
return wert
|
return wert
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def kodiitem(self,koditems = {"episode": "", "fanart": "", "file": "", "label": "", "season": "", "showtitle": "", "type": "",
|
def kodiitem(self, koditems=None):
|
||||||
"title": "", "id": "", "width": ""}):
|
if koditems is None:
|
||||||
a = self.JSON_holen()
|
koditems = {"episode": "", "label": "", "season": "", "showtitle": "", "type": "", "title": ""}
|
||||||
|
a = self.JSON_holen
|
||||||
if a != None:
|
if a != None:
|
||||||
for i in koditems:
|
for i in koditems:
|
||||||
string = self.Suchen_nach(i, a)
|
string = self.Suchen_nach(i, a)
|
||||||
|
|
@ -62,7 +67,8 @@ class kodi():
|
||||||
koditems["season"] = ""
|
koditems["season"] = ""
|
||||||
koditems["episode"] = ""
|
koditems["episode"] = ""
|
||||||
return koditems
|
return koditems
|
||||||
|
|
||||||
koditems = {"episode": "", "width": "","label": ""}
|
koditems = {"episode": "", "width": "","label": ""}
|
||||||
a = kodi("10.0.1.102")
|
a = kodi("10.0.1.102")
|
||||||
|
|
||||||
print(a.kodiitem(koditems))
|
print(a.kodiitem())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue