# Path: resources/lib/simple_logging.py
# class SimpleLogging:
#     name = ""
#     enable_logging = False
# 
#     def __init__(self, name):
#         settings = xbmcaddon.Addon()
#         prefix = settings.getAddonInfo('name')
#         self.name = prefix + '.' + name
#         self.enable_logging = settings.getSetting('log_debug') == "true"
# 
#         # params = {"setting": "debug.showloginfo"}
#         # setting_result = json_rpc('Settings.getSettingValue').execute(params)
#         # current_value = setting_result.get("result", None)
#         # if current_value is not None:
#         #     self.enable_logging = current_value.get("value", False)
#         # xbmc.log("LOGGING_ENABLED %s : %s" % (self.name, str(self.enable_logging)), level=xbmc.LOGDEBUG)
# 
#     def __str__(self):
#         return "LoggingEnabled: " + str(self.enable_logging)
# 
#     def info(self, fmt, *args, **kwargs):
#         log_line = self.name + "|INFO|" + self.log_line(fmt, *args)
#         xbmc.log(log_line, level=xbmc.LOGNOTICE)
# 
#     def error(self, fmt, *args, **kwargs):
#         log_line = self.name + "|ERROR|" + self.log_line(fmt, *args)
#         xbmc.log(log_line, level=xbmc.LOGERROR)
# 
#     def debug(self, fmt, *args, **kwargs):
#         if self.enable_logging:
#             log_line = self.name + "|DEBUG|" + self.log_line(fmt, *args)
#             xbmc.log(log_line, level=xbmc.LOGNOTICE)
# 
#     @staticmethod
#     def log_line(fmt, *args):
#         new_args = []
#         # convert any unicode to utf-8 strings
#         for arg in args:
#             if isinstance(arg, unicode):
#                 new_args.append(arg.encode("utf-8"))
#             else:
#                 new_args.append(arg)
#         log_line = fmt.format(*new_args)
#         return log_line
# 
# Path: resources/lib/play_utils.py
# def play_all_files(items, auto_resume, monitor, play_items=True):
# def play_list_of_items(id_list, auto_resume, monitor):
# def add_to_playlist(play_info, monitor):
# def get_playback_intros(item_id):
# def play_file(play_info, monitor):
# def __build_label2_from(source):
# def get_next_episode(item):
# def send_next_episode_details(item, next_episode):
# def set_list_item_props(item_id, list_item, result, server, extra_props, title):
# def audio_subs_pref(url, list_item, media_source, item_id, audio_stream_index, subtitle_stream_index):
# def external_subs(media_source, list_item, item_id):
# def send_progress(monitor):
# def get_volume():
# def prompt_for_stop_actions(item_id, data):
# def stop_all_playback(played_information):
# def get_playing_data(play_data_map):
#     def __init__(self, *args):
#     def onPlayBackStarted(self):
#     def onAVStarted(self):
#     def onPlayBackEnded(self):
#     def onPlayBackStopped(self):
#     def onPlayBackPaused(self):
#     def onPlayBackResumed(self):
#     def onPlayBackSeek(self, time, seek_offset):
#     def __init__(self, monitor):
#     def onNotification(self, sender, method, data):
#     def screensaver_activated(self):
#     def screensaver_deactivated(self):
# class Service(xbmc.Player):
# class PlaybackService(xbmc.Monitor):
# 
# Path: resources/lib/action_menu.py
# class ActionAutoClose(threading.Thread):
# 
#     last_interaction = time.time()
#     parent_dialog = None
#     stop_thread = False
#     progress_call_back = None
#     time_out = 20
# 
#     def __init__(self, parent):
#         self.parent_dialog = parent
#         self.stop_thread = False
#         self.last_interaction = time.time()
#         threading.Thread.__init__(self)
#         self.time_out = 20
# 
#     def run(self):
#         log.debug("ActionAutoClose Running")
#         monitor = xbmc.Monitor()
#         while not monitor.abortRequested() and not self.stop_thread:
#             time_since_last = time.time() - self.last_interaction
#             log.debug("ActionAutoClose time_since_last : {0}", time_since_last)
# 
#             if time_since_last > self.time_out:
#                 log.debug("ActionAutoClose Closing Parent")
#                 self.parent_dialog.close()
#                 break
# 
#             if self.progress_call_back is not None:
#                 percentage = (float(time_since_last) / float(self.time_out)) * 100
#                 self.progress_call_back.update_progress(percentage)
# 
#             monitor.waitForAbort(0.1)
# 
#         log.debug("ActionAutoClose Exited")
# 
#     def set_timeout(self, t):
#         self.time_out = t
# 
#     def set_callback(self, call_back):
#         self.progress_call_back = call_back
# 
#     def set_last(self):
#         self.last_interaction = time.time()
#         log.debug("ActionAutoClose set_last : {0}", self.last_interaction)
# 
#     def stop(self):
#         log.debug("ActionAutoClose stop_thread called")
#         self.stop_thread = True


import os
import threading
import xbmc
import xbmcgui
import xbmcaddon
from .simple_logging import SimpleLogging
from .play_utils import send_event_notification
from .action_menu import ActionAutoClose
        from .play_utils import get_playing_data


log = SimpleLogging(__name__)


class PlayNextService(threading.Thread):

    stop_thread = False
    monitor = None

    def __init__(self, play_monitor):
        super(PlayNextService, self).__init__()
        self.monitor = play_monitor

    def run(self):

        settings = xbmcaddon.Addon()
        play_next_trigger_time = int(settings.getSetting('play_next_trigger_time'))

        play_next_dialog = None
        play_next_triggered = False
        is_playing = False

        while not xbmc.Monitor().abortRequested() and not self.stop_thread:

            player = xbmc.Player()

