예제 #1
0
    def item_by_type(self, data):
        item_type = data.get(SC.ITEM_TYPE, None)
        if item_type == SC.ITEM_DIR:
            self.item = SCDir(data)
        elif item_type == SC.ITEM_VIDEO:
            self.item = SCVideo(data)
        elif item_type == SC.ITEM_HPDIR:
            self.item = SCHPDir(data)
        elif item_type == SC.ITEM_CUSTOM_FILTER:
            self.item = SCCustomFilterDir(data)
        elif item_type == SC.ITEM_CMD:
            self.item = SCCmd(data)
        elif item_type == SC.ITEM_ACTION:
            self.item = SCAction(data)
        elif item_type == SC.ITEM_NEXT:
            self.item = SCNext(data)
        elif item_type == 'ldir':
            self.item = SCLDir(data)
        elif item_type == 'add_custom_filter':
            self.item = SCAction(data)
        else:
            info('Nepodporovana polozka {} {}'.format(item_type, data))

        try:
            self.visible = self.item.visible()
        except:
            pass
    def list(self):
        self.succeeded = True
        pinned = self.get_pinned()
        hidden = self.storage.get('h-{}'.format(self.url))
        self.pinned_custom()
        if self.url == '/':
            info('Mame HP, skontrolujeme pripnute polozky')
            self.pinned_hp()

        for i in self.response.get(SC.ITEM_MENU):
            item = SCItem(i)

            if item.visible:
                # info('pin {} {}'.format(pinned, i.get(SC.ITEM_URL)))
                if pinned is not None and i.get(SC.ITEM_URL) and pinned.get(
                        i.get(SC.ITEM_URL)):
                    item.li().setProperty('SpecialSort', GUI.TOP)
                    info('TOP {}'.format(item.li().getProperty('SpecialSort')))
                    self.items_pinned.append(item.get())
                    item.visible = False

                if hidden is not None and hidden.get(item.li().getLabel()):
                    item.visible = False

            if item.visible:
                self.items.append(item.get())
 def action_cmd(self):
     url = self.args.get('url')
     if url.startswith('cmd://'):
         cmd = url[6:]
         info('CMD: {}'.format(cmd))
         exec_build_in(cmd)
         self.send_end = True
 def action_csearch(self):
     self.succeeded = True
     self.end_of_directory()
     _id = self.args.get(SC.ITEM_ID)
     home_win.setProperty('SC.search', '{}'.format(_id))
     search = dinput('', '', xbmcgui.INPUT_TYPE_TEXT)
     home_win.clearProperty('SC.search')
     info('search string: {}'.format(search))
     if search == '':
         exec_build_in('Action(Back)')
         return
     query = {'search': search, SC.ITEM_ID: _id}
     if _id.startswith('search-people'):
         query.update({'ms': '1'})
     st = List(_id)
     st.add(search)
     debug('SEARCH: _ID "{}" search for "{}" people "{}"'.format(
         _id, search, 1 if 'ms' in query else 0))
     url = '/Search/{}?{}'.format(_id, urlencode(query))
     info('search url: {}'.format(url))
     self.url = url
     self.call_url()
     if 'msgERROR' in self.response.get('system', {}):
         self.msg_error()
         exec_build_in('Action(Back)')
         return
     plugin_url = create_plugin_url({'url': url})
     container_update(plugin_url)
     return
 def action_pin(self):
     pinned = self.get_pinned()
     if pinned and self.args.get(SC.ITEM_ID) in pinned:
         info('remove')
         del pinned[self.args.get(SC.ITEM_ID)]
     else:
         info('add')
         pinned.update({self.args.get(SC.ITEM_ID): True})
     self.set_pinned(pinned)
     container_refresh()
