def get_channel_json(channel_name): # logger.info("channel_name=" + channel_name) import filetools channel_json = None try: channel_path = filetools.join(config.get_runtime_path(), "channels", channel_name + ".json") if not os.path.isfile(channel_path): channel_path = filetools.join(config.get_runtime_path(), 'channels', "p**n", channel_name + ".json") if not os.path.isfile(channel_path): channel_path = filetools.join(config.get_runtime_path(), "specials", channel_name + ".json") if not os.path.isfile(channel_path): channel_path = filetools.join(config.get_runtime_path(), "servers", channel_name + ".json") if not os.path.isfile(channel_path): channel_path = filetools.join( config.get_runtime_path(), "servers", "debriders", channel_name + ".json") if filetools.isfile(channel_path): # logger.info("channel_data=" + channel_path) channel_json = jsontools.load(filetools.read(channel_path)) # logger.info("channel_json= %s" % channel_json) except Exception, ex: template = "An exception of type %s occured. Arguments:\n%r" message = template % (type(ex).__name__, ex.args) logger.error(" %s" % message)
def set_channel_setting(name, value, channel): """ Fija el valor de configuracion del parametro indicado. Establece 'value' como el valor del parametro 'name' en la configuracion propia del canal 'channel'. Devuelve el valor cambiado o None si la asignacion no se ha podido completar. Si se especifica el nombre del canal busca en la ruta \addon_data\plugin.video.alfa\settings_channels el archivo channel_data.json y establece el parametro 'name' al valor indicado por 'value'. Si el parametro 'name' no existe lo añade, con su valor, al archivo correspondiente. @param name: nombre del parametro @type name: str @param value: valor del parametro @type value: str @param channel: nombre del canal @type channel: str @return: 'value' en caso de que se haya podido fijar el valor y None en caso contrario @rtype: str, None """ # Creamos la carpeta si no existe if not os.path.exists( os.path.join(config.get_data_path(), "settings_channels")): os.mkdir(os.path.join(config.get_data_path(), "settings_channels")) file_settings = os.path.join(config.get_data_path(), "settings_channels", channel + "_data.json") dict_settings = {} dict_file = None if os.path.exists(file_settings): # Obtenemos configuracion guardada de ../settings/channel_data.json try: dict_file = jsontools.load(open(file_settings, "r").read()) dict_settings = dict_file.get('settings', {}) except EnvironmentError: logger.error("ERROR al leer el archivo: %s" % file_settings) dict_settings[name] = value # comprobamos si existe dict_file y es un diccionario, sino lo creamos if dict_file is None or not dict_file: dict_file = {} dict_file['settings'] = dict_settings # Creamos el archivo ../settings/channel_data.json try: json_data = jsontools.dump(dict_file) open(file_settings, "w").write(json_data) except EnvironmentError: logger.error("ERROR al salvar el archivo: %s" % file_settings) return None return value
def get_channel_setting(name, channel, default=None): """ Retorna el valor de configuracion del parametro solicitado. Devuelve el valor del parametro 'name' en la configuracion propia del canal 'channel'. Busca en la ruta \addon_data\plugin.video.alfa\settings_channels el archivo channel_data.json y lee el valor del parametro 'name'. Si el archivo channel_data.json no existe busca en la carpeta channels el archivo channel.json y crea un archivo channel_data.json antes de retornar el valor solicitado. Si el parametro 'name' tampoco existe en el el archivo channel.json se devuelve el parametro default. @param name: nombre del parametro @type name: str @param channel: nombre del canal @type channel: str @param default: valor devuelto en caso de que no exista el parametro name @type default: cualquiera @return: El valor del parametro 'name' @rtype: El tipo del valor del parametro """ file_settings = os.path.join(config.get_data_path(), "settings_channels", channel + "_data.json") dict_settings = {} dict_file = {} if os.path.exists(file_settings): # Obtenemos configuracion guardada de ../settings/channel_data.json try: dict_file = jsontools.load(open(file_settings, "rb").read()) if isinstance(dict_file, dict) and 'settings' in dict_file: dict_settings = dict_file['settings'] except EnvironmentError: logger.error("ERROR al leer el archivo: %s" % file_settings) if not dict_settings or name not in dict_settings: # Obtenemos controles del archivo ../channels/channel.json try: list_controls, default_settings = get_channel_controls_settings( channel) except: default_settings = {} if name in default_settings: # Si el parametro existe en el channel.json creamos el channel_data.json default_settings.update(dict_settings) dict_settings = default_settings dict_file['settings'] = dict_settings # Creamos el archivo ../settings/channel_data.json json_data = jsontools.dump(dict_file) try: open(file_settings, "wb").write(json_data) except EnvironmentError: logger.error("ERROR al salvar el archivo: %s" % file_settings) # Devolvemos el valor del parametro local 'name' si existe, si no se devuelve default return dict_settings.get(name, default)
def get_channel_json(channel_name): # logger.info("channel_name=" + channel_name) import filetools try: channel_path = filetools.join(config.get_runtime_path(), "channels", channel_name + ".json") # logger.info("channel_data=" + channel_path) channel_json = jsontools.load(filetools.read(channel_path)) # logger.info("channel_json= %s" % channel_json) except Exception, ex: template = "An exception of type %s occured. Arguments:\n%r" message = template % (type(ex).__name__, ex.args) logger.error(" %s" % message) channel_json = None
def remote_call(url, parameters={}, require_session=True): logger.info("url=" + url + ", parameters=" + repr(parameters)) if not url.startswith("http"): url = MAIN_URL + "/" + url if not "api_key" in parameters: parameters["api_key"] = API_KEY # Add session token if not here # if not "s" in parameters and require_session: # parameters["s"] = get_session_token() headers = DEFAULT_HEADERS post = urllib.urlencode(parameters) response_body = scrapertools.downloadpage(url, post, headers) return jsontools.load(response_body)
def get_default_settings(channel_name): import filetools, inspect # Check if it is a real channel try: channel = __import__('channels.%s' % channel_name, fromlist=["channels.%s" % channel_name]) except: return get_channel_json(channel_name).get('settings', list()) list_language = get_lang(channel_name) # Check if the automatic renumbering function exists renumber = False if 'episodios' in dir(channel): from core import scrapertoolsV2 if scrapertoolsV2.find_single_match(inspect.getsource(channel), r'(anime\s*=\s*True)') \ or scrapertoolsV2.find_single_match(inspect.getsource(channel), r'(autorenumber\()'): renumber = True # Collects configurations channel_language = categories = get_channel_json(channel_name).get( 'language', list()) channel_controls = get_channel_json(channel_name).get('settings', list()) default_path = filetools.join(config.get_runtime_path(), 'default_channel_settings' + '.json') default_controls = jsontools.load(filetools.read(default_path)).get( 'settings', list()) default_controls_renumber = jsontools.load( filetools.read(default_path)).get('renumber', list()) categories = get_channel_json(channel_name).get('categories', list()) # Apply default configurations if they do not exist for control in default_controls: if control['id'] not in str(channel_controls): if 'include_in_newest' in control['id']: label = control['id'].split('_') label = label[-1] if label == 'peliculas': if 'movie' in categories: control['label'] = config.get_localized_string( 70727) + ' - ' + config.get_localized_string(30122) channel_controls.append(control) else: pass elif label == 'series': if 'tvshow' in categories: control['label'] = config.get_localized_string( 70727) + ' - ' + config.get_localized_string(30123) channel_controls.append(control) else: pass elif label == 'anime': if 'anime' in categories: control['label'] = config.get_localized_string( 70727) + ' - ' + config.get_localized_string(30124) channel_controls.append(control) else: pass else: control['label'] = config.get_localized_string( 70727) + ' - ' + label.capitalize() channel_controls.append(control) elif control['id'] == 'filter_languages': if len(channel_language) > 1: control['lvalues'] = list_language channel_controls.append(control) else: pass else: channel_controls.append(control) if renumber: for control in default_controls_renumber: if control['id'] not in str(channel_controls): channel_controls.append(control) else: pass return channel_controls
def Capitulos(self, Nam, URLL="", THUMB="", historial="", temporada=""): try: global opener global OTRO NN = Nam NN = NN.replace("¡", "") NN = NN.replace("¿", "") NN = NN.replace("?", "") NN = NN.replace(":", "") NN = NN.replace("º", "") NN = NN.replace("ª", "") NN = NN.replace("\"", "") NN = NN.replace("\'", "") NN = NN.replace("(", "") NN = NN.replace(")", "") NN = NN.replace("á", "a") NN = NN.replace("Á", "A") NN = NN.replace("é", "e") NN = NN.replace("É", "E") NN = NN.replace("í", "i") NN = NN.replace("Í", "I") NN = NN.replace("ó", "o") NN = NN.replace("Ó", "O") NN = NN.replace("ú", "u") NN = NN.replace("Ú", "U") NN = NN.replace("ñ", "n") NN = NN.replace("Ñ", "N") NN = NN.replace("ñ", "n") NN = NN.replace(""", "") NN = NN.replace("'", "") NN = NN.replace("'", "") if "###" in URLL: idd = URLL.split("###")[1].split(";")[0] typee = URLL.split("###")[1].split(";")[1] URLL = URLL.split("###")[0] Categ = RutaTMP + NN.encode('utf8') + "_1.xml" url = 'https://hdfull.io/a/episodes' post = "action=season&start=0&limit=0&show=%s&season=%s" % (idd, temporada) req = urllib2.Request(url) req.add_header('User-Agent', user_agent_default) req.add_header('Referer', URLL) Abrir = OP(req, data=post) data = jsontools.load(Abrir.read()) Abrir.close() FF = open(Categ, 'w') for episode in data: language = episode['languages'] tempo = episode['season'] episodio = episode['episode'] if episode['title']['es'] == "": titulo = "" else: titulo = str(episode['title']['es'].decode('utf8')) titulo = titulo.replace('\xc3\xb1', 'n') titulo = titulo.replace('\xc3\x81', 'A') titulo = titulo.replace('\xc3\xa1', 'a') titulo = titulo.replace('\xc3\x8d', 'I') titulo = titulo.replace('\xc3\xad', 'i') titulo = titulo.replace('\xc3\x89', 'E') titulo = titulo.replace('\xc3\xa9', 'e') titulo = titulo.replace('\xc3\x93', 'O') titulo = titulo.replace('\xc3\xb3', 'o') titulo = titulo.replace('\xc3\x9a', 'U') titulo = titulo.replace('\xc3\xba', 'u') if episodio == "1": FF.write( '<?xml version="1.0" encoding="iso-8859-1"?>\n<items>\n<playlist_name><![CDATA[' + titulo + ']]></playlist_name>\n\n') FF.write("<channel>\n") FF.write(" <title><![CDATA[" + temporada + "x" + episodio + " " + titulo + "]]></title>\n") FF.write(' <description><![CDATA[]]></description>\n') FF.write(' <playlist_url><![CDATA[' + URLL + '/episodio-' + episodio + ']]></playlist_url>\n') FF.write(' <img_src><![CDATA[' + str(THUMB) + ']]></img_src>\n') FF.write(' <tipo><![CDATA[hdfullEnlaces]]></tipo>\n') FF.write(' <historial><![CDATA[' + Categ + ']]></historial>\n') FF.write('</channel>\n\n') FF.write('<prev_page_url text="CH- ATRAS"><![CDATA[' + historial + ']]></prev_page_url>\n</items>') FF.close() return Categ except Exception as er: print "Error: " + str(er) + " En Capitulos HDFULL" print "Error: " + str(er) + " En Capitulos HDFULL" print "Error: " + str(er) + " En Capitulos HDFULL" return [1, er]
def Enlaces(self, Nam, URLL="", THUMB="", historial=""): NN = Nam NN = NN.replace("¡", "") NN = NN.replace("¿", "") NN = NN.replace("?", "") NN = NN.replace(":", "") NN = NN.replace("º", "") NN = NN.replace("ª", "") NN = NN.replace("\"", "") NN = NN.replace("\'", "") NN = NN.replace("(", "") NN = NN.replace(")", "") NN = NN.replace("á", "a") NN = NN.replace("Á", "A") NN = NN.replace("é", "e") NN = NN.replace("É", "E") NN = NN.replace("í", "i") NN = NN.replace("Í", "I") NN = NN.replace("ó", "o") NN = NN.replace("Ó", "O") NN = NN.replace("ú", "u") NN = NN.replace("Ú", "U") NN = NN.replace("ñ", "n") NN = NN.replace("Ñ", "N") NN = NN.replace("ñ", "n") NN = NN.replace(""", "") NN = NN.replace("'", "") NN = NN.replace("'", "") ENN = URLL IMG = THUMB Categ = RutaTMP + NN + ".xml" if "###" in ENN: id = ENN.split("###")[1].split(";")[0] type = ENN.split("###")[1].split(";")[1] ENN = ENN.split("###")[0] itemlist = [] it1 = [] it2 = [] url_targets = ENN data_js = httptools.downloadpage( "http://ps3plusteam.ddns.net/hdfull/jquery.hdfull.view.min.js", headers={ 'referer': 'http://ps3plusteam.ddns.net/' }).data key = scrapertools.find_single_match( data_js, 'JSON.parse\(atob.*?substrings\((.*?)\)') data_js = httptools.downloadpage( "http://ps3plusteam.ddns.net/hdfull/providers.js", headers={ 'referer': 'http://ps3plusteam.ddns.net/' }).data decoded = jhexdecode(data_js).replace("'", '"') providers_pattern = 'p\[(\d+)\]= {"t":"([^"]+)","d":".*?","e":.function.*?,"l":.function.*?return "([^"]+)".*?};' providers = scrapertools.find_multiple_matches(decoded, providers_pattern) provs = {} for provider, e, l in providers: provs[provider] = [e, l] data = agrupa_datos(ENN) data_obf = scrapertools.find_single_match(data, "var ad\s*=\s*'([^']+)'") data_decrypt = jsontools.load( obfs(base64.b64decode(data_obf), 126 - int(key))) FF = open(Categ, 'w') FF.write( '<?xml version="1.0" encoding="iso-8859-1"?>\n<items>\n<playlist_name><![CDATA[' + NN + ']]></playlist_name>\n\n') Conteo = 0 matches = [] for match in data_decrypt: if match['provider'] in provs: try: embed = provs[match['provider']][0] url = provs[match['provider']][1] + match['code'] matches.append([match['lang'], match['quality'], url, embed]) except: pass for idioma, calidad, url, embed in matches: if embed == 'd': option = "Descargar" option1 = 2 if idioma == "ESP": if url.find('uptobox') != -1: Conteo = Conteo + 1 FF.write("<channel>\n") FF.write(" <title><![CDATA[Ver en gamovideo " + NN.encode('utf8') + " " + calidad + "]]></title>\n") FF.write(' <description><![CDATA[' + IMG + ']]></description>\n') FF.write(' <playlist_url><![CDATA[' + url + ']]></playlist_url>\n') FF.write( ' <stream_url><![CDATA[http://ps3plusteam.ddns.net/teamps3plus/pro/uptobox.txt]]></stream_url>\n' ) FF.write( ' <img_src><![CDATA[http://ps3plusteam.ddns.net/ps3plus/images/letras/uptobox.png]]></img_src>\n' ) FF.write(' <tipo><![CDATA[hdfullLinks]]></tipo>\n') FF.write('</channel>\n\n') else: option = "Ver" option1 = 1 if idioma == "ESP": Conteo = Conteo + 1 if url.find('vidoza') != -1: FF.write("<channel>\n") FF.write(" <title><![CDATA[Ver en vidoza " + NN.encode('utf8') + " " + calidad + "]]></title>\n") FF.write(' <description><![CDATA[' + IMG + ']]></description>\n') FF.write(' <playlist_url><![CDATA[' + url + ']]></playlist_url>\n') FF.write( ' <stream_url><![CDATA[http://ps3plusteam.ddns.net/teamps3plus/pro/vidoza.txt]]></stream_url>\n' ) FF.write( ' <img_src><![CDATA[http://ps3plusteam.ddns.net/ps3plus/images/letras/vidoza.png]]></img_src>\n' ) FF.write(' <tipo><![CDATA[hdfullLinks]]></tipo>\n') FF.write('</channel>\n\n') if url.find('gamovideo') != -1: Conteo = Conteo + 1 buscaID = re.findall(r'com/(.*)', url) buscaID = buscaID[0] FF.write("<channel>\n") FF.write(" <title><![CDATA[Ver en gamovideo " + NN.encode('utf8') + " " + calidad + "]]></title>\n") FF.write(' <description><![CDATA[' + IMG + ']]></description>\n') FF.write( ' <playlist_url><![CDATA[http://gamovideo.com/embed-' + buscaID + '-640x360.html]]></playlist_url>\n') FF.write( ' <stream_url><![CDATA[http://ps3plusteam.ddns.net/teamps3plus/props3/gamo.txt]]></stream_url>\n' ) FF.write( ' <img_src><![CDATA[http://ps3plusteam.ddns.net/ps3plus/images/letras/gamovideo.png]]></img_src>\n' ) FF.write(' <tipo><![CDATA[hdfullLinks]]></tipo>\n') FF.write('</channel>\n\n') FF.write('<prev_page_url text="CH- ATRAS"><![CDATA[' + historial + ']]></prev_page_url>\n</items>') if Conteo == 0: return None return Categ
def get_default_settings(channel_name): import filetools default_path = filetools.join(config.get_runtime_path(), 'default_channel_settings' + '.json') default_file = jsontools.load(filetools.read(default_path)) channel_path = filetools.join(config.get_runtime_path(), 'channels', channel_name + '.json') adult_path = filetools.join(config.get_runtime_path(), 'channels', 'p**n', channel_name + '.json') # from core.support import dbg; dbg() if os.path.exists(channel_path) or os.path.exists(adult_path): default_controls = default_file['settings'] default_controls_renumber = default_file['renumber'] channel_json = get_channel_json(channel_name) # Collects configurations channel_language = channel_json['language'] channel_controls = channel_json['settings'] categories = channel_json['categories'] not_active = channel_json['not_active'] if channel_json.has_key( 'not_active') else [] default_off = channel_json['default_off'] if channel_json.has_key( 'default_off') else [] # Apply default configurations if they do not exist for control in default_controls: if control['id'] not in str(channel_controls): if 'include_in_newest' in control[ 'id'] and 'include_in_newest' not in not_active and control[ 'id'] not in not_active: label = control['id'].split('_') label = label[-1] if label == 'peliculas': if 'movie' in categories: control['label'] = config.get_localized_string( 70727) + ' - ' + config.get_localized_string( 30122) control['default'] = False if ( 'include_in_newest' in default_off) or ( 'include_in_newest_peliculas' in default_off) else True channel_controls.append(control) else: pass elif label == 'series': if 'tvshow' in categories: control['label'] = config.get_localized_string( 70727) + ' - ' + config.get_localized_string( 30123) control['default'] = False if ( 'include_in_newest' in default_off) or ('include_in_newest_series' in default_off) else True channel_controls.append(control) else: pass elif label == 'anime': if 'anime' in categories: control['label'] = config.get_localized_string( 70727) + ' - ' + config.get_localized_string( 30124) control['default'] = False if ( 'include_in_newest' in default_off) or ('include_in_newest_anime' in default_off) else True channel_controls.append(control) else: pass else: control['label'] = config.get_localized_string( 70727) + ' - ' + label.capitalize() control['default'] = control['default'] if control[ 'id'] not in default_off else False channel_controls.append(control) elif control[ 'id'] not in not_active and 'include_in_newest' not in control[ 'id']: if type(control['default']) == bool: control['default'] = control['default'] if control[ 'id'] not in default_off else False channel_controls.append(control) if 'anime' in categories: for control in default_controls_renumber: if control['id'] not in str(channel_controls): channel_controls.append(control) else: pass else: return get_channel_json(channel_name).get('settings', list()) return channel_controls
def Capitulos(self, Nam, URLL = "", THUMB = "", historial = "", temporada = ""): try: global opener global OTRO NN = Nam NN = CambiaTexto(NN) if "###" in URLL: idd = URLL.split("###")[1].split(";")[0] typee = URLL.split("###")[1].split(";")[1] URLL = URLL.split("###")[0] Categ = RutaTMP + NN.encode('utf8') + "_1.xml" url = 'https://hdfull.lv/a/episodes' post = "action=season&start=0&limit=0&show=%s&season=%s" % (idd, temporada) req = urllib2.Request(url) req.add_header('User-Agent',user_agent_default) req.add_header('Referer', URLL) Abrir = OP(req, data=post) data = jsontools.load(Abrir.read()) Abrir.close() FF = open(Categ, 'w') for episode in data: language = episode['languages'] tempo = episode['season'] episodio = episode['episode'] if "es" in episode['title']: titulo = str(episode['title']['es'].decode('utf8')) elif "en" in episode['title']: titulo = str(episode['title']['en'].decode('utf8')) else: titulo = "" titulo = CambiaTexto(titulo) if episodio == "1": FF.write('<?xml version="1.0" encoding="iso-8859-1"?>\n<items>\n<playlist_name><![CDATA[' + titulo + ']]></playlist_name>\n\n') FF.write("<channel>\n") FF.write(" <title><![CDATA[" + temporada + "x" + episodio + " " + titulo + "]]></title>\n") FF.write(' <description><![CDATA[]]></description>\n') FF.write(' <playlist_url><![CDATA[' + URLL + '/episodio-' + episodio + ']]></playlist_url>\n') FF.write(' <img_src><![CDATA[' + str(THUMB) + ']]></img_src>\n') FF.write(' <tipo><![CDATA[hdfullEnlaces]]></tipo>\n') FF.write(' <historial><![CDATA[' + Categ + ']]></historial>\n') FF.write('</channel>\n\n') FF.write('<prev_page_url text="CH- ATRAS"><![CDATA[' + historial + ']]></prev_page_url>\n</items>') FF.close() return Categ except Exception as er: Log(str(er), "En Capitulos HDFULL") return [1, er]