videonodes v0.1

This commit is contained in:
tomkat83 2016-01-11 09:57:45 +01:00
parent 388e8e36e9
commit c854ee621e
4 changed files with 53 additions and 74 deletions

View file

@ -1594,12 +1594,16 @@ class API():
"""
item = self.item
item = item[self.child].attrib
regex = re.compile(r'''com.plexapp.agents.(.+)$''')
try:
item = item['guid']
except KeyError:
return None
provider = regex.findall(item['guid'])
regex = re.compile(r'''com\.plexapp\.agents\.(.+)$''')
provider = regex.findall(item)
try:
provider = provider[0]
except KeyError:
except IndexError:
provider = None
return provider
@ -1662,7 +1666,7 @@ class API():
item = item[self.child].attrib
try:
rating = item['audienceRating']
except:
except KeyError:
rating = None
return rating
@ -1674,7 +1678,7 @@ class API():
item = item[self.child].attrib
try:
year = item['year']
except:
except KeyError:
year = None
return year

View file

@ -333,6 +333,7 @@ class Movies(Items):
shortplot = None
tagline = API.getTagline()
votecount = None
rating = API.getAudienceRating()
year = API.getYear()
imdb = API.getProvider('Imdb')
@ -346,9 +347,11 @@ class Movies(Items):
studio = studios[0]
except IndexError:
studio = None
self.logMsg("Retrieved metadata for %s" % itemid, 2)
# TODO: trailers
trailer = None
self.logMsg("Retrieved trailer for %s" % itemid, 2)
##### GET THE FILE AND PATH #####
playurl = API.getFilePath()

View file

@ -346,10 +346,11 @@ class LibrarySync(threading.Thread):
starttotal = datetime.now()
# Set views
# self.maintainViews(embycursor, kodicursor)
# embyconn.commit()
# Ensure that DBs exist if called for very first time
self.initializeDBs()
# Set views
self.maintainViews()
# Sync video library
# process = {
@ -362,7 +363,6 @@ class LibrarySync(threading.Thread):
process = {
'movies': self.PlexMovies,
'tvshows': self.PlexTVShows
# 'tvshows': self.PlexTVShows
}
for itemtype in process:
@ -420,79 +420,46 @@ class LibrarySync(threading.Thread):
sound=False)
return True
def refreshViews(self):
embyconn = utils.kodiSQL('emby')
embycursor = embyconn.cursor()
kodiconn = utils.kodiSQL('video')
kodicursor = kodiconn.cursor()
# Compare views, assign correct tags to items
self.maintainViews(embycursor, kodicursor)
self.dbCommit(kodiconn)
kodicursor.close()
embyconn.commit()
embycursor.close()
def maintainViews(self, embycursor, kodicursor):
def maintainViews(self):
"""
Reverse engineering:
Compare the views to Plex
Input:
embycursor
kodicursor
Output:
vnodes.viewNode(totalnodes, foldername, mediatype, viewtype)
kodi_db.createTag(foldername)
kodi_db.updateTag(current_tagid, tagid, item[0],Current_viewtype[:-1])
"""
# Compare the views to emby
# Open DB links
embyconn = utils.kodiSQL('emby')
embycursor = embyconn.cursor()
kodiconn = utils.kodiSQL('video')
kodicursor = kodiconn.cursor()
emby_db = embydb.Embydb_Functions(embycursor)
kodi_db = kodidb.Kodidb_Functions(kodicursor)
doUtils = self.doUtils
vnodes = self.vnodes
# Get views
url = "{server}/emby/Users/{UserId}/Views?format=json"
result = doUtils.downloadUrl(url)
grouped_views = result['Items']
try:
groupedFolders = self.user.userSettings['Configuration']['GroupedFolders']
except TypeError:
url = "{server}/emby/Users/{UserId}?format=json"
result = doUtils.downloadUrl(url)
groupedFolders = result['Configuration']['GroupedFolders']
# Get views
url = "{server}/library/sections"
result = doUtils.downloadUrl(url)
result = result['_children']
# total nodes for window properties
vnodes.clearProperties()
totalnodes = 0
# Set views for supported media type
mediatypes = ['movies', 'tvshows', 'musicvideos', 'homevideos', 'music']
for mediatype in mediatypes:
# Get media folders from server
folders = self.emby.getViews(mediatype, root=True)
for folder in folders:
folderid = folder['id']
foldername = folder['name']
mediatypes = [
'movie',
'show'
]
for folder in result:
mediatype = folder['type']
if mediatype in mediatypes:
folderid = folder['key']
foldername = folder['title']
viewtype = folder['type']
if folderid in groupedFolders:
# Media folders are grouped into userview
for grouped_view in grouped_views:
# This is only reserved for the detection of grouped views
if (grouped_view['Type'] == "UserView" and
grouped_view.get('CollectionType') == mediatype and
grouped_view['Id'] not in grouped_view.get('Path', "")):
# Take the name of the userview
foldername = grouped_view['Name']
break
# Get current media folders from emby database
view = emby_db.getView_byId(folderid)
@ -567,14 +534,19 @@ class LibrarySync(threading.Thread):
totalnodes += 1
else:
# Add video nodes listings
vnodes.singleNode(totalnodes, "Favorite movies", "movies", "favourites")
totalnodes += 1
vnodes.singleNode(totalnodes, "Favorite tvshows", "tvshows", "favourites")
totalnodes += 1
vnodes.singleNode(totalnodes, "channels", "movies", "channels")
totalnodes += 1
# vnodes.singleNode(totalnodes, "Favorite movies", "movies", "favourites")
# totalnodes += 1
# vnodes.singleNode(totalnodes, "Favorite tvshows", "tvshows", "favourites")
# totalnodes += 1
# vnodes.singleNode(totalnodes, "channels", "movies", "channels")
# totalnodes += 1
# Save total
utils.window('Emby.nodes.total', str(totalnodes))
# commit changes to DB
embyconn.commit()
kodiconn.commit()
embyconn.close()
kodiconn.close()
def GetUpdatelist(self, elementList, itemType, method, viewName, viewId):
"""