예제 #6
0
 def __init__(self, data):
     self.item = None
     self.visible = False
     if SC.ITEM_TYPE in data:
         self.item_by_type(data)
     elif SC.ITEM_STRMS in data:
         info('PLAY ITEM')
         self.item = SCPlayItem(data)
     else:
         info('Neznama polozka {}'.format(str(data)))
    def end_of_directory(self):
        if self.send_end:
            return
        self.send_end = True

        info('endOfDirectory s: {} u: {} c: {}'.format(self.succeeded,
                                                       self.update_listing,
                                                       self.cache_to_disc))
        xbmcplugin.endOfDirectory(params.handle,
                                  succeeded=self.succeeded,
                                  updateListing=self.update_listing,
                                  cacheToDisc=self.cache_to_disc)
 def pinned_hp(self):
     st = list_hp
     for itm in st.get():
         info('HP item: {}'.format(itm))
         item = SCItem({
             'type': SC.ITEM_HPDIR,
             'title': itm.get(SC.ITEM_ID),
             'url': itm.get(SC.ITEM_URL)
         })
         if item.visible:
             info('Pridavam item na HP: {}'.format(itm.get(SC.ITEM_ID)))
             item.li().setProperty('SpecialSort', GUI.TOP)
             self.items_pinned.append(item.get())
 def play(self):
     try:
         item = SCItem(self.response)
         url, li, status, selected = item.get()
         if SC.ACTION in self.args and SC.ACTION_DOWNLOAD in self.args[
                 SC.ACTION]:
             filename = selected.get('stream_info', {}).get('filename')
             if filename is None:
                 dok(Strings.txt(Strings.RESOLVE_ERROR_H1),
                     Strings.txt(Strings.RESOLVE_ERROR_L1))
                 return
             from threading import Thread
             worker = Thread(target=download,
                             args=(url, get_setting('download.path'),
                                   filename))
             worker.start()
             return
         debug(
             '----------------------------------------------------------------------------------------------------'
         )
         debug('play url: {}'.format(self.url))
         debug('play selected: {}'.format(dumps(selected)))
         # debug('play response: {}'.format(dumps(self.response)))
         # debug('play item: {}'.format(li))
         debug(
             '----------------------------------------------------------------------------------------------------'
         )
         self.response['strms'] = selected
         home_win.setProperty('SC.play_item', dumps(self.response))
         if params.handle == -1:
             debug('HANDLE -1')
             xbmc.Player().play(url, li)
         else:
             debug('HANDLE {}'.format(params.handle))
             self.succeeded = True
             self.cache_to_disc = False
             xbmcplugin.setResolvedUrl(params.handle, True, li)
             self.end_of_directory()
     except:
         # dok('ERROR', 'Chyba pri prehravani')
         info("ERR: {}".format(str(traceback.format_exc())))
         self.end_of_directory()
    def run(self):

        if SC.ITEM_URL in self.args:
            self.url = self.args.get(SC.ITEM_URL)

        if self.url == '/' and xbmc.Player().isPlayingVideo(
        ) and home_win.getProperty('{}.play'.format(ADDON_ID)):
            container_update('special://home', True)
            self.succeeded = False
            self.end_of_directory()
            return

        if SC.ITEM_URL in self.args and self.args.get(
                SC.ITEM_URL).startswith('http'):
            self.args.update({SC.ITEM_ACTION: SC.ACTION_PLAY_URL})

        info('Start: {} [{}]'.format(str(self.args), self.url))

        if 'title' in self.args:
            home_win.setProperty('SCTitle', self.args.get('title'))
        else:
            home_win.clearProperty('SCTitle')

        if SC.ACTION in self.args:
            exit_code = self.action()
            if exit_code is True:
                return
        elif 'play' in self.args:
            '''
            stara URL zo SC CS&SK pre play aby fungovala kniznica
            '''
            self.url = self.args.get('play')
            self.call_url_and_response()
        else:
            self.call_url_and_response()
        self.end()
예제 #11
0
    def _set_info(self, item_info):
        if self.debug:
            debug('set_info {}'.format(item_info))
        self.info.update(item_info)
        try:
            if SC.ITEM_TITLE in item_info:
                title = '{}'.format(item_info.get(SC.ITEM_TITLE))
                self.item.setLabel(title)

            if self.data.get('play'):
                if 'otitle' in item_info:
                    item_info.update({SC.ITEM_TITLE: item_info['otitle']})
                    del item_info['otitle']

                if 'epname' in item_info:
                    item_info.update({SC.ITEM_TITLE: item_info['epname']})
                    del item_info['epname']
            else:
                if 'epname' in item_info:
                    del item_info['epname']

                if 'otitle' in item_info:
                    del item_info['otitle']

            for i, e in enumerate(item_info):
                # debug('set info {} {}'.format(i, e))
                self.item.setProperty(e, '{}'.format(item_info[e]))

            if item_info.get('mediatype',
                             '') == 'season' and item_info.get('episode'):
                item = SCKODIItem(self.data.get(SC.ITEM_ID))
                data = item.data
                total_episodes = item_info.get('episode')
                watched = len(
                    data.get('series:{}'.format(item_info.get('season')), {}))
                debug('Mame seriu {} s {}/{} epizodami'.format(
                    item_info.get('season'), watched, total_episodes))
                if watched >= total_episodes:
                    item_info.update({'playcount': '1'})

            self.item.setInfo('video', item_info)
            self.item.setProperty('original_title',
                                  item_info.get('originaltitle'))
            self.info_set = True
        except Exception as e:
            import traceback
            info(
                '-----------------------------------------------------------------'
            )
            info('set info error [{}]'.format(str(traceback.format_exc())))
            info(
                '-----------------------------------------------------------------'
            )
