コード例 #1
0
def initializeSession():
    # リセット
    Common.SET('garapon_session', '')
    # データ取得
    response_body = Request().auth()
    if response_body:
        response_data = json.loads(response_body)
        if response_data['status'] == 1:
            if response_data['login'] == 1:
                gtvsession = response_data['gtvsession']
                Common.SET('garapon_session', gtvsession)
                Common.notify('Session initialized successfully')
                return True
            else:
                Common.log('auth failed', response_body, error=True)
                Common.notify('Session initialization failed')
                return False
        else:
            Common.log('auth failed', response_body, error=True)
            Common.notify('Session initialization failed')
            return False
    else:
        Common.log('empty response', error=True)
        Common.notify('Session initialization failed')
        return False
コード例 #2
0
 def beginEdit(self, name, ch, g0, g1):
     if ch:
         # keyword
         Common.SET('keyword', name)
         # channel
         channel = Channel().search(ch)
         Common.SET('channel', channel['name'])
         # genre
         genre = Genre().search(g0, g1)
         Common.SET('g0', genre['name0'])
         Common.SET(genre['id'], genre['name1'])
     else:
         # スマートリストでtitleが一致するものをダイアログに設定
         for item in filter(lambda x: x['title'] == name, self.getList()):
             for key, val in item.items():
                 Common.SET(key, val)
コード例 #3
0
def initializeChannel():
    # リセット
    Common.SET('garapon_ch', '')
    # チャンネル情報を取得
    response_body = Request().channel()
    if response_body:
        response_data = json.loads(response_body)
        if response_data['status'] == 1:
            # チャンネル情報をファイルに書き出す
            Common.write_json(Common.CHANNEL_FILE, response_data)
            # チャンネル数を設定
            Common.SET('garapon_ch', '%d channels' % len(response_data['ch_list'].keys()))
            # 設定画面のテンプレートを読み込む
            template = Common.read_file(Common.TEMPLATE_FILE)
            # テンプレートに書き出すジャンル情報
            genre = Genre().getLabel()
            # チャンネル情報とあわせてテンプレートに適用
            source = template.format(
                channel=Channel().getLabel(),
                g0=genre['g0'],
                g00=genre['g00'],
                g01=genre['g01'],
                g02=genre['g02'],
                g03=genre['g03'],
                g04=genre['g04'],
                g05=genre['g05'],
                g06=genre['g06'],
                g07=genre['g07'],
                g08=genre['g08'],
                g09=genre['g09'],
                g10=genre['g10'],
                g11=genre['g11']
            )
            # 設定画面をファイルに書き出す
            Common.write_file(Common.SETTINGS_FILE, source)
            # 完了
            Common.notify('Channel initialized successfully')
            return True
        else:
            Common.log('channel failed', response_body, error=True)
            Common.notify('Channel initialization failed')
            return False
    else:
        Common.log('empty response', error=True)
        Common.notify('Channel initialization failed')
        return False
コード例 #4
0
 def update(self):
     size = 0
     for file in self.files:
         try:
             size = size + os.path.getsize(
                 os.path.join(Common.CACHE_PATH, file))
         except Exception:
             pass
     if size > 1024 * 1024:
         Common.SET(
             'cache',
             '%.1f MB / %d files' % (size / 1024 / 1024, len(self.files)))
     elif size > 1024:
         Common.SET('cache',
                    '%.1f kB / %d files' % (size / 1024, len(self.files)))
     else:
         Common.SET('cache',
                    '%d bytes / %d files' % (size, len(self.files)))
コード例 #5
0
 def update_settings(self):
     # テンプレートを読み込む
     template = Common.read_file(Common.TEMPLATE_FILE)
     # 設定ファイルに書き出すトークンを設定
     keys = list(self.data.keys())
     if len(keys) == 0:
         namelist = 'n/a'
     else:
         namelist = ('|'.join(keys))
         if len(keys) == 1:
             Common.SET('defaultname', keys[0])
     # 設定ファイルを書き出す
     Common.write_file(
         Common.SETTINGS_FILE,
         template.format(tokenname=namelist, tokenname2=namelist))
コード例 #6
0
def initializeNetwork():
    # リセット
    Common.SET('garapon_addr', '')
    Common.SET('garapon_http', '')
    Common.SET('garapon_https', '')
    # データ取得
    response_body = Request().getgtvaddress()
    if response_body:
        params = {}
        for i in response_body.split('\n'):
            try:
                (key, value) = i.split(';', 1)
                if key == '0':
                    params['message'] = value
                elif key == '1':
                    params['message'] = value
                else:
                    params[key] = value
            except Exception:
                pass
        if params['message'] == 'success':
            Common.SET('garapon_addr', params['ipaddr'])
            if params['ipaddr'] == params['gipaddr']:
                Common.SET('garapon_http', params['port'])
                Common.SET('garapon_https', params['port2'])
            else:
                Common.SET('garapon_http', '')
                Common.SET('garapon_https', '')
            Common.notify('Network initialized successfully')
            return True
        else:
            Common.log('getgtvaddress failed', response_body, error=True)
            Common.notify('Network initialization failed')
            return False
    else:
        Common.log('empty response', error=True)
        Common.notify('Network initialization failed')
        return False
コード例 #7
0
from resources.lib.history import History
from resources.lib.phonebook import PhoneBook

