Example #1
0
def dbg():
    if config.dev_mode():
        import web_pdb
        if not web_pdb.WebPdb.active_instance:
            import webbrowser
            webbrowser.open('http://127.0.0.1:5555')
        web_pdb.set_trace()
Example #2
0
def regexDbg(item, patron, headers, data=''):
    if config.dev_mode():
        import json, urllib2, webbrowser
        url = 'https://regex101.com'

        if not data:
            html = httptools.downloadpage(
                item.url, headers=headers,
                ignore_response_code=True).data.replace("'", '"')
            html = re.sub('\n|\t', ' ', html)
        else:
            html = data
        headers = {'content-type': 'application/json'}
        data = {
            'regex': patron,
            'flags': 'gm',
            'testString': html,
            'delimiter': '"""',
            'flavor': 'python'
        }
        r = urllib2.Request(url + '/api/regex',
                            json.dumps(data, encoding='latin1'),
                            headers=headers)
        r = urllib2.urlopen(r).read()
        permaLink = json.loads(r)['permalinkFragment']
        webbrowser.open(url + "/r/" + permaLink)
Example #3
0
 def scheduleUpdater(self):
     if not config.dev_mode():
         updaterCheck()
         self.updaterPeriod = config.get_setting('addon_update_timer')
         schedule.every(
             self.updaterPeriod).hours.do(updaterCheck).tag('updater')
         logger.debug('scheduled updater every ' + str(self.updaterPeriod) +
                      ' hours')
Example #4
0
def check_quickfixes(item):
    logger.info()

    if not config.dev_mode():
        from platformcode import updater
        return updater.check_addon_init()
    else:
        return False
Example #5
0
def start():
    """ First function that is executed when entering the plugin.
    Within this function all calls should go to
    functions that we want to execute as soon as we open the plugin.
    """
    logger.debug()

    if not config.dev_mode():
        try:
            with open(config.changelogFile, 'r') as fileC:
                changelog = fileC.read()
                if changelog.strip():
                    platformtools.dialog_ok('Kodi on Demand', 'Aggiornamenti applicati:\n' + changelog)
            os.remove(config.changelogFile)
        except:
            pass
Example #6
0
def start():
    """ Primera funcion que se ejecuta al entrar en el plugin.
    Dentro de esta funcion deberian ir todas las llamadas a las
    funciones que deseamos que se ejecuten nada mas abrir el plugin.
    """
    logger.info()
    #config.set_setting('show_once', True)
    # Test if all the required directories are created
    config.verify_directories_created()
    # controlla se l'utente ha qualche problema di connessione
    # se lo ha: non lo fa entrare nell'addon
    # se ha problemi di DNS avvia ma lascia entrare
    # se tutto ok: entra nell'addon

    from specials.checkhost import test_conn
    import threading
    threading.Thread(target=test_conn, args=(True, not config.get_setting('resolver_dns'), True, [], [], True)).start()

    if not config.dev_mode():
        from platformcode import updater
        updater.showSavedChangelog()
Example #7
0
def start():
    """ First function that is executed when entering the plugin.
    Within this function all calls should go to
    functions that we want to execute as soon as we open the plugin.
    """
    logger.debug()
    # config.set_setting('show_once', True)
    # Test if all the required directories are created
    config.verify_directories_created()
    # check if the user has any connection problems
    # if it has: it does not enter the addon
    # if it has DNS problems start but let in
    # if everything is ok: enter the addon

    from platformcode.checkhost import test_conn
    import threading
    threading.Thread(target=test_conn,
                     args=(True, not config.get_setting('resolver_dns'), True,
                           [], [], True)).start()

    if not config.dev_mode():
        from platformcode import updater
        updater.showSavedChangelog()