View file

@ -93,7 +93,7 @@ class VideoNodes(object):
# Create index entry
nodeXML = "%sindex.xml" % nodepath
# Set windows property
path = "library://video/Emby - %s/" % dirname
path = "library://video/plexkodiconnect - %s/" % dirname
for i in range(1, indexnumber):
# Verify to make sure we don't create duplicates
if utils.window('Emby.nodes.%s.index' % i) == path:
@ -124,7 +124,7 @@ class VideoNodes(object):
}
mediatypes = {
# label according to nodetype per mediatype
'movies': {
'movie': {
'1': tagname,
'2': 30174,
'4': 30177,
@ -134,7 +134,7 @@ class VideoNodes(object):
'10': 30229,
'11': 30230},
'tvshows': {
'show': {
'1': tagname,
'2': 30170,
'3': 30175,
@ -171,7 +171,7 @@ class VideoNodes(object):
# Custom query
path = "plugin://plugin.video.plexkodiconnect/?id=%s&mode=inprogressepisodes&limit=25"% tagname
else:
path = "library://video/Emby - %s/%s_%s.xml" % (dirname, cleantagname, nodetype)
path = "library://video/plexkodiconnect - %s/%s_%s.xml" % (dirname, cleantagname, nodetype)
windowpath = "ActivateWindow(Video,%s,return)" % path
if nodetype == "all":
@ -276,7 +276,7 @@ class VideoNodes(object):
cleantagname = utils.normalize_nodes(tagname)
nodepath = xbmc.translatePath("special://profile/library/video/").decode('utf-8')
nodeXML = "%semby_%s.xml" % (nodepath, cleantagname)
path = "library://video/emby_%s.xml" % (cleantagname)
path = "library://video/plexkodiconnect_%s.xml" % (cleantagname)
windowpath = "ActivateWindow(Video,%s,return)" % path
# Create the video node directory