def upload_log_file(name=None):
    from resources.lib.gui.dialog import dnotify, dselect
    from resources.lib.system import user_agent, Http

    if name is None:
        name = get_app_name().lower()

    url = 'https://paste.kodi.tv/'
    log_path = translate_path('special://logpath/')
    log_file = os.path.join(log_path, '%s.log' % name.lower())
    if not file_exists(log_file):
        return dnotify(message='Log File not found, likely logging is not enabled.')
    try:
        f = open(log_file, 'r', encoding='utf-8', errors='ignore')
        text = f.read()
        f.close()
        response = Http.post(url + 'documents', data=text.encode('utf-8', errors='ignore'),
                             headers={'User-Agent': user_agent()})
        if 'key' in response.json():
            result = url + response.json()['key']
            debug('{} log file uploaded to: {}'.format(name, result))
            list_items = [('url:  {}'.format(str(result)), str(result))]
            from sys import platform as sys_platform
            supported_platform = any(value in sys_platform for value in ('win32', 'linux2', 'darwin'))
            if supported_platform:
                list_items += [('-- Copy url To Clipboard', ' ')]
            dselect([i[0] for i in list_items], 'Upload')
            if supported_platform:
                copy2clip(str(result))
        elif 'message' in response.json():
            dnotify('', '{} Log upload failed: {}'.format(name, str(response.json()['message'])))
            info('{} Log upload failed: {}'.format(name, str(response.json()['message'])))
        else:
            dnotify('', '{} Log upload failed'.format(name))
            info('%s Log upload failed: %s' % (name, response.text))
    except:
        info('{} log upload failed'.format(name))
        dnotify('', 'pastebin post failed: See log for more info')
    def action(self):
        action = self.args.get(SC.ITEM_ACTION)
        if action == SC.ACTION_PLAY_URL:
            self.play_url(self.args.get(SC.ITEM_URL))
            self.succeeded = True
        elif action == SC.ACTION_CMD:
            self.action_cmd()
        elif action == 'intro':
            intro(2, True)
        elif action == SC.ACTION_PIN:
            self.action_pin()
        elif action == SC.ACTION_CSEARCH:
            self.action_csearch()
        elif action == SC.ACTION_LAST:
            self.action_last()
        elif action == 'nextep':
            self.action_next_ep()
        elif action == 'update_nextep':
            self.action_update_next_ep()
            return True
        elif action == 'search_next_episodes':
            self.action_search_next_episodes()
        elif action == SC.ACTION_DEBUG:
            from resources.lib.kodiutils import check_set_debug

            check_set_debug(True)
        elif action == SC.ACTION_DOWNLOAD:
            self.url = self.args.get(SC.ITEM_DOWNLOAD)
            self.call_url_and_response()
        elif action == SC.ACTION_BUFFER:
            set_kodi_cache_size()
        elif action == SC.ACTION_ANDROID:
            self.action_android()
        elif action == SC.ACTION_ADD2HP:
            self.action_add2hp()
        elif action == SC.ACTION_DEL2HP:
            self.action_add2hp(True)
        elif action == SC.ACTION_ADD_CUSTOM_FILTER:
            self.action_add_custom_filter()
        elif action == SC.ACTION_DEL_CUSTOM_FILTER:
            self.action_add_custom_filter(True)
        elif action == SC.ACTION_REMOVE_FROM_LIST:
            self.action_remove_from_list()
        elif action == SC.ACTION_UPDATE_ADDON:
            update_addon()
        elif 'trakt.' in action:
            from resources.lib.trakt.Trakt import trakt
            trakt.action(action, self)
            return True
        elif action in ['add_to_library', 'add_to_library_sub']:
            lib = List(SC.ITEM_LIBRARY)
            lib.add(self.args.get(SC.ITEM_ID))
            if action == 'add_to_library_sub':
                sub = List(SC.ITEM_LIBRARY_SUB)
                sub.add(self.args.get(SC.ITEM_ID))
            container_refresh()
        elif action == 'remove_from_sub':
            lib = List(SC.ITEM_LIBRARY)
            lib.add(self.args.get(SC.ITEM_ID), True)
            if action == 'remove_from_sub':
                sub = List(SC.ITEM_LIBRARY_SUB)
                sub.add(self.args.get(SC.ITEM_ID), True)
            container_refresh()
        elif action == 'autocomplet':
            from resources.lib.services.autocomplete import Autocomplete
            Autocomplete(self.args)
            return True
        elif action == SC.ACTION_DEL_PREFERRED_LANGUAGE:
            del preferred_lang_list[self.args.get(SC.ITEM_ID)]
            container_refresh()
            return
        elif action == SC.ACTION_SET_PREFERRED_LANGUAGE:
            lang_list = Sc.get('/Lang/{}'.format(self.args.get(SC.ITEM_ID)))
            debug('parametre: {} / langs: {}'.format(self.args, lang_list))
            ret = dselect(lang_list,
                          Strings.txt(Strings.CONTEXT_ADD_PREF_LANG))
            if ret > -1:
                st = preferred_lang_list
                st[self.args.get(SC.ITEM_ID)] = lang_list[ret]
                debug('znovelene: {} / {}'.format(
                    ret, st[self.args.get(SC.ITEM_ID)]))
                container_refresh()
            return
        else:
            info('Neznama akcia: {}'.format(action))
        return False
