PlexKodiConnect/resources/lib/initialsetup.py

140 lines
5.5 KiB
Python
Raw Permalink Normal View History

# -*- coding: utf-8 -*-
2016-02-20 06:03:06 +11:00
###############################################################################
2017-07-01 20:32:23 +10:00
from logging import getLogger
from xbmc import executebuiltin
2017-07-01 20:32:23 +10:00
from utils import settings, language as lang, advancedsettings_xml, dialog
from connectmanager import ConnectManager
import state
2017-05-30 01:29:29 +10:00
from migration import check_migration
2015-12-27 22:14:06 +11:00
2016-02-20 06:03:06 +11:00
###############################################################################
2017-07-01 20:32:23 +10:00
log = getLogger("PLEX."+__name__)
2016-08-31 00:13:13 +10:00
###############################################################################
2017-07-02 22:42:52 +10:00
def setup():
2017-07-01 20:32:23 +10:00
"""
Initial setup. Run once upon startup.
Check server, user, direct paths, music, direct stream if not direct
path.
"""
log.info("Initial setup called")
connectmanager = ConnectManager()
# Get current Kodi video cache setting
cache, _ = advancedsettings_xml(['cache', 'memorysize'])
if cache is None:
# Kodi default cache
cache = '20971520'
else:
cache = str(cache.text)
log.info('Current Kodi video memory cache in bytes: %s' % cache)
settings('kodi_video_cache', value=cache)
# Do we need to migrate stuff?
check_migration()
# Optionally sign into plex.tv. Will not be called on very first run
# as plexToken will be ''
settings('plex_status', value=lang(39226))
if connectmanager.plexToken and connectmanager.myplexlogin:
connectmanager.check_plex_tv_signin()
# If a Plex server IP has already been set
# return only if the right machine identifier is found
if connectmanager.server:
2017-07-02 22:42:52 +10:00
log.info("PMS is already set: %s. Checking now..."
% connectmanager.server)
2017-07-01 20:32:23 +10:00
if connectmanager.check_pms():
log.info("Using PMS %s with machineIdentifier %s"
2017-07-02 22:42:52 +10:00
% (connectmanager.server, connectmanager.serverid))
connectmanager.write_pms_settings(connectmanager.server,
connectmanager.pms_token)
2017-07-26 02:17:49 +10:00
connectmanager.pick_pms(show_dialog=True)
return
2016-05-30 00:52:00 +10:00
2017-07-01 20:32:23 +10:00
# If not already retrieved myplex info, optionally let user sign in
# to plex.tv. This DOES get called on very first install run
if not connectmanager.plexToken and connectmanager.myplexlogin:
connectmanager.plex_tv_signin()
server = connectmanager.connectmanager.pick_pms()
if server is not None:
# Write our chosen server to Kodi settings file
connectmanager.write_pms_to_settings(server)
# User already answered the installation questions
if settings('InstallQuestionsAnswered') == 'true':
return
# Additional settings where the user needs to choose
# Direct paths (\\NAS\mymovie.mkv) or addon (http)?
goToSettings = False
if dialog('yesno',
lang(29999),
lang(39027),
lang(39028),
nolabel="Addon (Default)",
yeslabel="Native (Direct Paths)"):
log.debug("User opted to use direct paths.")
settings('useDirectPaths', value="1")
state.DIRECT_PATHS = True
# Are you on a system where you would like to replace paths
# \\NAS\mymovie.mkv with smb://NAS/mymovie.mkv? (e.g. Windows)
if dialog('yesno', heading=lang(29999), line1=lang(39033)):
log.debug("User chose to replace paths with smb")
else:
2017-07-01 20:32:23 +10:00
settings('replaceSMB', value="false")
# complete replace all original Plex library paths with custom SMB
if dialog('yesno', heading=lang(29999), line1=lang(39043)):
log.debug("User chose custom smb paths")
settings('remapSMB', value="true")
# Please enter your custom smb paths in the settings under
# "Sync Options" and then restart Kodi
dialog('ok', heading=lang(29999), line1=lang(39044))
goToSettings = True
# Go to network credentials?
if dialog('yesno',
heading=lang(29999),
line1=lang(39029),
line2=lang(39030)):
log.debug("Presenting network credentials dialog.")
from utils import passwordsXML
passwordsXML()
# Disable Plex music?
if dialog('yesno', heading=lang(29999), line1=lang(39016)):
log.debug("User opted to disable Plex music library.")
settings('enableMusic', value="false")
# Download additional art from FanArtTV
if dialog('yesno', heading=lang(29999), line1=lang(39061)):
log.debug("User opted to use FanArtTV")
settings('FanartTV', value="true")
# Do you want to replace your custom user ratings with an indicator of
# how many versions of a media item you posses?
if dialog('yesno', heading=lang(29999), line1=lang(39718)):
log.debug("User opted to replace user ratings with version number")
settings('indicate_media_versions', value="true")
# If you use several Plex libraries of one kind, e.g. "Kids Movies" and
# "Parents Movies", be sure to check https://goo.gl/JFtQV9
dialog('ok', heading=lang(29999), line1=lang(39076))
# Need to tell about our image source for collections: themoviedb.org
dialog('ok', heading=lang(29999), line1=lang(39717))
# Make sure that we only ask these questions upon first installation
settings('InstallQuestionsAnswered', value='true')
if goToSettings is False:
# Open Settings page now? You will need to restart!
goToSettings = dialog('yesno', heading=lang(29999), line1=lang(39017))
if goToSettings:
state.PMS_STATUS = 'Stop'
executebuiltin('Addon.OpenSettings(plugin.video.plexkodiconnect)')