Example #8
0
def getmainlist(view="thumb_"):
    logger.info()
    itemlist = list()

    if config.dev_mode():
        itemlist.append(
            Item(title="Redirect",
                 channel="checkhost",
                 action="check_channels",
                 thumbnail='',
                 category=config.get_localized_string(30119),
                 viewmode="thumbnails"))
    # Main Menu Channels
    if addon.getSetting('enable_news_menu') == "true":
        itemlist.append(
            Item(title=config.get_localized_string(30130),
                 channel="news",
                 action="mainlist",
                 thumbnail=get_thumb("news.png", view),
                 category=config.get_localized_string(30119),
                 viewmode="thumbnails",
                 context=[{
                     "title": config.get_localized_string(70285),
                     "channel": "shortcuts",
                     "action": "SettingOnPosition",
                     "category": 7,
                     "setting": 1
                 }]))

    if addon.getSetting('enable_channels_menu') == "true":
        itemlist.append(
            Item(title=config.get_localized_string(30118),
                 channel="channelselector",
                 action="getchanneltypes",
                 thumbnail=get_thumb("channels.png", view),
                 view=view,
                 category=config.get_localized_string(30119),
                 viewmode="thumbnails"))

    if addon.getSetting('enable_search_menu') == "true":
        itemlist.append(
            Item(title=config.get_localized_string(30103),
                 channel="search",
                 path='special',
                 action="mainlist",
                 thumbnail=get_thumb("search.png", view),
                 category=config.get_localized_string(30119),
                 viewmode="list",
                 context=[{
                     "title": config.get_localized_string(60412),
                     "action": "setting_channel_new",
                     "channel": "search"
                 }, {
                     "title": config.get_localized_string(70286),
                     "channel": "shortcuts",
                     "action": "SettingOnPosition",
                     "category": 5,
                     "setting": 1
                 }]))

    if addon.getSetting('enable_onair_menu') == "true":
        itemlist.append(
            Item(channel="filmontv",
                 action="mainlist",
                 title=config.get_localized_string(50001),
                 thumbnail=get_thumb("on_the_air.png"),
                 viewmode="thumbnails"))

    if addon.getSetting('enable_link_menu') == "true":
        itemlist.append(
            Item(title=config.get_localized_string(70527),
                 channel="kodfavorites",
                 action="mainlist",
                 thumbnail=get_thumb("mylink.png", view),
                 view=view,
                 category=config.get_localized_string(70527),
                 viewmode="thumbnails"))

    if addon.getSetting('enable_fav_menu') == "true":
        itemlist.append(
            Item(title=config.get_localized_string(30102),
                 channel="favorites",
                 action="mainlist",
                 thumbnail=get_thumb("favorites.png", view),
                 category=config.get_localized_string(30102),
                 viewmode="thumbnails"))

    if config.get_videolibrary_support() and addon.getSetting(
            'enable_library_menu') == "true":
        itemlist.append(
            Item(title=config.get_localized_string(30131),
                 channel="videolibrary",
                 action="mainlist",
                 thumbnail=get_thumb("videolibrary.png", view),
                 category=config.get_localized_string(30119),
                 viewmode="thumbnails",
                 context=[{
                     "title": config.get_localized_string(70287),
                     "channel": "shortcuts",
                     "action": "SettingOnPosition",
                     "category": 2,
                     "setting": 1
                 }, {
                     "title": config.get_localized_string(60568),
                     "channel": "videolibrary",
                     "action": "update_videolibrary"
                 }]))
    if downloadenabled != "false":
        itemlist.append(
            Item(title=config.get_localized_string(30101),
                 channel="downloads",
                 action="mainlist",
                 thumbnail=get_thumb("downloads.png", view),
                 viewmode="list",
                 context=[{
                     "title": config.get_localized_string(70288),
                     "channel": "shortcuts",
                     "action": "SettingOnPosition",
                     "category": 6
                 }]))

    thumb_setting = "setting_%s.png" % 0  # config.get_setting("plugin_updates_available")

    itemlist.append(
        Item(title=config.get_localized_string(30100),
             channel="setting",
             action="settings",
             thumbnail=get_thumb(thumb_setting, view),
             category=config.get_localized_string(30100),
             viewmode="list"))
    itemlist.append(
        Item(title=config.get_localized_string(30104) + " (v" +
             config.get_addon_version(with_fix=True) + ")",
             channel="help",
             action="mainlist",
             thumbnail=get_thumb("help.png", view),
             category=config.get_localized_string(30104),
             viewmode="list"))
    return itemlist
