import sys, os PY3 = False if sys.version_info[0] >= 3: PY3 = True unicode = str unichr = chr long = int from core.item import Item from core import filetools, jsontools from platformcode import config, logger, platformtools from platformcode.logger import WebErrorException temp_search_file = config.get_temp_file('temp-search') 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
# -*- coding: utf-8 -*- import sys import time from threading import Thread import xbmcgui from core import httptools from core import filetools from platformcode import config, platformtools from platformcode import logger from lib.librecaptcha.recaptcha import ReCaptcha, Solver, DynamicSolver, MultiCaptchaSolver, Solution, \ ImageGridChallenge lang = 'it' temp_dir = config.get_temp_file('reCAPTCHA/') tiles_pos = (75 + 390, 90 + 40) grid_width = 450 tiles_texture_focus = 'white.png' tiles_texture_checked = 'Controls/check_mark.png' cur_tmp = 0 TITLE = 10 PANEL = 11 IMAGE = 12 CONTROL = 1 OK = 21 CANCEL = 22 # RELOAD = 23
def new_search(item): logger.debug() temp_search_file = config.get_temp_file('temp-search') if filetools.isfile(temp_search_file): filetools.remove(temp_search_file) itemlist = [] if config.get_setting('last_search'): last_search = channeltools.get_channel_setting('Last_searched', 'search', '') else: last_search = '' if item.search_text: searched_text = item.search_text else: searched_text = platformtools.dialog_input(default=last_search, heading='') save_search(searched_text) if not searched_text: return channeltools.set_channel_setting('Last_searched', searched_text, 'search') searched_text = searched_text.replace("+", " ") if item.mode == 'person': item.searched_text = searched_text return actor_list(item) if item.mode != 'all': tmdb_info = tmdb.Tmdb(texto_buscado=searched_text, tipo=item.mode.replace('show', '')) results = tmdb_info.results for result in results: result = tmdb_info.get_infoLabels(result, origen=result) if item.mode == 'movie': title = result['title'] else: title = result['name'] item.mode = 'tvshow' thumbnail = result.get('thumbnail', '') fanart = result.get('fanart', '') new_item = Item(channel=item.channel, action='channel_search', title=title, text=searched_text, thumbnail=thumbnail, fanart=fanart, mode=item.mode, contentType=item.mode, infoLabels=result) if item.mode == 'movie': new_item.contentTitle = result['title'] else: new_item.contentSerieName = result['name'] itemlist.append(new_item) if item.mode == 'all' or not itemlist: return channel_search(Item(channel=item.channel, title=searched_text, text=searched_text, mode='all', infoLabels={})) return itemlist
def channel_search(item): logger.debug(item) start = time.time() searching = list() searching_titles = list() results = list() valid = list() ch_list = dict() mode = item.mode if item.infoLabels['tvshowtitle']: item.text = item.infoLabels['tvshowtitle'].split(' - ')[0] item.title = item.text elif item.infoLabels['title']: item.text = item.infoLabels['title'].split(' - ')[0] item.title = item.text temp_search_file = config.get_temp_file('temp-search') if filetools.isfile(temp_search_file): itemlist = [] f = filetools.read(temp_search_file) if f.startswith(item.text): for it in f.split(','): if it and it != item.text: itemlist.append(Item().fromurl(it)) return itemlist else: filetools.remove(temp_search_file) searched_id = item.infoLabels['tmdb_id'] channel_list, channel_titles = get_channels(item) searching += channel_list searching_titles += channel_titles cnt = 0 progress = platformtools.dialog_progress(config.get_localized_string(30993) % item.title, config.get_localized_string(70744) % len(channel_list) + '\n' + ', '.join(searching_titles)) config.set_setting('tmdb_active', False) search_action_list = [] module_dict = {} for ch in channel_list: try: module = __import__('channels.%s' % ch, fromlist=["channels.%s" % ch]) mainlist = getattr(module, 'mainlist')(Item(channel=ch, global_search=True)) module_dict[ch] = module search_action_list.extend([elem for elem in mainlist if elem.action == "search" and (mode == 'all' or elem.contentType in [mode, 'undefined'])]) if progress.iscanceled(): return [] except: import traceback logger.error('error importing/getting search items of ' + ch) logger.error(traceback.format_exc()) total_search_actions = len(search_action_list) with futures.ThreadPoolExecutor(max_workers=set_workers()) as executor: c_results = [] for search_action in search_action_list: c_results.append(executor.submit(get_channel_results, item, module_dict, search_action)) if progress.iscanceled(): break for res in futures.as_completed(c_results): search_action = res.result()[0] channel = search_action.channel if res.result()[1]: if channel not in ch_list: ch_list[channel] = [] ch_list[channel].extend(res.result()[1]) if res.result()[2]: valid.extend(res.result()[2]) if progress.iscanceled(): break search_action_list.remove(search_action) # if no action of this channel remains for it in search_action_list: if it.channel == channel: break else: cnt += 1 searching_titles.remove(searching_titles[searching.index(channel)]) searching.remove(channel) progress.update(old_div(((total_search_actions - len(search_action_list)) * 100), total_search_actions), config.get_localized_string(70744) % str(len(channel_list) - cnt) + '\n' + ', '.join(searching_titles)) progress.close() cnt = 0 progress = platformtools.dialog_progress(config.get_localized_string(30993) % item.title, config.get_localized_string(60295) + '\n' + config.get_localized_string(60293)) config.set_setting('tmdb_active', True) # res_count = 0 for key, value in ch_list.items(): ch_name = channel_titles[channel_list.index(key)] grouped = list() cnt += 1 progress.update(old_div((cnt * 100), len(ch_list)), config.get_localized_string(60295)) for it in value: if it.channel == item.channel: it.channel = key if it in valid: continue if mode == 'all' or (it.contentType and mode == it.contentType): if config.get_setting('result_mode') != 0: if config.get_localized_string(30992) not in it.title: it.title += typo(ch_name,'_ [] color kod bold') results.append(it) else: grouped.append(it) elif (mode == 'movie' and it.contentTitle) or (mode == 'tvshow' and (it.contentSerieName or it.show)): grouped.append(it) else: continue if not grouped: continue # to_temp[key] = grouped if config.get_setting('result_mode') == 0: if not config.get_setting('unify'): title = typo(ch_name,'bold') + typo(str(len(grouped)), '_ [] color kod bold') else: title = typo('%s %s' % (len(grouped), config.get_localized_string(70695)), 'bold') # res_count += len(grouped) plot='' for it in grouped: plot += it.title +'\n' ch_thumb = channeltools.get_channel_parameters(key)['thumbnail'] results.append(Item(channel='search', title=title, action='get_from_temp', thumbnail=ch_thumb, itemlist=[ris.tourl() for ris in grouped], plot=plot, page=1)) progress.close() # "All Together" and movie mode -> search servers if config.get_setting('result_mode') == 1 and mode == 'movie': progress = platformtools.dialog_progress(config.get_localized_string(30993) % item.title, config.get_localized_string(60683)) valid_servers = [] with futures.ThreadPoolExecutor(max_workers=set_workers()) as executor: c_results = [executor.submit(get_servers, v, module_dict) for v in valid] completed = 0 for res in futures.as_completed(c_results): if progress.iscanceled(): break if res.result(): completed += 1 valid_servers.extend(res.result()) progress.update(old_div(completed * 100, len(valid))) valid = valid_servers progress.close() # send_to_temp(to_temp) results = sorted(results, key=lambda it: it.title) results_statistic = config.get_localized_string(59972) % (item.title, time.time() - start) if mode == 'all': results.insert(0, Item(title=typo(results_statistic, 'color kod bold'), thumbnail=get_thumb('search.png'))) else: if not valid: valid.append(Item(title=config.get_localized_string(60347), thumbnail=get_thumb('nofolder.png'))) valid.insert(0, Item(title=typo(results_statistic, 'color kod bold'), thumbnail=get_thumb('search.png'))) results.insert(0, Item(title=typo(config.get_localized_string(30025), 'color kod bold'), thumbnail=get_thumb('search.png'))) # logger.debug(results_statistic) itlist = valid + results writelist = item.text for it in itlist: writelist += ',' + it.tourl() filetools.write(temp_search_file, writelist) return itlist
def play(item): from time import time from base64 import b64encode from hashlib import md5 data = support.httptools.downloadpage(item.url + item.episodeid, headers=headers).data.replace( '"', '"').replace('\\', '') scws_id = support.match(data, patron=r'scws_id"\s*:\s*(\d+)').match # support.dbg() if not scws_id: if '<strong>Prossimamente' in data: platformtools.dialog_ok( 'StreamingCommunity', 'Il sito notifica che il contenuto sarĂ disponibile prossimamente' ) platformtools.play_canceled = True return [] # Calculate Token client_ip = httptools.downloadpage('https://api.ipify.org/').data expires = int(time() + 172800) token = b64encode( md5('{}{} Yc8U6r8KjAKAepEA'.format( expires, client_ip).encode('utf-8')).digest()).decode('utf-8').replace( '=', '').replace('+', '-').replace('/', '_') url = 'https://scws.xyz/master/{}?token={}&expires={}&n=1'.format( scws_id, token, expires) subs = [] urls = [] info = support.scrapertools.find_multiple_matches( httptools.downloadpage(url).data, 'NAME="([^"]+)".*?URI="([^"]+)|RESOLUTION=\d+x(\d+).*?(http[^"\s]+)') if info: for lang, sub, res, url in info: if sub: s = config.get_temp_file(lang + '.srt') subs.append(s) filetools.write( s, support.vttToSrt( httptools.downloadpage( support.match( sub, patron=r'(http[^\s\n]+)').match).data)) elif url: urls.append(['hls [{}]'.format(res), url]) return [ item.clone(title=channeltools.get_channel_parameters( item.channel)['title'], server='directo', video_urls=urls, subtitle=subs, manifest='hls') ] else: return [ item.clone(title=channeltools.get_channel_parameters( item.channel)['title'], server='directo', url=url, manifest='hls') ]