Play images and video from Synology PhotoStation server

xbmcaddon.py 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # -*- coding: utf-8 -*-
  2. from __future__ import absolute_import
  3. import os
  4. from kodiswift.logger import log
  5. from kodiswift.mockxbmc import utils
  6. __all__ = ['Addon']
  7. def _get_env_setting(name):
  8. return os.getenv('KODISWIFT_%s' % name.upper())
  9. # noinspection PyPep8Naming
  10. class Addon(object):
  11. def __init__(self, id=None):
  12. # In CLI mode, kodiswift must be run from the root of the addon
  13. # directory, so we can rely on getcwd() being correct.
  14. addon_xml = os.path.join(os.getcwd(), 'addon.xml')
  15. _id = None
  16. if os.path.exists(addon_xml):
  17. _id = utils.get_addon_id(addon_xml)
  18. self._info = {
  19. 'id': id or _id,
  20. 'name': utils.get_addon_name(addon_xml),
  21. 'profile': 'special://profile/addon_data/%s/' % _id,
  22. 'path': 'special://home/addons/%s' % _id
  23. }
  24. self._strings = {}
  25. self._settings = {}
  26. strings_fn = os.path.join(
  27. os.getcwd(), 'resources', 'language', 'English', 'strings.po')
  28. utils.load_addon_strings(self, strings_fn)
  29. def getAddonInfo(self, prop):
  30. properties = ['author', 'changelog', 'description', 'disclaimer',
  31. 'fanart', 'icon', 'id', 'name', 'path', 'profile',
  32. 'stars', 'summary', 'type', 'version']
  33. if prop not in properties:
  34. raise ValueError('%s is not a valid property.' % prop)
  35. return self._info.get(prop, 'Unavailable')
  36. def getLocalizedString(self, str_id):
  37. key = str(str_id)
  38. if key not in self._strings:
  39. raise KeyError('id not found in English/strings.po or '
  40. 'strings.xml.')
  41. return self._strings[key]
  42. def getSetting(self, key):
  43. log.warning('xbmcaddon.Plugin.getSetting() has not been implemented '
  44. 'in CLI mode.')
  45. try:
  46. value = self._settings[key]
  47. except KeyError:
  48. # see if we have an env var
  49. value = _get_env_setting(key)
  50. if _get_env_setting(key) is None:
  51. value = raw_input(
  52. '* Please enter a temporary value for %s: ' % key)
  53. self._settings[key] = value
  54. return value
  55. def setSetting(self, key, value):
  56. self._settings[key] = value
  57. def openSettings(self):
  58. pass