# Path: lib/libs/pykodi.py
# def log(message, level=xbmc.LOGDEBUG, tag=None):
#     if is_addon_watched() and level < xbmc.LOGNOTICE:
#         # Messages from this add-on are being watched, elevate to NOTICE so Kodi logs it
#         level_tag = _log_level_tag_lookup[level] + ': ' if level in _log_level_tag_lookup else ''
#         level = xbmc.LOGNOTICE
#     else:
#         level_tag = ''
# 
#     if isinstance(message, (dict, list)) and len(message) > 300:
#         message = str(message)
#     elif isinstance(message, unicode):
#         message = message.encode('utf-8')
#     elif not isinstance(message, str):
#         message = json.dumps(message, cls=UTF8PrettyJSONEncoder)
# 
#     addontag = ADDONID if not tag else ADDONID + ':' + tag
#     file_message = '%s[%s] %s' % (level_tag, addontag, scrub_message(message))
#     xbmc.log(file_message, level)


import re
import xbmc
from collections import namedtuple
from os.path import split, basename, dirname
from lib.libs.pykodi import log
    if not stackedpath.startswith('stack://'):
        result = [stackedpath]
    else:
        firstpath, path2 = stackedpath[8:].split(' , ')[0:2]

        path, filename = split(firstpath)
        if filename:
            filename2 = basename(path2)
            for regex in moviestacking:
                offset = 0
                while True:
                    match = regex.match(filename, offset)
                    match2 = regex.match(filename2, offset)
                    if match is not None and match2 is not None and match.group(1).lower() == match2.group(1).lower():
                        if match.group(2).lower() == match2.group(2).lower():
                            offset = match.start(3)
                            continue
                        # DEPRECATED: Returning the path to part1 doesn't seem to work in Kodi.
                        #  Not sure where I got that idea, but it shouldn't be used.
                        # Also, AB created the ones missing `group(3)` for awhile, but it is wrong.
                        # Adding both here so that file scanning still finds them.
                        pathbase = path + get_pathsep(path) + filename[:offset] + match.group(1)
                        result = [
                            pathbase + match.group(3) + match.group(4),
                            pathbase + match.group(4),
                            firstpath]
                    break
        else: # folder stacking
            pass # I can't even get Kodi to add stacked VIDEO_TS rips period
        if not result:

# Path: lib/libs/pykodi.py
# def log(message, level=xbmc.LOGDEBUG, tag=None):
#     if is_addon_watched() and level < xbmc.LOGNOTICE:
#         # Messages from this add-on are being watched, elevate to NOTICE so Kodi logs it
#         level_tag = _log_level_tag_lookup[level] + ': ' if level in _log_level_tag_lookup else ''
#         level = xbmc.LOGNOTICE
#     else:
#         level_tag = ''
# 
#     if isinstance(message, (dict, list)) and len(message) > 300:
#         message = str(message)
#     elif isinstance(message, unicode):
#         message = message.encode('utf-8')
#     elif not isinstance(message, str):
#         message = json.dumps(message, cls=UTF8PrettyJSONEncoder)
# 
#     addontag = ADDONID if not tag else ADDONID + ':' + tag
#     file_message = '%s[%s] %s' % (level_tag, addontag, scrub_message(message))
#     xbmc.log(file_message, level)


# Path: lib/libs/utils.py
import re
import xbmc
from collections import namedtuple
from os.path import split, basename, dirname
from lib.libs.pykodi import log

    if not stackedpath.startswith('stack://'):
        result = [stackedpath]
    else:
        firstpath, path2 = stackedpath[8:].split(' , ')[0:2]

        path, filename = split(firstpath)
        if filename:
            filename2 = basename(path2)
            for regex in moviestacking:
                offset = 0
                while True:
                    match = regex.match(filename, offset)
                    match2 = regex.match(filename2, offset)
                    if match is not None and match2 is not None and match.group(1).lower() == match2.group(1).lower():
                        if match.group(2).lower() == match2.group(2).lower():
                            offset = match.start(3)
                            continue
                        # DEPRECATED: Returning the path to part1 doesn't seem to work in Kodi.
                        #  Not sure where I got that idea, but it shouldn't be used.
                        # Also, AB created the ones missing `group(3)` for awhile, but it is wrong.
                        # Adding both here so that file scanning still finds them.
                        pathbase = path + get_pathsep(path) + filename[:offset] + match.group(1)
                        result = [
                            pathbase + match.group(3) + match.group(4),
                            pathbase + match.group(4),
                            firstpath]
                    break
        else: # folder stacking
            pass # I can't even get Kodi to add stacked VIDEO_TS rips period
        if not result:

            log("Couldn't get an unstacked path from \"{0}\"".format(stackedpath), xbmc.LOGWARNING)