예제 #14
0
# -*- coding: utf-8 -*-
import time
import traceback
import xbmc

try:
    xbmc._set_log_level(1)
except:
    pass

from resources.lib.streamcinema import Scinema
from resources.lib.common.logger import info

try:
    start = time.time()
    Scinema().run()
    end = time.time()
    info('{0} took {1:.2f}ms'.format('ALL', (end - start) * 1000))
except:

    info('-----------------------------------------------------------------')
    info('main error [{}]'.format(str(traceback.format_exc())))
    info('-----------------------------------------------------------------')
    pass
 def run(self):
     file = self.select_stream()
     info('Vybrany stream: {}'.format(file))
     item = SCItem(self.data)
     # xbmcplugin.setResolvedUrl(params.handle, True, item)
     pass
 def play_url(self, url, li=None):
     info('playUrl: {} / {}'.format(url, li))
     xbmc.Player().play(url, listitem=li)
예제 #17
0
    def resolve(self):
        data = self.data
        del (data[SC.ITEM_URL])
        self.streams = self.input.get(SC.ITEM_STRMS)
        self.filter()

        items = []
        matrix = []
        for s in self.streams:
            debug('ideme vytvorit listItems zo streamov')
            s.update(data)
            itm = SCStreamSelect(s)
            x = itm.get()
            title_items = [
                '[B]{}[/B] - '.format(s.get(SC.ITEM_LANG)),
                '[B]{}[/B] '.format(s.get(SC.ITEM_QUALITY)),
                '{} '.format(s.get(SC.ITEM_SIZE)),
                '{}{}'.format(s.get(SC.ITEM_VIDEO_INFO),
                              s.get(SC.ITEM_AUDIO_INFO)),
            ]
            matrix.append(title_items)
            items.append(x[1])
        # matrix = make_table(matrix)
        # info('matrix: {}'.format(matrix))
        for i, itm in enumerate(items):
            itm.setProperty('old_title', itm.getLabel())
            itm.setLabel(' '.join(matrix[i]))

        if len(
                items
        ) > 1 or SC.ACTION_SELECT_STREAM in self.params or SC.ACTION_DOWNLOAD in self.params:
            pos = dselect(items,
                          heading=items[0].getProperty('old_title'),
                          use_details=True)
            # info('post: {} | {}'.format(pos, json.dumps(self.data)))
            if pos is False or pos == -1:
                raise BaseException
            res = items[pos]
            self.selected = self.streams[pos]
        elif len(items) == 1:
            res = items[0]
            self.selected = self.streams[
                0] if self.selected is None else self.selected
        else:
            raise BaseException

        url = res.getPath()
        # info('vybrany stream: {} / {}'.format(res.getPath(), self.selected))
        if res.getProperty(SC.ITEM_PROVIDER) == SC.PROVIDER:
            resp = Sc.get(res.getPath())
            kr = Kraska()
            try:
                ident = resp.get(SC.ITEM_IDENT)
                debug('ideme resolvovat ident {} na kra.sk'.format(ident))
                url = kr.resolve(ident)
            except ResolveException as e:
                dok(Strings.txt(Strings.RESOLVE_ERROR_H1),
                    Strings.txt(Strings.RESOLVE_ERROR_L1))
                raise BaseException
            except:
                raise BaseException
            if res.getProperty(SC.ITEM_SUBS):
                debug('subor ma titulky, tak ich natahujem')
                part = res.getProperty(SC.ITEM_SUBS).split('/file/')
                self.item.setSubtitles([kr.resolve(part[1])])
            else:
                info('nemame titulky')

        info('resolve: {}'.format(url))
        if 'lid' in data:
            lid = 'p-{}'.format(
                data.get('lid')) if parental_history() else data.get('lid')
            st = List(lid, max_items=20)
            st.add(res.getProperty(SC.ITEM_ID))
        self.item.setPath(url)
        self.item.setLabel(res.getProperty('original_title'))
        # home_win.setProperty('SC-lite-item', '{}'.format(res.getProperty(SC.ITEM_ID)))

        if 'unique_ids' in self.input.get(SC.ITEM_INFO):
            unique_ids = self.input.get(SC.ITEM_INFO).get('unique_ids')
            home_win.setProperty('script.trakt.ids',
                                 '{}'.format(dumps(unique_ids)))
            home_win.setProperty('{}.ids'.format(ADDON_ID),
                                 '{}'.format(dumps(unique_ids)))