Example #9
0
def run(item=None):
    logger.info()
    if not item:
        # Extract item from sys.argv
        if sys.argv[2]:
            item = Item().fromurl(sys.argv[2])

        # If no item, this is mainlist
        else:
            if config.get_setting("start_page"):

                if not config.get_setting("custom_start"):
                    dictCategory = {
                        config.get_localized_string(70137): 'peliculas',
                        config.get_localized_string(30123): 'series',
                        config.get_localized_string(30124): 'anime',
                        config.get_localized_string(70018): 'infantiles',
                        config.get_localized_string(60513): 'documentales',
                        config.get_localized_string(70013): 'terror',
                        config.get_localized_string(70014): 'castellano',
                        config.get_localized_string(59976): 'latino',
                        config.get_localized_string(70171): 'torrent',
                    }
                    category = dictCategory[config.get_setting("category")]
                    item = Item(channel="news",
                                action="novedades",
                                extra=category,
                                mode='silent')
                else:
                    from specials import side_menu
                    item = Item()
                    item = side_menu.check_user_home(item)
                    item.start = True
            else:
                item = Item(channel="channelselector",
                            action="getmainlist",
                            viewmode="movie")
        if not config.get_setting('show_once'):
            if not config.dev_mode():
                from platformcode import updater
                updater.calcCurrHash()
            from platformcode import xbmc_videolibrary
            xbmc_videolibrary.ask_set_content(
                1, config.get_setting('videolibrary_kodi_force'))
            config.set_setting('show_once', True)

    logger.info(item.tostring())

    try:
        # If item has no action, stops here
        if item.action == "":
            logger.info("Item sin accion")
            return

        # Action for main menu in channelselector
        elif item.action == "getmainlist":
            import channelselector

            itemlist = channelselector.getmainlist()

            platformtools.render_items(itemlist, item)

        # Action for channel types on channelselector: movies, series, etc.
        elif item.action == "getchanneltypes":
            import channelselector
            itemlist = channelselector.getchanneltypes()

            platformtools.render_items(itemlist, item)

        # Action for channel listing on channelselector
        elif item.action == "filterchannels":
            import channelselector
            itemlist = channelselector.filterchannels(item.channel_type)

            platformtools.render_items(itemlist, item)

        # Special action for playing a video from the library
        elif item.action == "play_from_library":
            play_from_library(item)
            return

        elif item.action == "keymap":
            from platformcode import keymaptools
            if item.open:
                return keymaptools.open_shortcut_menu()
            else:
                return keymaptools.set_key()

        elif item.action == "delete_key":
            from platformcode import keymaptools
            return keymaptools.delete_key()

        elif item.action == "script":
            from core import tmdb
            if tmdb.drop_bd():
                platformtools.dialog_notification(
                    config.get_localized_string(20000),
                    config.get_localized_string(60011),
                    time=2000,
                    sound=False)
        elif item.action == "itemInfo":
            import base64
            platformtools.dialog_textviewer('Item info', item.parent)
        # Action in certain channel specified in "action" and "channel" parameters
        else:
            # Entry point for a channel is the "mainlist" action, so here we check parental control
            if item.action == "mainlist":
                #updater.checkforupdates() beta version checking for update, still disabled

                # Parental control
                # If it is an adult channel, and user has configured pin, asks for it
                if channeltools.is_adult(item.channel) and config.get_setting(
                        "adult_request_password"):
                    tecleado = platformtools.dialog_input(
                        "", config.get_localized_string(60334), True)
                    if tecleado is None or tecleado != config.get_setting(
                            "adult_password"):
                        return
            # # Actualiza el canal individual
            # if (item.action == "mainlist" and item.channel != "channelselector" and
            #             config.get_setting("check_for_channel_updates") == True):
            #     from core import updater
            #     updater.update_channel(item.channel)

            # Checks if channel exists
            if os.path.isfile(
                    os.path.join(config.get_runtime_path(), 'channels',
                                 item.channel + ".py")):
                CHANNELS = 'channels'
            else:
                CHANNELS = 'specials'
            channel_file = os.path.join(config.get_runtime_path(), CHANNELS,
                                        item.channel + ".py")

            logger.info("channel_file= " + channel_file)

            channel = None

            if os.path.exists(channel_file):
                try:
                    channel = __import__(CHANNELS + item.channel, None, None,
                                         [CHANNELS + item.channel])
                except ImportError:
                    importer = "import " + CHANNELS + "." + item.channel + " as channel"
                    exec(importer)

            logger.info("Running channel %s | %s" %
                        (channel.__name__, channel.__file__))

            # Special play action
            if item.action == "play":
                #define la info para trakt
                try:
                    trakt_tools.set_trakt_info(item)
                except:
                    pass
                logger.info("item.action=%s" % item.action.upper())
                # logger.debug("item_toPlay: " + "\n" + item.tostring('\n'))

                # First checks if channel has a "play" function
                if hasattr(channel, 'play'):
                    logger.info("Executing channel 'play' method")
                    itemlist = channel.play(item)
                    b_favourite = item.isFavourite
                    # Play should return a list of playable URLS
                    if len(itemlist) > 0 and isinstance(itemlist[0], Item):
                        item = itemlist[0]
                        if b_favourite:
                            item.isFavourite = True
                        platformtools.play_video(item)

                    # Permitir varias calidades desde play en el canal
                    elif len(itemlist) > 0 and isinstance(itemlist[0], list):
                        item.video_urls = itemlist
                        platformtools.play_video(item)

                    # If not, shows user an error message
                    else:
                        platformtools.dialog_ok(
                            config.get_localized_string(20000),
                            config.get_localized_string(60339))

                # If player don't have a "play" function, not uses the standard play from platformtools
                else:
                    logger.info("Executing core 'play' method")
                    platformtools.play_video(item)

            # Special action for findvideos, where the plugin looks for known urls
            elif item.action == "findvideos":

                # First checks if channel has a "findvideos" function
                if hasattr(channel, 'findvideos'):
                    itemlist = getattr(channel, item.action)(item)
                    itemlist = servertools.filter_servers(itemlist)

                # If not, uses the generic findvideos function
                else:
                    logger.info("No channel 'findvideos' method, "
                                "executing core method")
                    itemlist = servertools.find_video_items(item)

                if config.get_setting("max_links", "videolibrary") != 0:
                    itemlist = limit_itemlist(itemlist)

                from platformcode import subtitletools
                subtitletools.saveSubtitleName(item)

                platformtools.render_items(itemlist, item)

            # Special action for adding a movie to the library
            elif item.action == "add_pelicula_to_library":
                videolibrarytools.add_movie(item)

            # Special action for adding a serie to the library
            elif item.action == "add_serie_to_library":
                videolibrarytools.add_tvshow(item, channel)

            # Special action for downloading all episodes from a serie
            elif item.action == "download_all_episodes":
                from specials import downloads
                item.action = item.extra
                del item.extra
                downloads.save_download(item)

            # Special action for searching, first asks for the words then call the "search" function
            elif item.action == "search":
                logger.info("item.action=%s" % item.action.upper())

                last_search = ""
                last_search_active = config.get_setting(
                    "last_search", "search")
                if last_search_active:
                    try:
                        current_saved_searches_list = list(
                            config.get_setting("saved_searches_list",
                                               "search"))
                        last_search = current_saved_searches_list[0]
                    except:
                        pass

                tecleado = platformtools.dialog_input(last_search)
                if tecleado is not None:
                    if last_search_active and not tecleado.startswith("http"):
                        from specials import search
                        search.save_search(tecleado)

                    if 'search' in dir(channel):
                        itemlist = channel.search(item, tecleado)
                    else:
                        from core import support
                        itemlist = support.search(channel, item, tecleado)
                else:
                    return

                platformtools.render_items(itemlist, item)

            # For all other actions
            else:
                # import web_pdb; web_pdb.set_trace()
                logger.info("Executing channel '%s' method" % item.action)
                itemlist = getattr(channel, item.action)(item)
                if config.get_setting('trakt_sync'):
                    token_auth = config.get_setting("token_trakt", "trakt")
                    if not token_auth:
                        trakt_tools.auth_trakt()
                    else:
                        import xbmc
                        if not xbmc.getCondVisibility(
                                'System.HasAddon(script.trakt)'
                        ) and config.get_setting('install_trakt'):
                            trakt_tools.ask_install_script()
                    itemlist = trakt_tools.trakt_check(itemlist)
                else:
                    config.set_setting('install_trakt', True)

                platformtools.render_items(itemlist, item)

    except urllib2.URLError, e:
        import traceback
        logger.error(traceback.format_exc())

        # Grab inner and third party errors
        if hasattr(e, 'reason'):
            logger.error("Razon del error, codigo: %s | Razon: %s" %
                         (str(e.reason[0]), str(e.reason[1])))
            texto = config.get_localized_string(
                30050)  # "No se puede conectar con el sitio web"
            platformtools.dialog_ok(config.get_localized_string(20000), texto)

        # Grab server response errors
        elif hasattr(e, 'code'):
            logger.error("Codigo de error HTTP : %d" % e.code)
            # "El sitio web no funciona correctamente (error http %d)"
            platformtools.dialog_ok(
                config.get_localized_string(20000),
                config.get_localized_string(30051) % e.code)
Example #10
0
# -*- coding: utf-8 -*-
# ------------------------------------------------------------
# XBMC entry point
# ------------------------------------------------------------

import os
import sys
from threading import Thread

import xbmc
from platformcode import config, logger

logger.info("init...")

librerias = xbmc.translatePath(os.path.join(config.get_runtime_path(), 'lib'))
sys.path.insert(0, librerias)

if not config.dev_mode():
    from platformcode import updater
    Thread(target=updater.timer())

from platformcode import launcher

if sys.argv[2] == "":
    launcher.start()
    launcher.run()
else:
    launcher.run()