def log(msg, level=LOGNOTICE): debug_enabled = control.addon('plugin.video.koditvr').getSetting( 'addon_debug') debug_log = control.addon('plugin.video.koditvr').getSetting( 'debug.location') print(DEBUGPREFIX + ' Debug Enabled?: ' + str(debug_enabled)) print(DEBUGPREFIX + ' Debug Log?: ' + str(debug_log)) if not control.addon('plugin.video.koditvr').getSetting( 'addon_debug') == 'true': return try: if isinstance(msg, six.text_type): msg = '%s (ENCODED)' % (control.six_encode(msg)) if not control.addon('plugin.video.koditvr').getSetting( 'debug.location') == '0': log_file = os.path.join(LOGPATH, 'koditvr.log') if not os.path.exists(log_file): f = open(log_file, 'w') f.close() with open(log_file, 'a') as f: line = '[%s %s] %s: %s' % (datetime.now().date(), str(datetime.now().time())[:8], DEBUGPREFIX, msg) f.write(line.rstrip('\r\n') + '\n') else: print('%s: %s' % (DEBUGPREFIX, msg)) except Exception as e: try: xbmc.log('Logging Failure: %s' % (e), level) except Exception: pass
def syncTraktStatus(): try: cachesyncMovies() cachesyncTVShows() control.infoDialog(control.six_encode(control.lang(32092))) except: control.infoDialog('Trakt sync failed') pass
def normalize(title): try: try: return control.six_encode(control.six_decode(title, char='ascii')) except: pass return str(''.join(c for c in unicodedata.normalize( 'NFKD', unicode(control.six_decode(title))) if unicodedata.category(c) != 'Mn')) except: return title
def getTVShowTranslation(self, thetvdb, lang): try: url = 'https://thetvdb.com/api/%s/series/%s/%s.xml' % (base64.b64decode('Sk1DTzhMUUhJWFg3NkNHTg=='), thetvdb, lang) r = requests.get(url, timeout=15, verify=True).content title = client.parseDOM(r, 'SeriesName')[0] title = client.replaceHTMLCodes(title) title = control.six_encode(title) return title except: pass
def authTrakt(): try: if getTraktCredentialsInfo() == True: if control.yesnoDialog(control.lang(32511) + '[CR]' + control.lang(32512), heading='Trakt'): control.addon('plugin.video.koditvr').setSetting(id='trakt.user', value='') control.addon('plugin.video.koditvr').setSetting(id='trakt.authed', value='') control.addon('plugin.video.koditvr').setSetting(id='trakt.token', value='') control.addon('plugin.video.koditvr').setSetting(id='trakt.refresh', value='') raise Exception() result = getTraktAsJson('/oauth/device/code', {'client_id': V2_API_KEY}) verification_url = control.lang(32513) % result['verification_url'] user_code = control.six_encode(control.lang(32514) % result['user_code']) expires_in = int(result['expires_in']) device_code = result['device_code'] interval = result['interval'] progressDialog = control.progressDialog progressDialog.create('Trakt') for i in list(range(0, expires_in)): try: percent = int(100 * float(i) / int(expires_in)) progressDialog.update(max(1, percent), verification_url + '[CR]' + user_code) if progressDialog.iscanceled(): break time.sleep(1) if not float(i) % interval == 0: raise Exception() r = getTraktAsJson('/oauth/device/token', {'client_id': V2_API_KEY, 'client_secret': CLIENT_SECRET, 'code': device_code}) if 'access_token' in r: break except: pass try: progressDialog.close() except: pass token, refresh = r['access_token'], r['refresh_token'] headers = {'Content-Type': 'application/json', 'trakt-api-key': V2_API_KEY, 'trakt-api-version': 2, 'Authorization': 'Bearer %s' % token} result = client.request(urllib_parse.urljoin(BASE_URL, '/users/me'), headers=headers) result = utils.json_loads_as_str(result) user = result['username'] authed = '' if user == '' else str('yes') print('info - ' + token) control.addon('plugin.video.koditvr').setSetting(id='trakt.user', value=user) control.addon('plugin.video.koditvr').setSetting(id='trakt.authed', value=authed) control.addon('plugin.video.koditvr').setSetting(id='trakt.token', value=token) control.addon('plugin.video.koditvr').setSetting(id='trakt.refresh', value=refresh) raise Exception() except: control.openSettings('2.1')
def get(title): if title is None: return try: title = control.six_encode(title) except: pass title = re.sub('&#(\d+);', '', title) title = re.sub('(&#[0-9]+)([^;^0-9]+)', '\\1;\\2', title) title = title.replace('"', '\"').replace('&', '&').replace('–', '-').replace('!', '') title = re.sub( '\n|([[].+?[]])|([(].+?[)])|\s(vs|v[.])\s|(:|;|-|–|"|,|\'|\_|\.|\?)|\s', '', title).lower() return title
def resolve(regex): try: vanilla = re.compile('(<regex>.+)', re.MULTILINE | re.DOTALL).findall(regex)[0] cddata = re.compile('<\!\[CDATA\[(.+?)\]\]>', re.MULTILINE | re.DOTALL).findall(regex) for i in cddata: regex = regex.replace('<![CDATA[' + i + ']]>', urllib_parse.quote_plus(i)) regexs = re.compile('(<regex>.+)', re.MULTILINE | re.DOTALL).findall(regex)[0] regexs = re.compile('<regex>(.+?)</regex>', re.MULTILINE | re.DOTALL).findall(regexs) regexs = [ re.compile('<(.+?)>(.*?)</.+?>', re.MULTILINE | re.DOTALL).findall(i) for i in regexs ] regexs = [ dict([(client.replaceHTMLCodes(x[0]), client.replaceHTMLCodes(urllib_parse.unquote_plus(x[1]))) for x in i]) for i in regexs ] regexs = [(i['name'], i) for i in regexs] regexs = dict(regexs) url = regex.split('<regex>', 1)[0].strip() url = client.replaceHTMLCodes(url) url = control.six_encode(url) r = getRegexParsed(regexs, url) try: ln = '' ret = r[1] listrepeat = r[2]['listrepeat'] regexname = r[2]['name'] for obj in ret: try: item = listrepeat for i in list(range(len(obj) + 1)): item = item.replace( '[%s.param%s]' % (regexname, str(i)), obj[i - 1]) item2 = vanilla for i in list(range(len(obj) + 1)): item2 = item2.replace( '[%s.param%s]' % (regexname, str(i)), obj[i - 1]) item2 = re.compile('(<regex>.+?</regex>)', re.MULTILINE | re.DOTALL).findall(item2) item2 = [ x for x in item2 if not '<name>%s</name>' % regexname in x ] item2 = ''.join(item2) ln += '\n<item>%s\n%s</item>\n' % (item, item2) except: pass return ln except: pass if r[1] == True: return r[0] except: return
def manager(name, imdb, tvdb, content): try: post = {"movies": [{"ids": {"imdb": imdb}}]} if content == 'movie' else {"shows": [{"ids": {"tvdb": tvdb}}]} items = [(control.six_encode(control.lang(32516)), '/sync/collection')] items += [(control.six_encode(control.lang(32517)), '/sync/collection/remove')] items += [(control.six_encode(control.lang(32518)), '/sync/watchlist')] items += [(control.six_encode(control.lang(32519)), '/sync/watchlist/remove')] items += [(control.six_encode(control.lang(32520)), '/users/me/lists/%s/items')] result = getTraktAsJson('/users/me/lists') lists = [(i['name'], i['ids']['slug']) for i in result] lists = [lists[i//2] for i in list(range(len(lists)*2))] for i in list(range(0, len(lists), 2)): lists[i] = ((control.six_encode(control.lang(32521) % lists[i][0])), '/users/me/lists/%s/items' % lists[i][1]) for i in list(range(1, len(lists), 2)): lists[i] = ((control.six_encode(control.lang(32522) % lists[i][0])), '/users/me/lists/%s/items/remove' % lists[i][1]) items += lists select = control.selectDialog([i[0] for i in items], control.six_encode(control.lang(32515))) if select == -1: return elif select == 4: t = control.six_encode(control.lang(32520)) k = control.keyboard('', t) ; k.doModal() new = k.getText() if k.isConfirmed() else None if (new == None or new == ''): return result = __getTrakt('/users/me/lists', post={"name": new, "privacy": "private"})[0] try: slug = utils.json_loads_as_str(result)['ids']['slug'] except: return control.infoDialog(control.six_encode(control.lang(32515)), heading=str(name), sound=True, icon='ERROR') result = __getTrakt(items[select][1] % slug, post=post)[0] else: result = __getTrakt(items[select][1], post=post)[0] icon = control.infoLabel('ListItem.Icon') if not result == None else 'ERROR' control.infoDialog(control.six_encode(control.lang(32515)), heading=str(name), sound=True, icon=icon) except: return