Add logic to safely enable the Kodi webserver for artwork caching
This commit is contained in:
parent
3bfe05c5bb
commit
dc2967c8da
3 changed files with 25 additions and 8 deletions
|
@ -36,6 +36,10 @@ msgctxt "#30003"
|
||||||
msgid "Warning: Kodi setting \"Play next video automatically\" is enabled. This could break PKC. Deactivate?"
|
msgid "Warning: Kodi setting \"Play next video automatically\" is enabled. This could break PKC. Deactivate?"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
msgctxt "#30004"
|
||||||
|
msgid "The Kodi webserver is needed for artwork caching. PKC already set a strong, random password automatically if you haven't done so already. Please confirm the next dialog that you want to enable the webserver now with Yes."
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
msgctxt "#30005"
|
msgctxt "#30005"
|
||||||
msgid "Username: "
|
msgid "Username: "
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
|
import secrets
|
||||||
|
|
||||||
from .. import utils, json_rpc as js, variables as v
|
from .. import utils, json_rpc as js, variables as v
|
||||||
|
|
||||||
|
@ -37,14 +38,29 @@ class Connection(object):
|
||||||
PKC needs Kodi webserver to work correctly
|
PKC needs Kodi webserver to work correctly
|
||||||
"""
|
"""
|
||||||
LOG.debug('Loading Kodi webserver details')
|
LOG.debug('Loading Kodi webserver details')
|
||||||
# Kodi webserver details
|
if not utils.settings('enableTextureCache') == 'true':
|
||||||
if js.get_setting('services.webserver') in (None, False):
|
LOG.info('Artwork caching disabled')
|
||||||
# Enable the webserver, it is disabled
|
return
|
||||||
|
self.webserver_password = js.get_setting('services.webserverpassword')
|
||||||
|
if not self.webserver_password:
|
||||||
|
LOG.warn('No password set for the Kodi web server. Generating a '
|
||||||
|
'new random password')
|
||||||
|
self.webserver_password = secrets.token_urlsafe(16)
|
||||||
|
js.set_setting('services.webserverpassword', self.webserver_password)
|
||||||
|
if not js.get_setting('services.webserver'):
|
||||||
|
# The Kodi webserver is needed for artwork caching. PKC already set
|
||||||
|
# a strong, random password automatically if you haven't done so
|
||||||
|
# already. Please confirm the next dialog that you want to enable
|
||||||
|
# the webserver now with Yes.
|
||||||
|
utils.messageDialog(utils.lang(29999), utils.lang(30004))
|
||||||
|
# Enable the webserver, it is disabled. Will force a Kodi pop-up
|
||||||
js.set_setting('services.webserver', True)
|
js.set_setting('services.webserver', True)
|
||||||
|
if not js.get_setting('services.webserver'):
|
||||||
|
LOG.warn('User chose to not enable Kodi webserver')
|
||||||
|
utils.settings('enableTextureCache', value='false')
|
||||||
self.webserver_host = 'localhost'
|
self.webserver_host = 'localhost'
|
||||||
self.webserver_port = js.get_setting('services.webserverport')
|
self.webserver_port = js.get_setting('services.webserverport')
|
||||||
self.webserver_username = js.get_setting('services.webserverusername')
|
self.webserver_username = js.get_setting('services.webserverusername')
|
||||||
self.webserver_password = js.get_setting('services.webserverpassword')
|
|
||||||
|
|
||||||
def load(self):
|
def load(self):
|
||||||
LOG.debug('Loading connection settings')
|
LOG.debug('Loading connection settings')
|
||||||
|
|
|
@ -100,10 +100,7 @@ def cache_url(url, should_suspend=None):
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
requests.head(
|
requests.head(
|
||||||
url="http://%s:%s/image/image://%s"
|
url=f'http://{app.CONN.webserver_username}:{app.CONN.webserver_password}@{app.CONN.webserver_host}:{app.CONN.webserver_port}/image/image://{url}',
|
||||||
% (app.CONN.webserver_host,
|
|
||||||
app.CONN.webserver_port,
|
|
||||||
url),
|
|
||||||
auth=(app.CONN.webserver_username,
|
auth=(app.CONN.webserver_username,
|
||||||
app.CONN.webserver_password),
|
app.CONN.webserver_password),
|
||||||
timeout=TIMEOUT)
|
timeout=TIMEOUT)
|
||||||
|
|
Loading…
Reference in a new issue