Methode "Kodiitem" flexibler gestaltet
This commit is contained in:
parent
48dfc09a3f
commit
70e5096563
1 changed files with 31 additions and 34 deletions
|
|
@ -5,8 +5,10 @@ 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")
|
print("Kodi-Objekt erzeugt")
|
||||||
|
self.a = self.JSON_holen()
|
||||||
|
|
||||||
def kodi_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())
|
||||||
|
|
@ -15,18 +17,15 @@ class kodi():
|
||||||
except:
|
except:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def kodi_suche_nach(self, suchstring,json=""):
|
def Suchen_nach(self, suchstring, json=""):
|
||||||
if json=="":
|
|
||||||
json=self.kodi_JSON_holen()
|
|
||||||
|
|
||||||
start = len(suchstring) + 3 # berechnet die Anfangsposition des Wertes
|
start = len(suchstring) + 3 # berechnet die Anfangsposition des Wertes
|
||||||
ende = len(json) # gibt die Gesamtlänge der URL Antwort an
|
ende = len(self.a) # gibt die Gesamtlänge der URL Antwort an
|
||||||
position = json.find("\"" + suchstring, 46,
|
position = self.a.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 = json.find(",\"", position,
|
position2 = self.a.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 = (json[position + start:position2]) # gibt den Wert des Suchbegriffes aus
|
wert = (self.a[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("\"}][{")
|
||||||
|
|
@ -34,38 +33,36 @@ class kodi():
|
||||||
return wert
|
return wert
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def kodiitem(self):
|
def kodiitem(self,koditems = {"episode": "", "fanart": "", "file": "", "label": "", "season": "", "showtitle": "", "type": "",
|
||||||
koditems = {"episode": "", "fanart": "", "file": "", "label": "", "season": "", "showtitle": "", "type": "",
|
"title": "", "id": "", "width": ""}):
|
||||||
"title": "", "id": "", "width": ""}
|
a = self.JSON_holen()
|
||||||
a = self.kodi_JSON_holen()
|
|
||||||
if a != None:
|
if a != None:
|
||||||
for i in koditems:
|
for i in koditems:
|
||||||
string = self.kodi_suche_nach(i,a)
|
string = self.Suchen_nach(i, a)
|
||||||
if type(string)==str:
|
if type(string)==str:
|
||||||
string = string.replace("ä", "ae").replace("Ä", "Ae").replace("ö", "oe").replace("Ö", "oe").replace(
|
string = string.replace("ä", "ae").replace("Ä", "Ae").replace("ö", "oe").replace("Ö", "oe").replace(
|
||||||
"ü", "ue").replace("Ü", "Ue").replace(" ", "_")
|
"ü", "ue").replace("Ü", "Ue").replace(" ", "_")
|
||||||
elif string == None:
|
elif string == None:
|
||||||
string =""
|
string =""
|
||||||
koditems[i] = string
|
koditems[i] = string
|
||||||
if koditems["type"] == "episode":
|
if "type" in koditems:
|
||||||
if len(koditems["season"]) == 1:
|
if koditems["type"] == "episode":
|
||||||
koditems["season"] = "S0" + koditems["season"]
|
if len(koditems["season"]) == 1:
|
||||||
else:
|
koditems["season"] = "S0" + koditems["season"]
|
||||||
koditems["season"] = "S" + koditems["season"]
|
else:
|
||||||
if len(koditems["episode"]) == 1:
|
koditems["season"] = "S" + koditems["season"]
|
||||||
koditems["episode"] = "E0" + koditems["episode"]
|
if len(koditems["episode"]) == 1:
|
||||||
else:
|
koditems["episode"] = "E0" + koditems["episode"]
|
||||||
koditems["episode"] = "E" + koditems["episode"]
|
else:
|
||||||
elif koditems["type"] == "movie":
|
koditems["episode"] = "E" + koditems["episode"]
|
||||||
koditems["season"] = ""
|
elif koditems["type"] == "movie":
|
||||||
koditems["episode"] = ""
|
koditems["season"] = ""
|
||||||
elif koditems["type"] == "unknown":
|
koditems["episode"] = ""
|
||||||
koditems["season"] = ""
|
elif koditems["type"] == "unknown":
|
||||||
koditems["episode"] = ""
|
koditems["season"] = ""
|
||||||
|
koditems["episode"] = ""
|
||||||
return koditems
|
return koditems
|
||||||
|
koditems = {"episode": "", "width": "","label": ""}
|
||||||
a = kodi("10.0.1.102")
|
a = kodi("10.0.1.102")
|
||||||
print(a.kodi_JSON_holen())
|
|
||||||
print(a.kodi_suche_nach("type"))
|
print(a.kodiitem(koditems))
|
||||||
print(a.kodiitem())
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue