Merge branch 'beta-version'

This commit is contained in:
croneter 2018-07-27 16:04:57 +02:00
commit bb9702550e
11 changed files with 171 additions and 113 deletions

View file

@ -1,5 +1,5 @@
[![stable version](https://img.shields.io/badge/stable_version-2.1.6-blue.svg?maxAge=60&style=flat) ](https://github.com/croneter/binary_repo/raw/master/stable/repository.plexkodiconnect/repository.plexkodiconnect-1.0.2.zip)
[![beta version](https://img.shields.io/badge/beta_version-2.2.16-red.svg?maxAge=60&style=flat) ](https://github.com/croneter/binary_repo/raw/master/beta/repository.plexkodiconnectbeta/repository.plexkodiconnectbeta-1.0.2.zip)
[![beta version](https://img.shields.io/badge/beta_version-2.2.17-red.svg?maxAge=60&style=flat) ](https://github.com/croneter/binary_repo/raw/master/beta/repository.plexkodiconnectbeta/repository.plexkodiconnectbeta-1.0.2.zip)
[![Installation](https://img.shields.io/badge/wiki-installation-brightgreen.svg?maxAge=60&style=flat)](https://github.com/croneter/PlexKodiConnect/wiki/Installation)
[![FAQ](https://img.shields.io/badge/wiki-FAQ-brightgreen.svg?maxAge=60&style=flat)](https://github.com/croneter/PlexKodiConnect/wiki/faq)

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.plexkodiconnect" name="PlexKodiConnect" version="2.2.16" provider-name="croneter">
<addon id="plugin.video.plexkodiconnect" name="PlexKodiConnect" version="2.2.17" provider-name="croneter">
<requires>
<import addon="xbmc.python" version="2.1.0"/>
<import addon="script.module.requests" version="2.9.1" />
@ -73,7 +73,13 @@
<summary lang="uk_UA">Нативна інтеграція Plex в Kodi</summary>
<description lang="uk_UA">Підключає Kodi до серверу Plex. Цей плагін передбачає, що ви керуєте всіма своїми відео за допомогою Plex (і ніяк не Kodi). Ви можете втратити дані, які вже зберігаються у відео та музичних БД Kodi (оскільки цей плагін безпосередньо їх змінює). Використовуйте на свій страх і ризик!</description>
<disclaimer lang="uk_UA">Використовуйте на свій ризик</disclaimer>
<news>version 2.2.16 (beta only):
<news>version 2.2.17 (beta only):
- Access Plex Hubs. Listing will be different depending on Kodi section!
- Fix year for songs missing
- Fix Plex extras not playing
- Fix rare library sync crash
version 2.2.16 (beta only):
- Enable Kodi libraries for Plex Music libraries
- New Playlists menu item for video libraries
- Only show Plex libraries in the applicable Kodi media category

View file

@ -1,3 +1,9 @@
version 2.2.17 (beta only):
- Access Plex Hubs. Listing will be different depending on Kodi section!
- Fix year for songs missing
- Fix Plex extras not playing
- Fix rare library sync crash
version 2.2.16 (beta only):
- Enable Kodi libraries for Plex Music libraries
- New Playlists menu item for video libraries

View file

@ -139,6 +139,9 @@ class Main():
elif mode == 'playlists':
entrypoint.playlists(params.get('type'))
elif mode == 'hub':
entrypoint.hub(params.get('type'))
else:
entrypoint.show_main_menu(content_type=params.get('content_type'))

View file

@ -152,7 +152,9 @@ def show_main_menu(content_type=None):
'homevideos',
'musicvideos') and content_type == 'video':
directory_item(label, path)
# Plex Hub
directory_item('Plex Hub',
'plugin://%s?mode=hub&type=%s' % (v.ADDON_ID, content_type))
# Plex Watch later
if content_type not in ('image', 'audio'):
directory_item(utils.lang(39211),
@ -707,6 +709,31 @@ def playlists(plex_playlist_type):
cacheToDisc=utils.settings('enableTextureCache') == 'true')
def hub(content_type):
"""
Plus hub endpoint pms:port/hubs. Need to separate Kodi types with
content_type:
audio, video, image
"""
xml = PF.get_plex_hub()
try:
xml.attrib
except AttributeError:
LOG.error('Could not get Plex hub listing')
return xbmcplugin.endOfDirectory(int(argv[1]), False)
for entry in xml:
api = API(entry)
if content_type == 'video' and api.plex_type() in v.PLEX_VIDEOTYPES:
__build_folder(entry)
elif content_type == 'audio' and api.plex_type() in v.PLEX_AUDIOTYPES:
__build_folder(entry)
elif content_type == 'image' and api.plex_type() == v.PLEX_TYPE_PHOTO:
__build_folder(entry)
xbmcplugin.endOfDirectory(
handle=int(argv[1]),
cacheToDisc=utils.settings('enableTextureCache') == 'true')
def watchlater():
"""
Listing for plex.tv Watch Later section (if signed in to plex.tv)
@ -768,8 +795,8 @@ def browse_plex(key=None, plex_section_id=None):
else:
xml = PF.GetPlexSectionResults(plex_section_id)
try:
xml[0].attrib
except (ValueError, AttributeError, IndexError, TypeError):
xml.attrib
except AttributeError:
LOG.error('Could not browse to key %s, section %s',
key, plex_section_id)
return xbmcplugin.endOfDirectory(int(argv[1]), False)
@ -866,17 +893,22 @@ def browse_plex(key=None, plex_section_id=None):
def __build_folder(xml_element, plex_section_id=None):
url = "plugin://%s/" % v.ADDON_ID
key = xml_element.attrib.get('fastKey', xml_element.attrib.get('key'))
key = xml_element.get('fastKey', xml_element.get('key'))
if not key.startswith('/'):
key = '/library/sections/%s/%s' % (plex_section_id, key)
params = {
'mode': "browseplex",
'key': key,
'id': plex_section_id
}
listitem = ListItem(xml_element.attrib.get('title'))
listitem.setArt({'thumb': xml_element.attrib.get('thumb'),
'poster': xml_element.attrib.get('art')})
if plex_section_id:
params['id'] = plex_section_id
listitem = ListItem(xml_element.get('title'))
thumb = xml_element.get('thumb') or \
'special://home/addons/%s/icon.png' % v.ADDON_ID
art = xml_element.get('art') or \
'special://home/addons/%s/fanart.jpg' % v.ADDON_ID
listitem.setThumbnailImage(thumb)
listitem.setArt({'fanart': art, 'landscape': art})
xbmcplugin.addDirectoryItem(handle=int(argv[1]),
url="%s?%s" % (url, urlencode(params)),
isFolder=True,

View file

@ -63,76 +63,14 @@ class Items(object):
self.kodiconn.close()
return self
@utils.catch_exceptions(warnuser=True)
def getfanart(self, plex_id, refresh=False):
def set_fanart(self, artworks, kodi_id, kodi_type):
"""
Tries to get additional fanart for movies (+sets) and TV shows.
Returns True if successful, False otherwise
Writes artworks [dict containing only set artworks] to the Kodi art DB
"""
with plexdb.Get_Plex_DB() as plex_db:
db_item = plex_db.getItem_byId(plex_id)
try:
kodi_id = db_item[0]
kodi_type = db_item[4]
except TypeError:
LOG.error('Could not get Kodi id for plex id %s, abort getfanart',
plex_id)
return False
if refresh is True:
# Leave the Plex art untouched
allartworks = None
else:
with kodidb.GetKodiDB('video') as kodi_db:
allartworks = kodi_db.get_art(kodi_id, kodi_type)
# Check if we even need to get additional art
needsupdate = False
for key in v.ALL_KODI_ARTWORK:
if key not in allartworks:
needsupdate = True
break
if needsupdate is False:
LOG.debug('Already got all fanart for Plex id %s', plex_id)
return True
xml = PF.GetPlexMetadata(plex_id)
if xml is None:
# Did not receive a valid XML - skip that item for now
LOG.error("Could not get metadata for %s. Skipping that item "
"for now", plex_id)
return False
elif xml == 401:
LOG.error('HTTP 401 returned by PMS. Too much strain? '
'Cancelling sync for now')
# Kill remaining items in queue (for main thread to cont.)
return False
api = API(xml[0])
if allartworks is None:
allartworks = api.artwork()
self.artwork.modify_artwork(api.fanart_artwork(allartworks),
self.artwork.modify_artwork(artworks,
kodi_id,
kodi_type,
self.kodicursor)
# Also get artwork for collections/movie sets
if kodi_type == v.KODI_TYPE_MOVIE:
for _, setname in api.collection_list():
LOG.debug('Getting artwork for movie set %s', setname)
setid = self.kodi_db.create_collection(setname)
external_set_artwork = api.set_artwork()
if (external_set_artwork and
utils.settings('PreferKodiCollectionArt') == 'true'):
# Need to make sure we are not overwriting existing Plex
# collection artwork
plex_artwork = api.artwork(kodi_id=setid,
kodi_type=v.KODI_TYPE_SET)
for art in plex_artwork:
if art in external_set_artwork:
del external_set_artwork[art]
self.artwork.modify_artwork(external_set_artwork,
setid,
v.KODI_TYPE_SET,
self.kodicursor)
return True
def updateUserdata(self, xml):
"""
@ -1427,10 +1365,10 @@ class Music(Items):
# Add all children - all tracks
if scan_children:
for child in children:
self.add_updateSong(child, viewtag, viewid)
self.add_updateSong(child, viewtag, viewid, item)
@utils.catch_exceptions(warnuser=True)
def add_updateSong(self, item, viewtag=None, viewid=None):
def add_updateSong(self, item, viewtag=None, viewid=None, album_xml=None):
"""
Process single song
"""
@ -1491,6 +1429,10 @@ class Music(Items):
else:
track = disc * 2 ** 16 + tracknumber
year = api.year()
if not year and album_xml:
# Plex did not pass year info - get it from the parent album
album_api = API(album_xml)
year = album_api.year()
_, duration = api.resume_runtime()
rating = userdata['UserRating']
comment = None

View file

@ -5,12 +5,9 @@ from threading import Thread
from Queue import Empty
import xbmc
from .. import utils
from .. import plexdb_functions as plexdb
from .. import itemtypes
from .. import artwork
from .. import variables as v
from .. import state
from ..plex_api import API
from .. import utils, plexdb_functions as plexdb, kodidb_functions as kodidb
from .. import itemtypes, artwork, plex_functions as PF, variables as v, state
###############################################################################
@ -46,24 +43,22 @@ class ThreadedProcessFanart(Thread):
Do the work
"""
LOG.debug("---===### Starting FanartSync ###===---")
stopped = self.stopped
suspended = self.suspended
queue = self.queue
while not stopped():
while not self.stopped():
# In the event the server goes offline
while suspended():
while self.suspended():
# Set in service.py
if stopped():
if self.stopped():
# Abort was requested while waiting. We should exit
LOG.info("---===### Stopped FanartSync ###===---")
LOG.debug("---===### Stopped FanartSync ###===---")
return
xbmc.sleep(1000)
# grabs Plex item from queue
try:
item = queue.get(block=False)
item = self.queue.get(block=False)
except Empty:
xbmc.sleep(200)
continue
self.queue.task_done()
if isinstance(item, artwork.ArtworkSyncMessage):
if state.IMAGE_SYNC_NOTIFICATIONS:
utils.dialog('notification',
@ -71,17 +66,76 @@ class ThreadedProcessFanart(Thread):
message=item.message,
icon='{plex}',
sound=False)
queue.task_done()
continue
LOG.debug('Get additional fanart for Plex id %s', item['plex_id'])
with getattr(itemtypes,
v.ITEMTYPE_FROM_PLEXTYPE[item['plex_type']])() as item_type:
result = item_type.getfanart(item['plex_id'],
refresh=item['refresh'])
if result is True:
LOG.debug('Done getting fanart for Plex id %s', item['plex_id'])
with plexdb.Get_Plex_DB() as plex_db:
plex_db.set_fanart_synched(item['plex_id'])
queue.task_done()
_process(item)
LOG.debug("---===### Stopped FanartSync ###===---")
def _process(item):
done = False
try:
artworks = None
with plexdb.Get_Plex_DB() as plex_db:
db_item = plex_db.getItem_byId(item['plex_id'])
try:
kodi_id = db_item[0]
kodi_type = db_item[4]
except TypeError:
LOG.error('Could not get Kodi id for plex id %s, abort getfanart',
item['plex_id'])
return
if item['refresh'] is False:
with kodidb.GetKodiDB('video') as kodi_db:
artworks = kodi_db.get_art(kodi_id, kodi_type)
# Check if we even need to get additional art
for key in v.ALL_KODI_ARTWORK:
if key not in artworks:
break
else:
LOG.debug('Already got all fanart for Plex id %s',
item['plex_id'])
done = True
return
xml = PF.GetPlexMetadata(item['plex_id'])
if xml is None:
LOG.error('Could not get metadata for %s. Skipping that item '
'for now', item['plex_id'])
return
elif xml == 401:
LOG.error('HTTP 401 returned by PMS. Too much strain? '
'Cancelling sync for now')
return
api = API(xml[0])
if artworks is None:
artworks = api.artwork()
# Get additional missing artwork from fanart artwork sites
artworks = api.fanart_artwork(artworks)
with getattr(itemtypes,
v.ITEMTYPE_FROM_PLEXTYPE[item['plex_type']])() as itm:
itm.set_fanart(artworks, kodi_id, kodi_type)
# Additional fanart for sets/collections
if api.plex_type() == v.PLEX_TYPE_MOVIE:
for _, setname in api.collection_list():
LOG.debug('Getting artwork for movie set %s', setname)
with kodidb.GetKodiDB('video') as kodi_db:
setid = kodi_db.create_collection(setname)
external_set_artwork = api.set_artwork()
if (external_set_artwork and
utils.settings('PreferKodiCollectionArt') == 'false'):
kodi_artwork = api.artwork(kodi_id=setid,
kodi_type=v.KODI_TYPE_SET)
for art in kodi_artwork:
if art in external_set_artwork:
del external_set_artwork[art]
with itemtypes.Movies() as movie_db:
movie_db.artwork.modify_artwork(external_set_artwork,
setid,
v.KODI_TYPE_SET,
movie_db.kodicursor)
done = True
finally:
if done is True:
LOG.debug('Done getting fanart for Plex id %s', item['plex_id'])
with plexdb.Get_Plex_DB() as plex_db:
plex_db.set_fanart_synched(item['plex_id'])

View file

@ -1298,17 +1298,17 @@ class API(object):
else:
option = '%s ' % option
if 'videoResolution' in entry.attrib:
res = utils.try_decode(entry['videoResolution'])
res = utils.try_decode(entry.attrib['videoResolution'])
option = '%s%sp ' % (option, res)
if 'videoCodec' in entry.attrib:
codec = utils.try_decode(entry['videoCodec'])
codec = utils.try_decode(entry.attrib['videoCodec'])
option = '%s%s' % (option, codec)
option = option.strip() + ' - '
if 'audioProfile' in entry.attrib:
profile = utils.try_decode(entry['audioProfile'])
profile = utils.try_decode(entry.attrib['audioProfile'])
option = '%s%s ' % (option, profile)
if 'audioCodec' in entry.attrib:
codec = utils.try_decode(entry['audioCodec'])
codec = utils.try_decode(entry.attrib['audioCodec'])
option = '%s%s ' % (option, codec)
option = utils.try_encode(option.strip())
dialoglist.append(option)

View file

@ -611,6 +611,10 @@ def GetPlexOnDeck(viewId):
return DownloadChunks("{server}/library/sections/%s/onDeck?" % viewId)
def get_plex_hub():
return DU().downloadUrl('{server}/hubs')
def get_plex_sections():
"""
Returns all Plex sections (libraries) of the PMS as an etree xml

View file

@ -146,6 +146,7 @@ PLEX_TYPE_VIDEO = 'video'
PLEX_TYPE_MOVIE = 'movie'
PLEX_TYPE_CLIP = 'clip' # e.g. trailers
PLEX_TYPE_SET = 'collection' # sets/collections
PLEX_TYPE_MIXED = 'mixed'
PLEX_TYPE_EPISODE = 'episode'
PLEX_TYPE_SEASON = 'season'
@ -198,15 +199,19 @@ KODI_VIDEOTYPES = (
KODI_TYPE_SHOW,
KODI_TYPE_SEASON,
KODI_TYPE_EPISODE,
KODI_TYPE_SET
KODI_TYPE_SET,
KODI_TYPE_CLIP
)
PLEX_VIDEOTYPES = (
PLEX_TYPE_VIDEO,
PLEX_TYPE_MOVIE,
PLEX_TYPE_CLIP,
PLEX_TYPE_EPISODE,
PLEX_TYPE_SHOW,
PLEX_TYPE_SEASON,
PLEX_TYPE_SHOW
PLEX_TYPE_EPISODE,
PLEX_TYPE_SET,
PLEX_TYPE_CLIP,
PLEX_TYPE_MIXED, # MIXED SEEMS TO ALWAYS REFER TO VIDEO!
)
KODI_AUDIOTYPES = (
@ -215,6 +220,12 @@ KODI_AUDIOTYPES = (
KODI_TYPE_ARTIST,
)
PLEX_AUDIOTYPES = (
PLEX_TYPE_SONG,
PLEX_TYPE_ALBUM,
PLEX_TYPE_ARTIST,
)
# Translation tables
ADDON_TYPE = {

View file

@ -131,9 +131,9 @@
<category label="30544"><!-- artwork -->
<setting id="enableTextureCache" label="30512" type="bool" default="true" /> <!-- Cache all artwork for a smooth Kodi experience -->
<setting id="PreferKodiCollectionArt" label="30543" type="bool" default="true" /><!-- Prefer Kodi artwork for collections -->
<setting id="FanartTV" label="30539" type="bool" default="false" /><!-- Download additional art from FanArtTV -->
<setting label="39222" type="action" action="RunPlugin(plugin://plugin.video.plexkodiconnect/?mode=fanart)" option="close" visible="eq(-1,true)" subsetting="true" /> <!-- Look for missing fanart on FanartTV now -->
<setting id="PreferKodiCollectionArt" label="30543" type="bool" default="true" visible="eq(-1,true)" subsetting="true" /><!-- Prefer Kodi artwork for collections -->
<setting label="39222" type="action" action="RunPlugin(plugin://plugin.video.plexkodiconnect/?mode=fanart)" option="close" visible="eq(-2,true)" subsetting="true" /> <!-- Look for missing fanart on FanartTV now -->
<setting id="imageSyncNotifications" label="30008" type="bool" default="true" /><!-- Enable notifications for image caching -->
<setting id="imageSyncDuringPlayback" label="30009" type="bool" default="true" /><!-- Enable image caching during Kodi playback (restart Kodi!) -->
<setting label="39020" type="action" action="RunPlugin(plugin://plugin.video.plexkodiconnect/?mode=texturecache)" option="close" /> <!-- Cache all images to Kodi texture cache now -->