Refactor 1/4
This commit is contained in:
parent
ed77944543
commit
ed784bfcd9
2 changed files with 134 additions and 120 deletions
|
@ -23,6 +23,7 @@ import xml.etree.cElementTree as ET
|
||||||
from API import API
|
from API import API
|
||||||
import Utils as utils
|
import Utils as utils
|
||||||
from DownloadUtils import DownloadUtils
|
from DownloadUtils import DownloadUtils
|
||||||
|
from ReadEmbyDB import ReadEmbyDB
|
||||||
|
|
||||||
addon = xbmcaddon.Addon(id='plugin.video.mb3sync')
|
addon = xbmcaddon.Addon(id='plugin.video.mb3sync')
|
||||||
addondir = xbmc.translatePath(addon.getAddonInfo('profile'))
|
addondir = xbmc.translatePath(addon.getAddonInfo('profile'))
|
||||||
|
@ -58,10 +59,10 @@ class LibrarySync():
|
||||||
if processMovies:
|
if processMovies:
|
||||||
allMovies = list()
|
allMovies = list()
|
||||||
|
|
||||||
views = self.getCollections("movies")
|
views = ReadEmbyDB().getCollections("movies")
|
||||||
for view in views:
|
for view in views:
|
||||||
|
|
||||||
movieData = self.getMovies(view.get('id'), True)
|
movieData = ReadEmbyDB().getMovies(view.get('id'), True)
|
||||||
|
|
||||||
if(self.ShouldStop()):
|
if(self.ShouldStop()):
|
||||||
return True
|
return True
|
||||||
|
@ -103,7 +104,7 @@ class LibrarySync():
|
||||||
if processTvShows:
|
if processTvShows:
|
||||||
allTVShows = list()
|
allTVShows = list()
|
||||||
allEpisodes = list()
|
allEpisodes = list()
|
||||||
tvShowData = self.getTVShows(True)
|
tvShowData = ReadEmbyDB().getTVShows(True)
|
||||||
|
|
||||||
if(self.ShouldStop()):
|
if(self.ShouldStop()):
|
||||||
return True
|
return True
|
||||||
|
@ -146,7 +147,7 @@ class LibrarySync():
|
||||||
|
|
||||||
for tvshow in allTVShows:
|
for tvshow in allTVShows:
|
||||||
|
|
||||||
episodeData = self.getEpisodes(tvshow,True)
|
episodeData = ReadEmbyDB().getEpisodes(tvshow,True)
|
||||||
kodiEpisodes = self.getKodiEpisodes(tvshow)
|
kodiEpisodes = self.getKodiEpisodes(tvshow)
|
||||||
|
|
||||||
if(self.ShouldStop()):
|
if(self.ShouldStop()):
|
||||||
|
@ -253,9 +254,9 @@ class LibrarySync():
|
||||||
|
|
||||||
#process movies
|
#process movies
|
||||||
if processMovies:
|
if processMovies:
|
||||||
views = self.getCollections("movies")
|
views = ReadEmbyDB().getCollections("movies")
|
||||||
for view in views:
|
for view in views:
|
||||||
movieData = self.getMovies(view.get('id'),False)
|
movieData = ReadEmbyDB().getMovies(view.get('id'),False)
|
||||||
|
|
||||||
if(self.ShouldStop()):
|
if(self.ShouldStop()):
|
||||||
return True
|
return True
|
||||||
|
@ -295,7 +296,7 @@ class LibrarySync():
|
||||||
|
|
||||||
#process Tv shows
|
#process Tv shows
|
||||||
if processTvShows:
|
if processTvShows:
|
||||||
tvshowData = self.getTVShows(False)
|
tvshowData = ReadEmbyDB().getTVShows(False)
|
||||||
|
|
||||||
if(self.ShouldStop()):
|
if(self.ShouldStop()):
|
||||||
return True
|
return True
|
||||||
|
@ -305,7 +306,7 @@ class LibrarySync():
|
||||||
|
|
||||||
for item in tvshowData:
|
for item in tvshowData:
|
||||||
xbmc.sleep(sleepVal)
|
xbmc.sleep(sleepVal)
|
||||||
episodeData = self.getEpisodes(item["Id"], False)
|
episodeData = ReadEmbyDB().getEpisodes(item["Id"], False)
|
||||||
|
|
||||||
if (episodeData != None):
|
if (episodeData != None):
|
||||||
if(pDialog != None):
|
if(pDialog != None):
|
||||||
|
@ -343,78 +344,6 @@ class LibrarySync():
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def getMovies(self, id, fullinfo = False):
|
|
||||||
result = None
|
|
||||||
|
|
||||||
addon = xbmcaddon.Addon(id='plugin.video.mb3sync')
|
|
||||||
port = addon.getSetting('port')
|
|
||||||
host = addon.getSetting('ipaddress')
|
|
||||||
server = host + ":" + port
|
|
||||||
|
|
||||||
downloadUtils = DownloadUtils()
|
|
||||||
userid = downloadUtils.getUserId()
|
|
||||||
|
|
||||||
if fullinfo:
|
|
||||||
url = server + '/mediabrowser/Users/' + userid + '/items?ParentId=' + id + '&SortBy=SortName&Fields=Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,CommunityRating,OfficialRating,CumulativeRunTimeTicks,Metascore,AirTime,DateCreated,MediaStreams,People,Overview&Recursive=true&SortOrder=Ascending&IncludeItemTypes=Movie&format=json&ImageTypeLimit=1'
|
|
||||||
else:
|
|
||||||
url = server + '/mediabrowser/Users/' + userid + '/items?ParentId=' + id + '&SortBy=SortName&Fields=CumulativeRunTimeTicks&Recursive=true&SortOrder=Ascending&IncludeItemTypes=Movie&format=json&ImageTypeLimit=1'
|
|
||||||
|
|
||||||
jsonData = downloadUtils.downloadUrl(url, suppress=True, popup=0)
|
|
||||||
if jsonData != None and jsonData != "":
|
|
||||||
result = json.loads(jsonData)
|
|
||||||
if(result.has_key('Items')):
|
|
||||||
result = result['Items']
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
def getTVShows(self, fullinfo = False):
|
|
||||||
result = None
|
|
||||||
|
|
||||||
addon = xbmcaddon.Addon(id='plugin.video.mb3sync')
|
|
||||||
port = addon.getSetting('port')
|
|
||||||
host = addon.getSetting('ipaddress')
|
|
||||||
server = host + ":" + port
|
|
||||||
|
|
||||||
downloadUtils = DownloadUtils()
|
|
||||||
userid = downloadUtils.getUserId()
|
|
||||||
|
|
||||||
if fullinfo:
|
|
||||||
url = server + '/mediabrowser/Users/' + userid + '/Items?&SortBy=SortName&Fields=Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,CommunityRating,OfficialRating,CumulativeRunTimeTicks,Metascore,AirTime,DateCreated,MediaStreams,People,Overview&Recursive=true&SortOrder=Ascending&IncludeItemTypes=Series&format=json&ImageTypeLimit=1'
|
|
||||||
else:
|
|
||||||
url = server + '/mediabrowser/Users/' + userid + '/Items?&SortBy=SortName&Fields=CumulativeRunTimeTicks&Recursive=true&SortOrder=Ascending&IncludeItemTypes=Series&format=json&ImageTypeLimit=1'
|
|
||||||
|
|
||||||
jsonData = downloadUtils.downloadUrl(url, suppress=True, popup=0)
|
|
||||||
if jsonData != None and jsonData != "":
|
|
||||||
result = json.loads(jsonData)
|
|
||||||
if(result.has_key('Items')):
|
|
||||||
result = result['Items']
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
def getEpisodes(self, showId, fullinfo = False):
|
|
||||||
result = None
|
|
||||||
|
|
||||||
addon = xbmcaddon.Addon(id='plugin.video.mb3sync')
|
|
||||||
port = addon.getSetting('port')
|
|
||||||
host = addon.getSetting('ipaddress')
|
|
||||||
server = host + ":" + port
|
|
||||||
|
|
||||||
downloadUtils = DownloadUtils()
|
|
||||||
userid = downloadUtils.getUserId()
|
|
||||||
|
|
||||||
if fullinfo:
|
|
||||||
url = server + '/mediabrowser/Users/' + userid + '/Items?ParentId=' + showId + '&IsVirtualUnaired=false&IsMissing=False&SortBy=SortName&Fields=Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,CommunityRating,OfficialRating,CumulativeRunTimeTicks,Metascore,AirTime,DateCreated,MediaStreams,People,Overview&Recursive=true&SortOrder=Ascending&IncludeItemTypes=Episode&format=json&ImageTypeLimit=1'
|
|
||||||
else:
|
|
||||||
url = server + '/mediabrowser/Users/' + userid + '/Items?ParentId=' + showId + '&IsVirtualUnaired=false&IsMissing=False&SortBy=SortName&Fields=Name,SortName,CumulativeRunTimeTicks&Recursive=true&SortOrder=Ascending&IncludeItemTypes=Episode&format=json&ImageTypeLimit=1'
|
|
||||||
|
|
||||||
jsonData = downloadUtils.downloadUrl(url, suppress=True, popup=0)
|
|
||||||
|
|
||||||
if jsonData != None and jsonData != "":
|
|
||||||
result = json.loads(jsonData)
|
|
||||||
if(result.has_key('Items')):
|
|
||||||
result = result['Items']
|
|
||||||
return result
|
|
||||||
|
|
||||||
def updatePlayCountFromKodi(self, id, playcount=0):
|
def updatePlayCountFromKodi(self, id, playcount=0):
|
||||||
#when user marks item watched from kodi interface update this to MB3
|
#when user marks item watched from kodi interface update this to MB3
|
||||||
|
|
||||||
|
@ -1146,47 +1075,7 @@ class LibrarySync():
|
||||||
episode = item
|
episode = item
|
||||||
|
|
||||||
return episode
|
return episode
|
||||||
|
|
||||||
|
|
||||||
def getCollections(self, type):
|
|
||||||
#Build a list of the user views
|
|
||||||
userid = DownloadUtils().getUserId()
|
|
||||||
addon = xbmcaddon.Addon(id='plugin.video.mb3sync')
|
|
||||||
port = addon.getSetting('port')
|
|
||||||
host = addon.getSetting('ipaddress')
|
|
||||||
server = host + ":" + port
|
|
||||||
|
|
||||||
viewsUrl = server + "/mediabrowser/Users/" + userid + "/Views?format=json&ImageTypeLimit=1"
|
|
||||||
jsonData = DownloadUtils().downloadUrl(viewsUrl, suppress=True, popup=0 )
|
|
||||||
|
|
||||||
if(jsonData != ""):
|
|
||||||
views = json.loads(jsonData)
|
|
||||||
views = views.get("Items")
|
|
||||||
collections=[]
|
|
||||||
for view in views:
|
|
||||||
if view.get("Type") == 'UserView': # Need to grab the real main node
|
|
||||||
newViewsUrl = server + '/mediabrowser/Users/' + userid + '/items?ParentId=' + view.get("Id") + '&SortBy=SortName&SortOrder=Ascending&format=json&ImageTypeLimit=1'
|
|
||||||
jsonData = DownloadUtils().downloadUrl(newViewsUrl, suppress=True, popup=0 )
|
|
||||||
if(jsonData != ""):
|
|
||||||
newViews = json.loads(jsonData)
|
|
||||||
newViews = newViews.get("Items")
|
|
||||||
for newView in newViews:
|
|
||||||
# There are multiple nodes in here like 'Latest', 'NextUp' - below we grab the full node.
|
|
||||||
if newView.get("CollectionType") == "MovieMovies" or newView.get("CollectionType") == "TvShowSeries":
|
|
||||||
view=newView
|
|
||||||
if(view.get("ChildCount") != 0):
|
|
||||||
Name =(view.get("Name")).encode('utf-8')
|
|
||||||
|
|
||||||
total = str(view.get("ChildCount"))
|
|
||||||
type = view.get("CollectionType")
|
|
||||||
if type == None:
|
|
||||||
type = "None" # User may not have declared the type
|
|
||||||
if type == type:
|
|
||||||
collections.append( {'title' : Name,
|
|
||||||
'type' : type,
|
|
||||||
'id' : view.get("Id")})
|
|
||||||
return collections
|
|
||||||
|
|
||||||
def ShouldStop(self):
|
def ShouldStop(self):
|
||||||
if(xbmc.Player().isPlaying() or xbmc.abortRequested):
|
if(xbmc.Player().isPlaying() or xbmc.abortRequested):
|
||||||
return True
|
return True
|
||||||
|
|
125
resources/lib/ReadEmbyDB.py
Normal file
125
resources/lib/ReadEmbyDB.py
Normal file
|
@ -0,0 +1,125 @@
|
||||||
|
#################################################################################################
|
||||||
|
# ReadEmbyDB
|
||||||
|
#################################################################################################
|
||||||
|
|
||||||
|
import xbmc
|
||||||
|
import xbmcgui
|
||||||
|
import xbmcaddon
|
||||||
|
import json
|
||||||
|
|
||||||
|
from DownloadUtils import DownloadUtils
|
||||||
|
|
||||||
|
addon = xbmcaddon.Addon(id='plugin.video.mb3sync')
|
||||||
|
|
||||||
|
class ReadEmbyDB():
|
||||||
|
def getMovies(self, id, fullinfo = False):
|
||||||
|
result = None
|
||||||
|
|
||||||
|
addon = xbmcaddon.Addon(id='plugin.video.mb3sync')
|
||||||
|
port = addon.getSetting('port')
|
||||||
|
host = addon.getSetting('ipaddress')
|
||||||
|
server = host + ":" + port
|
||||||
|
|
||||||
|
downloadUtils = DownloadUtils()
|
||||||
|
userid = downloadUtils.getUserId()
|
||||||
|
|
||||||
|
if fullinfo:
|
||||||
|
url = server + '/mediabrowser/Users/' + userid + '/items?ParentId=' + id + '&SortBy=SortName&Fields=Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,CommunityRating,OfficialRating,CumulativeRunTimeTicks,Metascore,AirTime,DateCreated,MediaStreams,People,Overview&Recursive=true&SortOrder=Ascending&IncludeItemTypes=Movie&format=json&ImageTypeLimit=1'
|
||||||
|
else:
|
||||||
|
url = server + '/mediabrowser/Users/' + userid + '/items?ParentId=' + id + '&SortBy=SortName&Fields=CumulativeRunTimeTicks&Recursive=true&SortOrder=Ascending&IncludeItemTypes=Movie&format=json&ImageTypeLimit=1'
|
||||||
|
|
||||||
|
jsonData = downloadUtils.downloadUrl(url, suppress=True, popup=0)
|
||||||
|
if jsonData != None and jsonData != "":
|
||||||
|
result = json.loads(jsonData)
|
||||||
|
if(result.has_key('Items')):
|
||||||
|
result = result['Items']
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
def getTVShows(self, fullinfo = False):
|
||||||
|
result = None
|
||||||
|
|
||||||
|
addon = xbmcaddon.Addon(id='plugin.video.mb3sync')
|
||||||
|
port = addon.getSetting('port')
|
||||||
|
host = addon.getSetting('ipaddress')
|
||||||
|
server = host + ":" + port
|
||||||
|
|
||||||
|
downloadUtils = DownloadUtils()
|
||||||
|
userid = downloadUtils.getUserId()
|
||||||
|
|
||||||
|
if fullinfo:
|
||||||
|
url = server + '/mediabrowser/Users/' + userid + '/Items?&SortBy=SortName&Fields=Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,CommunityRating,OfficialRating,CumulativeRunTimeTicks,Metascore,AirTime,DateCreated,MediaStreams,People,Overview&Recursive=true&SortOrder=Ascending&IncludeItemTypes=Series&format=json&ImageTypeLimit=1'
|
||||||
|
else:
|
||||||
|
url = server + '/mediabrowser/Users/' + userid + '/Items?&SortBy=SortName&Fields=CumulativeRunTimeTicks&Recursive=true&SortOrder=Ascending&IncludeItemTypes=Series&format=json&ImageTypeLimit=1'
|
||||||
|
|
||||||
|
jsonData = downloadUtils.downloadUrl(url, suppress=True, popup=0)
|
||||||
|
if jsonData != None and jsonData != "":
|
||||||
|
result = json.loads(jsonData)
|
||||||
|
if(result.has_key('Items')):
|
||||||
|
result = result['Items']
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
def getEpisodes(self, showId, fullinfo = False):
|
||||||
|
result = None
|
||||||
|
|
||||||
|
addon = xbmcaddon.Addon(id='plugin.video.mb3sync')
|
||||||
|
port = addon.getSetting('port')
|
||||||
|
host = addon.getSetting('ipaddress')
|
||||||
|
server = host + ":" + port
|
||||||
|
|
||||||
|
downloadUtils = DownloadUtils()
|
||||||
|
userid = downloadUtils.getUserId()
|
||||||
|
|
||||||
|
if fullinfo:
|
||||||
|
url = server + '/mediabrowser/Users/' + userid + '/Items?ParentId=' + showId + '&IsVirtualUnaired=false&IsMissing=False&SortBy=SortName&Fields=Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,CommunityRating,OfficialRating,CumulativeRunTimeTicks,Metascore,AirTime,DateCreated,MediaStreams,People,Overview&Recursive=true&SortOrder=Ascending&IncludeItemTypes=Episode&format=json&ImageTypeLimit=1'
|
||||||
|
else:
|
||||||
|
url = server + '/mediabrowser/Users/' + userid + '/Items?ParentId=' + showId + '&IsVirtualUnaired=false&IsMissing=False&SortBy=SortName&Fields=Name,SortName,CumulativeRunTimeTicks&Recursive=true&SortOrder=Ascending&IncludeItemTypes=Episode&format=json&ImageTypeLimit=1'
|
||||||
|
|
||||||
|
jsonData = downloadUtils.downloadUrl(url, suppress=True, popup=0)
|
||||||
|
|
||||||
|
if jsonData != None and jsonData != "":
|
||||||
|
result = json.loads(jsonData)
|
||||||
|
if(result.has_key('Items')):
|
||||||
|
result = result['Items']
|
||||||
|
return result
|
||||||
|
|
||||||
|
def getCollections(self, type):
|
||||||
|
#Build a list of the user views
|
||||||
|
userid = DownloadUtils().getUserId()
|
||||||
|
addon = xbmcaddon.Addon(id='plugin.video.mb3sync')
|
||||||
|
port = addon.getSetting('port')
|
||||||
|
host = addon.getSetting('ipaddress')
|
||||||
|
server = host + ":" + port
|
||||||
|
|
||||||
|
viewsUrl = server + "/mediabrowser/Users/" + userid + "/Views?format=json&ImageTypeLimit=1"
|
||||||
|
jsonData = DownloadUtils().downloadUrl(viewsUrl, suppress=True, popup=0 )
|
||||||
|
|
||||||
|
if(jsonData != ""):
|
||||||
|
views = json.loads(jsonData)
|
||||||
|
views = views.get("Items")
|
||||||
|
collections=[]
|
||||||
|
for view in views:
|
||||||
|
if view.get("Type") == 'UserView': # Need to grab the real main node
|
||||||
|
newViewsUrl = server + '/mediabrowser/Users/' + userid + '/items?ParentId=' + view.get("Id") + '&SortBy=SortName&SortOrder=Ascending&format=json&ImageTypeLimit=1'
|
||||||
|
jsonData = DownloadUtils().downloadUrl(newViewsUrl, suppress=True, popup=0 )
|
||||||
|
if(jsonData != ""):
|
||||||
|
newViews = json.loads(jsonData)
|
||||||
|
newViews = newViews.get("Items")
|
||||||
|
for newView in newViews:
|
||||||
|
# There are multiple nodes in here like 'Latest', 'NextUp' - below we grab the full node.
|
||||||
|
if newView.get("CollectionType") == "MovieMovies" or newView.get("CollectionType") == "TvShowSeries":
|
||||||
|
view=newView
|
||||||
|
if(view.get("ChildCount") != 0):
|
||||||
|
Name =(view.get("Name")).encode('utf-8')
|
||||||
|
|
||||||
|
total = str(view.get("ChildCount"))
|
||||||
|
type = view.get("CollectionType")
|
||||||
|
if type == None:
|
||||||
|
type = "None" # User may not have declared the type
|
||||||
|
if type == type:
|
||||||
|
collections.append( {'title' : Name,
|
||||||
|
'type' : type,
|
||||||
|
'id' : view.get("Id")})
|
||||||
|
return collections
|
||||||
|
|
Loading…
Reference in a new issue