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

__init__.py 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # -*- coding: utf-8 -*-
  2. """
  3. kodiswift
  4. ----------
  5. A micro framework to enable rapid development of Kodi plugins.
  6. :copyright: (c) 2012 by Jonathan Beluch
  7. :license: GPLv3, see LICENSE for more details.
  8. """
  9. from __future__ import absolute_import
  10. from types import ModuleType
  11. try:
  12. import xbmc
  13. import xbmcgui
  14. import xbmcplugin
  15. import xbmcaddon
  16. import xbmcvfs
  17. CLI_MODE = False
  18. except ImportError:
  19. CLI_MODE = True
  20. import sys
  21. from kodiswift.logger import log
  22. # Mock the Kodi modules
  23. from kodiswift.mockxbmc import xbmc, xbmcgui, xbmcplugin, xbmcaddon, xbmcvfs
  24. class _Module(ModuleType):
  25. """A wrapper class for a module used to override __getattr__.
  26. This class will behave normally for any existing module attributes.
  27. For any attributes which do not exist in the wrapped module, a mock
  28. function will be returned. This function will also return itself
  29. enabling multiple mock function calls.
  30. """
  31. def __init__(self, wrapped=None):
  32. self.wrapped = wrapped
  33. if wrapped:
  34. self.__dict__.update(wrapped.__dict__)
  35. def __getattr__(self, name):
  36. """Returns any existing attr for the wrapped module or returns a
  37. mock function for anything else. Never raises an AttributeError.
  38. """
  39. try:
  40. return getattr(self.wrapped, name)
  41. except AttributeError:
  42. # noinspection PyUnusedLocal
  43. # pylint disable=unused-argument
  44. def func(*args, **kwargs):
  45. """A mock function which returns itself, enabling chainable
  46. function calls.
  47. """
  48. log.warning('The %s method has not been implemented on '
  49. 'the CLI. Your code might not work properly '
  50. 'when calling it.', name)
  51. return self
  52. return func
  53. xbmc = _Module(xbmc)
  54. xbmcgui = _Module(xbmcgui)
  55. xbmcplugin = _Module(xbmcplugin)
  56. xbmcaddon = _Module(xbmcaddon)
  57. xbmcvfs = _Module(xbmcvfs)
  58. for m in (xbmc, xbmcgui, xbmcplugin, xbmcaddon, xbmcvfs):
  59. name = reversed(m.__name__.rsplit('.', 1)).next()
  60. sys.modules[name] = m
  61. from kodiswift.storage import TimedStorage
  62. from kodiswift.request import Request
  63. from kodiswift.common import (kodi_url, clean_dict, pickle_dict, unpickle_args,
  64. unpickle_dict, download_page)
  65. from kodiswift.constants import SortMethod
  66. from kodiswift.listitem import ListItem
  67. from kodiswift.logger import setup_log
  68. from kodiswift.module import Module
  69. from kodiswift.urls import AmbiguousUrlException, NotFoundException, UrlRule
  70. from kodiswift.xbmcmixin import XBMCMixin
  71. from kodiswift.plugin import Plugin