def change_channel(type, id, change, **kwargs): change = int(change) if not id or len(unicode(id)) == 0 or not type or len(unicode(type)) == 0: return False prefs = load_prefs(profile_id=1) id = unicode(id) type = unicode(type) mod_pref = { 'live': 1, 'live_auto': 1, 'replay': 1, 'replay_auto': 1, 'epg': 1, 'epg_auto': 1, } if change == 0: mod_pref[unicode(type) + '_auto'] = 0 if not check_key(prefs, id): mod_pref[type] = 0 else: if prefs[id][type] == 1: mod_pref[type] = 0 else: mod_pref[type] = 1 else: mod_pref[unicode(type) + '_auto'] = 1 results = load_tests(profile_id=1) if not results or not check_key(results, id) or not results[id][type] == 1: mod_pref[type] = 1 else: mod_pref[type] = 0 query = "REPLACE INTO `prefs_{profile_id}` VALUES ('{id}', '{live}', '{live_auto}', '{replay}', '{replay_auto}', '{epg}', '{epg_auto}')".format( profile_id=1, id=id, live=mod_pref['live'], live_auto=mod_pref['live_auto'], replay=mod_pref['replay'], replay_auto=mod_pref['replay_auto'], epg=mod_pref['epg'], epg_auto=mod_pref['epg_auto']) query_settings(query=query, return_result=False, return_insert=False, commit=True) if type == 'epg': create_playlist() xbmc.executeJSONRPC( '{{"jsonrpc":"2.0","id":1,"method":"GUI.ActivateWindow","params":{{"window":"videos","parameters":["plugin://' + unicode(ADDON_ID) + '/?_=channel_picker&type=' + type + '"]}}}}')
def channel_picker(type, **kwargs): if type=='live': title = _.LIVE_TV rows = get_live_channels(addon=False, all=True) elif type=='replay': title = _.CHANNELS rows = get_replay_channels(all=True) else: title = _.SIMPLEIPTV rows = get_live_channels(addon=False, all=True) folder = plugin.Folder(title=title) prefs = load_prefs(profile_id=1) results = load_tests(profile_id=1) type = unicode(type) for row in rows: id = unicode(row['channel']) if not prefs or not check_key(prefs, id) or prefs[id][type] == 1: color = 'green' else: color = 'red' label = _(row['label'], _bold=True, _color=color) if results and check_key(results, id): if results[id][type] == 1: label += _(' (' + _.TEST_SUCCESS + ')', _bold=False, _color='green') else: label += _(' (' + _.TEST_FAILED + ')', _bold=False, _color='red') else: label += _(' (' + _.NOT_TESTED + ')', _bold=False, _color='orange') if not prefs or not check_key(prefs, id) or prefs[id][type + '_auto'] == 1: choice = _(' ,' + _.AUTO_CHOICE + '', _bold=False, _color='green') else: choice = _(' ,' + _.MANUAL_CHOICE + '', _bold=False, _color='orange') label += choice folder.add_item( label = label, art = {'thumb': row['image']}, path = plugin.url_for(func_or_url=change_channel, type=type, id=id, change=0), context = [ (_.AUTO_CHOICE_SET, 'Container.Update({context_url})'.format(context_url=plugin.url_for(func_or_url=change_channel, type=type, id=id, change=1)), ), #(_.TEST_CHANNEL, 'RunPlugin({context_url})'.format(context_url=plugin.url_for(func_or_url=test_channel, channel=id)), ), ], playable = False, ) return folder
def get_replay_channels(all=False): channels = [] query = "SELECT * FROM `channels`" data = query_epg(query=query, return_result=True, return_insert=False, commit=False) prefs = load_prefs(profile_id=1) if data: for row in data: if '18+' in row['name']: continue id = unicode(row['id']) if all or not prefs or not check_key( prefs, id) or prefs[id]['replay'] == 1: image_path = ADDON_PROFILE + "images" + os.sep + unicode( row['id']) + ".png" if os.path.isfile(image_path): image = image_path else: image = row['icon'] channels.append({ 'label': row['name'], 'channel': row['id'], 'chno': row['channelno'], 'description': row['description'], 'image': image, 'path': plugin.url_for(func_or_url=replaytv_by_day, image=row['icon'], description=row['description'], label=row['name'], station=row['id']), 'playable': False, 'context': [], }) channels[:] = sorted(channels, key=_sort_live) return channels
def process_replaytv_list_content(label, idtitle, start=0): profile_settings = load_profile(profile_id=1) start = int(start) now = datetime.datetime.now(pytz.timezone("Europe/Amsterdam")) sevendays = datetime.datetime.now(pytz.timezone("Europe/Amsterdam")) - datetime.timedelta(days=7) nowstamp = int((now - datetime.datetime(1970, 1, 1, tzinfo=pytz.utc)).total_seconds()) sevendaysstamp = int((sevendays - datetime.datetime(1970, 1, 1, tzinfo=pytz.utc)).total_seconds()) query = "SELECT * FROM `channels`" data = query_epg(query=query, return_result=True, return_insert=False, commit=False) channels_ar2 = {} if data: for row in data: channels_ar2[unicode(row['id'])] = row['name'] prefs = load_prefs(profile_id=1) channels_ar = [] if prefs: for row in prefs: currow = prefs[row] if '18+' in channels_ar2[unicode(currow['id'])]: continue if currow['replay'] == 1: channels_ar.append(row) channels = "', '".join(map(str, channels_ar)) query = "SELECT * FROM `epg` WHERE idtitle='{idtitle}' AND start < {nowstamp} AND end > {sevendaysstamp} AND channel IN ('{channels}') LIMIT 51 OFFSET {start}".format(idtitle=idtitle, nowstamp=nowstamp, sevendaysstamp=sevendaysstamp, channels=channels, start=start) data = query_epg(query=query, return_result=True, return_insert=False, commit=False) items = [] item_count = 0 if not data: return {'items': items, 'count': item_count, 'total': 0} for row in data: if item_count == 51: break item_count += 1 startT = datetime.datetime.fromtimestamp(row['start']) startT = convert_datetime_timezone(startT, "Europe/Amsterdam", "Europe/Amsterdam") endT = datetime.datetime.fromtimestamp(row['end']) endT = convert_datetime_timezone(endT, "Europe/Amsterdam", "Europe/Amsterdam") if xbmc.getLanguage(xbmc.ISO_639_1) == 'nl': itemlabel = '{weekday} {day} {month} {yearhourminute} '.format(weekday=date_to_nl_dag(startT), day=startT.strftime("%d"), month=date_to_nl_maand(startT), yearhourminute=startT.strftime("%Y %H:%M")) else: itemlabel = startT.strftime("%A %d %B %Y %H:%M ").capitalize() itemlabel += row['title'] + " (" + channels_ar2[unicode(row['channel'])] + ")" description = row['description'] duration = int((endT - startT).total_seconds()) program_image = row['icon'] program_image_large = row['icon'] items.append(plugin.Item( label = itemlabel, info = { 'plot': description, 'duration': duration, 'mediatype': 'video', }, art = { 'thumb': program_image, 'fanart': program_image_large }, path = plugin.url_for(func_or_url=play_video, type='program', channel=row['channel'], id=row['program_id'], duration=duration), playable = True, )) returnar = {'items': items, 'count': item_count, 'total': len(data)} return returnar
def process_replaytv_search(search): profile_settings = load_profile(profile_id=1) now = datetime.datetime.now(pytz.timezone("Europe/Amsterdam")) sevendays = datetime.datetime.now(pytz.timezone("Europe/Amsterdam")) - datetime.timedelta(days=7) nowstamp = int((now - datetime.datetime(1970, 1, 1, tzinfo=pytz.utc)).total_seconds()) sevendaysstamp = int((sevendays - datetime.datetime(1970, 1, 1, tzinfo=pytz.utc)).total_seconds()) query = "SELECT * FROM `channels`" data = query_epg(query=query, return_result=True, return_insert=False, commit=False) channels_ar2 = {} if data: for row in data: channels_ar2[unicode(row['id'])] = row['name'] prefs = load_prefs(profile_id=1) channels_ar = [] if prefs: for row in prefs: currow = prefs[row] if '18+' in channels_ar2[unicode(currow['id'])]: continue if currow['replay'] == 1: channels_ar.append(row) channels = "', '".join(map(str, channels_ar)) query = "SELECT idtitle, title, icon FROM `epg` WHERE start < {nowstamp} AND end > {sevendaysstamp} AND channel IN ('{channels}') GROUP BY idtitle".format(nowstamp=nowstamp, sevendaysstamp=sevendaysstamp, channels=channels) data = query_epg(query=query, return_result=True, return_insert=False, commit=False) items = [] if not data: return {'items': items} for row in data: fuzz_set = fuzz.token_set_ratio(row['title'], search) fuzz_partial = fuzz.partial_ratio(row['title'], search) fuzz_sort = fuzz.token_sort_ratio(row['title'], search) if (fuzz_set + fuzz_partial + fuzz_sort) > 160: label = row['title'] + ' (ReplayTV)' idtitle = row['idtitle'] items.append(plugin.Item( label = label, art = { 'thumb': row['icon'], 'fanart': row['icon'] }, properties = {"fuzz_set": fuzz_set, "fuzz_sort": fuzz_sort, "fuzz_partial": fuzz_partial, "fuzz_total": fuzz_set + fuzz_partial + fuzz_sort}, path = plugin.url_for(func_or_url=replaytv_item, label=label, idtitle=idtitle, start=0), )) returnar = {'items': items} return returnar
def process_replaytv_list(character, start=0): profile_settings = load_profile(profile_id=1) now = datetime.datetime.now(pytz.timezone("Europe/Amsterdam")) sevendays = datetime.datetime.now(pytz.timezone("Europe/Amsterdam")) - datetime.timedelta(days=7) nowstamp = int((now - datetime.datetime(1970, 1, 1, tzinfo=pytz.utc)).total_seconds()) sevendaysstamp = int((sevendays - datetime.datetime(1970, 1, 1, tzinfo=pytz.utc)).total_seconds()) query = "SELECT * FROM `channels`" data = query_epg(query=query, return_result=True, return_insert=False, commit=False) channels_ar2 = {} if data: for row in data: channels_ar2[unicode(row['id'])] = row['name'] prefs = load_prefs(profile_id=1) channels_ar = [] if prefs: for row in prefs: currow = prefs[row] if '18+' in channels_ar2[unicode(currow['id'])]: continue if currow['replay'] == 1: channels_ar.append(row) channels = "', '".join(map(str, channels_ar)) query = "SELECT idtitle, title, icon FROM `epg` WHERE first='{first}' AND start < {nowstamp} AND end > {sevendaysstamp} AND channel IN ('{channels}') GROUP BY idtitle LIMIT 51 OFFSET {start}".format(first=character, nowstamp=nowstamp, sevendaysstamp=sevendaysstamp, channels=channels, start=start) data = query_epg(query=query, return_result=True, return_insert=False, commit=False) start = int(start) items = [] item_count = 0 if not data: return {'items': items, 'count': item_count, 'total': 0} for row in data: if item_count == 51: break item_count += 1 label = row['title'] idtitle = row['idtitle'] items.append(plugin.Item( label = label, art = { 'thumb': row['icon'], 'fanart': row['icon'] }, path = plugin.url_for(func_or_url=replaytv_item, label=label, idtitle=idtitle, start=0), )) returnar = {'items': items, 'count': item_count, 'total': len(data)} return returnar
def get_live_channels(addon=False, all=False): global backend channels = [] pvrchannels = [] query = "SELECT * FROM `channels`" data = query_epg(query=query, return_result=True, return_insert=False, commit=False) prefs = load_prefs(profile_id=1) if data: if addon: query_addons = json.loads(xbmc.executeJSONRPC('{"jsonrpc": "2.0", "id": 1, "method": "Addons.GetAddons", "params": {"type": "xbmc.pvrclient"}}')) if check_key(query_addons, 'result') and check_key(query_addons['result'], 'addons'): addons = query_addons['result']['addons'] backend = addons[0]['addonid'] query_channel = json.loads(xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "PVR.GetChannels", "params": {"channelgroupid": "alltv", "properties" :["uniqueid"]},"id": 1}')) if check_key(query_channel, 'result') and check_key(query_channel['result'], 'channels'): pvrchannels = query_channel['result']['channels'] for row in data: path = plugin.url_for(func_or_url=play_video, type='channel', channel=row['id'], id=None, _is_live=True) playable = True for channel in pvrchannels: if channel['label'] == row['name']: channel_uid = channel['uniqueid'] path = plugin.url_for(func_or_url=switchChannel, channel_uid=channel_uid) playable = False break if '18+' in row['name']: continue id = unicode(row['id']) if all or not prefs or not check_key(prefs, id) or prefs[id]['live'] == 1: image_path = ADDON_PROFILE + "images" + os.sep + unicode(row['id']) + ".png" if os.path.isfile(image_path): image = image_path else: image = row['icon'] channels.append({ 'label': row['name'], 'channel': row['id'], 'chno': row['channelno'], 'description': row['description'], 'image': image, 'path': path, 'playable': playable, 'context': [ (_.START_BEGINNING, 'RunPlugin({context_url})'.format(context_url=plugin.url_for(func_or_url=play_video, type='channel', channel=row['id'], id=None, from_beginning=1)), ), ], }) channels[:] = sorted(channels, key=_sort_live) return channels