Kodi plugin to to play various online streams (mostly Latvian)

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # -*- coding: utf-8 -*-
  2. from __future__ import print_function, absolute_import
  3. import errno
  4. import os
  5. import tempfile
  6. import kodiswift
  7. from kodiswift.cli.create import get_value
  8. TEMP_DIR = os.path.join(tempfile.gettempdir(), 'kodiswift_debug')
  9. kodiswift.log.info('Using temp directory %s', TEMP_DIR)
  10. def _create_dir(path):
  11. """Creates necessary directories for the given path or does nothing
  12. if the directories already exist.
  13. """
  14. try:
  15. os.makedirs(path)
  16. except OSError as exc:
  17. if exc.errno == errno.EEXIST:
  18. pass
  19. else:
  20. raise
  21. def log(msg, level=0):
  22. levels = [
  23. 'LOGDEBUG',
  24. 'LOGINFO',
  25. 'LOGNOTICE',
  26. 'LOGWARNING',
  27. 'LOGERROR',
  28. 'LOGSEVERE',
  29. 'LOGFATAL',
  30. 'LOGNONE',
  31. ]
  32. print('%s - %s' % (levels[level], msg))
  33. # noinspection PyPep8Naming
  34. def translatePath(path):
  35. """Creates folders in the OS's temp directory. Doesn't touch any
  36. possible Kodi installation on the machine. Attempting to do as
  37. little work as possible to enable this function to work seamlessly.
  38. """
  39. valid_dirs = ['xbmc', 'home', 'temp', 'masterprofile', 'profile',
  40. 'subtitles', 'userdata', 'database', 'thumbnails',
  41. 'recordings', 'screenshots', 'musicplaylists',
  42. 'videoplaylists', 'cdrips', 'skin', ]
  43. # TODO: Remove asserts
  44. assert path.startswith('special://'), 'Not a valid special:// path.'
  45. parts = path.split('/')[2:]
  46. assert len(parts) > 1, 'Need at least a single root directory'
  47. assert parts[0] in valid_dirs, '%s is not a valid root dir.' % parts[0]
  48. # We don't want to swallow any potential IOErrors here, so only makedir for
  49. # the root dir, the user is responsible for making any further child dirs
  50. _create_dir(os.path.join(TEMP_DIR, parts[0]))
  51. return os.path.join(TEMP_DIR, *parts)
  52. # noinspection PyPep8Naming
  53. class Keyboard(object):
  54. def __init__(self, default='', heading='', hidden=False):
  55. self._heading = heading
  56. self._default = default
  57. self._hidden = hidden
  58. self._confirmed = False
  59. self._input = None
  60. def setDefault(self, default):
  61. self._default = default
  62. def setHeading(self, heading):
  63. self._heading = heading
  64. def setHiddenInput(self, hidden):
  65. self._hidden = hidden
  66. def doModal(self):
  67. self._confirmed = False
  68. try:
  69. self._input = get_value(
  70. self._heading, self._default, hidden=self._hidden)
  71. self._confirmed = True
  72. except(KeyboardInterrupt, EOFError):
  73. pass
  74. def isConfirmed(self):
  75. return self._confirmed
  76. def getText(self):
  77. return self._input