예제 #18
0
def intro(step=None, credentials_only=False):
    info('Step: {}'.format(step))
    auto_close = 60

    if step is None and get_setting('kraska.user') != '':
        info('Uz nieje treba intro....')
        return
    elif step is None:
        step = 1

    if step == 1:
        start = dyesno(Strings.txt(Strings.INTRO_STEP1_H1),
                       Strings.txt(Strings.INTRO_STEP1_L1),
                       autoclose=auto_close)
        info('RET: [{}] [{}]'.format(start, 'Ano' if start else 'Nie'))
        return intro(step + 1, credentials_only) if start == 1 else 0

    if step == 2:
        user = dinput(Strings.txt(Strings.INTRO_STEP2_H1),
                      get_setting('kraska.user'))
        info(Strings.INTRO_STEP1_H1)
        info(Strings.txt(Strings.INTRO_STEP1_H1))
        info('RET: {}'.format(user))
        settings.set_setting('kraska.user', user)
        if user != settings.get_setting('kraska.user'):
            _remove_settings_file()
            debug('Zmazanie nastaveni')
            return 0

        return intro(step + 1, credentials_only) if user != '' else 0

    if step == 3:
        password = dinput(Strings.txt(Strings.INTRO_STEP3_H1), '')
        info('RET: {}'.format(password))
        settings.set_setting('kraska.pass', password)
        if password != settings.get_setting('kraska.pass'):
            debug('skusam znova zapisat heslo...')
            settings.set_setting('kraska.pass', password)
        kr = Kraska(p=password)
        data = kr.user_info()
        return intro(step +
                     1, credentials_only) if data is False else intro(step + 2)

    if step == 4:
        dok(Strings.txt(Strings.INTRO_STEP4_H1),
            Strings.txt(Strings.INTRO_STEP4_L1))
        return intro(step - 2, credentials_only)

    if step == 5 and credentials_only is False:
        res = dyesno(Strings.txt(Strings.INTRO_STEP5_H1),
                     Strings.txt(Strings.INTRO_STEP5_L1))
        if res:
            open_settings('1.0')
예제 #19
0
from resources.lib.intro import intro
from resources.lib.kodiutils import get_kodi_version, get_screen_width, get_screen_height, \
    get_app_name, get_uuid
from resources.lib.common import logger
from resources.lib.services.service import service

logger.APP = 'SC:S'
logger.info("Start sw: [{}] kodi ver: [{}] screen [{}x{}] uuid: [{}]".format(
    get_app_name(), get_kodi_version(), get_screen_width(),
    get_screen_height(), get_uuid()))

intro()
service.run()
 def set_pinned(self, data):
     info('new pined {} for {}'.format(data, self.pinned_key()))
     self.storage[self.pinned_key()] = data