if __name__ == '__main__':

    # 引数
    args = parse_qs(sys.argv[2][1:], keep_blank_values=True)
    for key in args.keys():
        args[key] = args[key][0]
    action = args.get('action', 'showHistory')

    # アドオン設定
    settings = {}
    for key in ('key', 'name'):
        settings[key] = Common.GET(key)
    Common.SET('key', '')
    Common.SET('name', '')
    Common.SET('mode', 'create')

    # actionに応じた処理

    # 着信履歴
    if action == 'showHistory':
        History().show()
    elif action == 'clearHistory':
        History().clear()
        xbmc.executebuiltin('Container.Refresh()')

    # 電話帳
    elif action == 'showPhoneBook':
        PhoneBook().show()
コード例 #8
0
    args = parse_qs(sys.argv[2][1:], keep_blank_values=True)
    for key in args.keys():
        args[key] = args[key][0]

    mode = args.get('mode', '')
    url = args.get('url', '')

    # アドオン設定をコピー
    settings = {}
    if not os.path.isfile(Common.SETTINGS_FILE):
        # settings.xmlがない場合はテンプレートをコピーする
        shutil.copyfile(Common.TEMPLATE_FILE, Common.SETTINGS_FILE)
    else:
        for id in ['keyword', 'query']:
            settings[id] = Common.GET(id)
            Common.SET(id, '')
        for id in ['source']:
            settings[id] = Common.GET(id)
            Common.SET(id, '0')
        for id in ['channel']:
            settings[id] = Common.GET(id)
            Common.SET(id, Channel().getDefault())
        for id in [
                'g0', 'g00', 'g01', 'g02', 'g03', 'g04', 'g05', 'g06', 'g07',
                'g08', 'g09', 'g10', 'g11'
        ]:
            settings[id] = Common.GET(id)
            Common.SET(id, Genre().getDefault(id))

    # キャッシュサイズが未設定の場合は設定
    if Common.GET('cache') == '':
コード例 #9
0
    shutil.copy(srcfile, Common.PY_FILE)
    # _pjsua2.soをコピー
    srcfile = glob.glob(os.path.join(os.path.dirname(srcfile), '_pjsua2*.so'))[0]
    shutil.copy(srcfile, Common.SO_FILE)
    # インポート実行
    from resources.pjsua2 import pjsua2 as pj
except Exception as e:
    Common.notify('Importing pjsua2 failed', time=3000, error=True)
    Common.log(e)
    sys.exit()

# 電子メールクライアントの有無を確認
try:
    mailaddon = 'script.handler.email'
    xbmcaddon.Addon(mailaddon)
    Common.SET('mailaddon', mailaddon)
except Exception:
    Common.SET('mailaddon', '')

# LINE Notifyハンドラの有無を確認
try:
    lineaddon = 'script.handler.line.notify'
    xbmcaddon.Addon(lineaddon)
    Common.SET('lineaddon', lineaddon)
except Exception:
    Common.SET('lineaddon', '')


class Monitor(xbmc.Monitor):

    interval = 1
コード例 #10
0
 def main(self):
     # パラメータ抽出
     params = {
         'action': '',
         'filename': '',
         'subject': '',
         'message': '',
         'to': [],
         'cc': []
     }
     args = parse_qs(sys.argv[2][1:])
     for key in params.keys():
         params[key] = args.get(key, params[key])
     for key in ['action', 'filename', 'subject', 'message']:
         params[key] = params[key] and params[key][0]
     # メイン処理
     if params['action'] == '':
         start = Common.GET('start')
         if start == "true":
             # 新着をチェックして表示
             self.check()
         else:
             # 新着をチェックしないで表示
             self.list(newmails=[])
     elif params['action'] == 'check':
         # 新着をチェックして表示
         self.check()
     elif params['action'] == 'refresh':
         # キャッシュクリア
         files = os.listdir(self.cache_path)
         for filename in files:
             os.remove(os.path.join(self.cache_path, filename))
         # 再読み込み
         xbmc.executebuiltin('Container.Update(%s?action=check,replace)' %
                             (sys.argv[0]))
     elif params['action'] == 'open':
         # メールの内容を表示
         if params['filename']:
             self.open(params['filename'])
     elif params['action'] == 'sendmessage':
         # メールを送信
         subject = Common.GET('subject')
         message = Common.GET('message')
         to = Common.GET('to')
         cc = Common.GET('cc')
         # 送信データ
         values = {
             'action': 'send',
             'subject': subject,
             'message': message,
             'to': to,
             'cc': cc
         }
         postdata = urlencode(values)
         xbmc.executebuiltin('RunPlugin(%s?%s)' % (sys.argv[0], postdata))
     elif params['action'] == 'prepmessage':
         Common.SET('subject', params['subject'])
         Common.SET('message', params['message'])
         Common.SET('to', ','.join(params['to']))
         Common.SET('cc', ','.join(params['cc']))
         xbmc.executebuiltin('Addon.OpenSettings(%s)' % Common.ADDON_ID)
         xbmc.executebuiltin('SetFocus(101)')  # 2nd category
         xbmc.executebuiltin('SetFocus(203)')  # 4th control
     elif params['action'] == 'send':
         # メールを送信
         if Common.GET('bcc') == 'true':
             bcc = [self.service.smtp_from]
         else:
             bcc = []
         self.send(subject=params['subject'],
                   message=params['message'],
                   to=params['to'],
                   cc=params['cc'],
                   bcc=bcc)
コード例 #11
0
 def beginEdit(self, key, name, mode):
     Common.SET('key', key)
     Common.SET('name', name)
     Common.SET('mode', mode)  # modeはコンテクストに応じた設定画面表示のために使用
     xbmc.executebuiltin('Addon.OpenSettings(%s)' % Common.ADDON_ID)
     xbmc.executebuiltin('SetFocus(-99)')