# Path: resources/lib/simple_logging.py
# class SimpleLogging:
#     name = ""
#     enable_logging = False
# 
#     def __init__(self, name):
#         settings = xbmcaddon.Addon()
#         prefix = settings.getAddonInfo('name')
#         self.name = prefix + '.' + name
#         self.enable_logging = settings.getSetting('log_debug') == "true"
# 
#         # params = {"setting": "debug.showloginfo"}
#         # setting_result = json_rpc('Settings.getSettingValue').execute(params)
#         # current_value = setting_result.get("result", None)
#         # if current_value is not None:
#         #     self.enable_logging = current_value.get("value", False)
#         # xbmc.log("LOGGING_ENABLED %s : %s" % (self.name, str(self.enable_logging)), level=xbmc.LOGDEBUG)
# 
#     def __str__(self):
#         return "LoggingEnabled: " + str(self.enable_logging)
# 
#     def info(self, fmt, *args, **kwargs):
#         log_line = self.name + "|INFO|" + self.log_line(fmt, *args)
#         xbmc.log(log_line, level=xbmc.LOGNOTICE)
# 
#     def error(self, fmt, *args, **kwargs):
#         log_line = self.name + "|ERROR|" + self.log_line(fmt, *args)
#         xbmc.log(log_line, level=xbmc.LOGERROR)
# 
#     def debug(self, fmt, *args, **kwargs):
#         if self.enable_logging:
#             log_line = self.name + "|DEBUG|" + self.log_line(fmt, *args)
#             xbmc.log(log_line, level=xbmc.LOGNOTICE)
# 
#     @staticmethod
#     def log_line(fmt, *args):
#         new_args = []
#         # convert any unicode to utf-8 strings
#         for arg in args:
#             if isinstance(arg, unicode):
#                 new_args.append(arg.encode("utf-8"))
#             else:
#                 new_args.append(arg)
#         log_line = fmt.format(*new_args)
#         return log_line
# 
# Path: resources/lib/play_utils.py
# def play_all_files(items, auto_resume, monitor, play_items=True):
# def play_list_of_items(id_list, auto_resume, monitor):
# def add_to_playlist(play_info, monitor):
# def get_playback_intros(item_id):
# def play_file(play_info, monitor):
# def __build_label2_from(source):
# def get_next_episode(item):
# def send_next_episode_details(item, next_episode):
# def set_list_item_props(item_id, list_item, result, server, extra_props, title):
# def audio_subs_pref(url, list_item, media_source, item_id, audio_stream_index, subtitle_stream_index):
# def external_subs(media_source, list_item, item_id):
# def send_progress(monitor):
# def get_volume():
# def prompt_for_stop_actions(item_id, data):
# def stop_all_playback(played_information):
# def get_playing_data(play_data_map):
#     def __init__(self, *args):
#     def onPlayBackStarted(self):
#     def onAVStarted(self):
#     def onPlayBackEnded(self):
#     def onPlayBackStopped(self):
#     def onPlayBackPaused(self):
#     def onPlayBackResumed(self):
#     def onPlayBackSeek(self, time, seek_offset):
#     def __init__(self, monitor):
#     def onNotification(self, sender, method, data):
#     def screensaver_activated(self):
#     def screensaver_deactivated(self):
# class Service(xbmc.Player):
# class PlaybackService(xbmc.Monitor):
# 
# Path: resources/lib/action_menu.py
# class ActionAutoClose(threading.Thread):
# 
#     last_interaction = time.time()
#     parent_dialog = None
#     stop_thread = False
#     progress_call_back = None
#     time_out = 20
# 
#     def __init__(self, parent):
#         self.parent_dialog = parent
#         self.stop_thread = False
#         self.last_interaction = time.time()
#         threading.Thread.__init__(self)
#         self.time_out = 20
# 
#     def run(self):
#         log.debug("ActionAutoClose Running")
#         monitor = xbmc.Monitor()
#         while not monitor.abortRequested() and not self.stop_thread:
#             time_since_last = time.time() - self.last_interaction
#             log.debug("ActionAutoClose time_since_last : {0}", time_since_last)
# 
#             if time_since_last > self.time_out:
#                 log.debug("ActionAutoClose Closing Parent")
#                 self.parent_dialog.close()
#                 break
# 
#             if self.progress_call_back is not None:
#                 percentage = (float(time_since_last) / float(self.time_out)) * 100
#                 self.progress_call_back.update_progress(percentage)
# 
#             monitor.waitForAbort(0.1)
# 
#         log.debug("ActionAutoClose Exited")
# 
#     def set_timeout(self, t):
#         self.time_out = t
# 
#     def set_callback(self, call_back):
#         self.progress_call_back = call_back
# 
#     def set_last(self):
#         self.last_interaction = time.time()
#         log.debug("ActionAutoClose set_last : {0}", self.last_interaction)
# 
#     def stop(self):
#         log.debug("ActionAutoClose stop_thread called")
#         self.stop_thread = True


# Path: resources/lib/playnext.py
import os
import threading
import xbmc
import xbmcgui
import xbmcaddon
from .simple_logging import SimpleLogging
from .play_utils import send_event_notification
from .action_menu import ActionAutoClose
        from .play_utils import get_playing_data



log = SimpleLogging(__name__)


class PlayNextService(threading.Thread):

    stop_thread = False
    monitor = None

    def __init__(self, play_monitor):
        super(PlayNextService, self).__init__()
        self.monitor = play_monitor

    def run(self):

        settings = xbmcaddon.Addon()
        play_next_trigger_time = int(settings.getSetting('play_next_trigger_time'))

        play_next_dialog = None
        play_next_triggered = False
        is_playing = False

        while not xbmc.Monitor().abortRequested() and not self.stop_thread:

            player = xbmc.Player()

            if player.isPlaying():