def get_current_episode(file_path_b64=None): try: redis = redis_connect() if file_path_b64 is None: current_tv_show_name_b64 = redis_circular_list.current( redis, "STATE.USB_STORAGE.LIBRARY.TV_SHOWS") current_tv_show_name = utils.base64_decode( current_tv_show_name_b64) file_path_b64 = redis_circular_list.current( redis, f"STATE.USB_STORAGE.LIBRARY.TV_SHOWS.{current_tv_show_name_b64}" ) file_path = utils.base64_decode(file_path_b64) meta_data_key = f"STATE.USB_STORAGE.LIBRARY.META_DATA.{file_path_b64}" meta_data = redis.get(meta_data_key) if meta_data is None: meta_data = { "current_time": 0, "duration": 0, "last_watched_time": 0, "last_completed_time": 0, "file_path": file_path } redis.set(meta_data_key, json.dumps(meta_data)) else: meta_data = json.loads(meta_data) return meta_data except Exception as e: print(e) return False
def analyze(data: SubscribeCrawl, html: str): if html is None or html == "": return None if data.crawl_type == SubscribeCrawlType.Subscription.value: try: v2ray_url_list = utils.base64_decode(html).split("\n") for v2ray_url in v2ray_url_list: add_new_vmess(v2ray_url, crawl_id=data.id, interval=data.interval) except: logger.error("err: {}".format(traceback.format_exc())) elif data.crawl_type == SubscribeCrawlType.Xpath.value: rule = VariableManager(data.rule) soup = etree.HTML(html) for result in soup.xpath(rule.get_conf_str("xpath", default=None)): if not isinstance(result, str) or result.__len__() == 0: continue try: v2ray_url_list = utils.base64_decode(result).split("\n") for v2ray_url in v2ray_url_list: add_new_vmess(v2ray_url, crawl_id=data.id, interval=data.interval) except: logger.error("err: {}".format(traceback.format_exc()))
def deserialize(serialized_format, delimiter=':', text_encoding="utf-8"): crypto_data = HashBasedCryptoData(from_code=True) crypto_data.apply_deserialized_data (*utils.base64_decode ( *serialized_format.split (delimiter), \ text_encoding = text_encoding )) return crypto_data
def add_new_vmess( v2ray_url, crawl_id: int = 0, interval: int = global_variable.get_conf_int("INTERVAL", default=1800), ) -> bool: try: if v2ray_url == "": return False # 已经存在了,就不管了 data = (global_variable.get_db().query(SubscribeVmss).filter( SubscribeVmss.url == v2ray_url).first()) if data is not None: if (data.death_count is None or data.death_count < global_variable.get_conf_int( "BASE_DEATH_COUNT", default=10)): logger.debug("vmess crawl again {}".format(v2ray_url)) new_db = global_variable.get_db() new_db.query(SubscribeVmss).filter( SubscribeVmss.id == data.id).update({ SubscribeVmss.death_count: int( global_variable.get_conf_int("BASE_DEATH_COUNT", default=30) / 2), }) new_db.commit() return True if v2ray_url.startswith("vmess://"): # vmess try: logger.debug("new vmess is {}".format(v2ray_url)) v = json.loads( utils.base64_decode(v2ray_url.replace("vmess://", ""))) new_db = global_variable.get_db() new_db.add( SubscribeVmss( url=v2ray_url, network_protocol_type="" if v.get("net") is None else v.get("net"), death_count=global_variable.get_conf_int( "BASE_DEATH_COUNT", default=30), next_at=0, is_closed=False, interval=int(interval), crawl_id=int(crawl_id), conf_details=v, )) new_db.commit() return True except sqlalchemy.exc.IntegrityError: pass except (UnicodeDecodeError, json.decoder.JSONDecodeError): pass except: logger.error("err: {}".format(traceback.format_exc())) return False except: logger.error("err: {}".format(traceback.format_exc())) return True
def get_node_by_url(url: str != ""): try: # if url.startswith("ss://"): # ss node # node_type = "ss" # base64_str = url.replace("ss://", "") # base64_str = urllib.parse.unquote(base64_str) # # origin = utils.decode(base64_str[0 : base64_str.index("#")]) # remark = base64_str[base64_str.index("#") + 1 :] # security = origin[0 : origin.index(":")] # password = origin[origin.index(":") + 1 : origin.index("@")] # ipandport = origin[origin.index("@") + 1 :] # ip = ipandport[0 : ipandport.index(":")] # port = int(ipandport[ipandport.index(":") + 1 :]) # ssode = Shadowsocks(ip, port, remark, security, password) # node = ssode if url.startswith("vmess://"): # vmess server_node = json.loads(utils.base64_decode(url.replace("vmess://", ""))) return V2ray( server_node["add"], int(server_node["port"]), server_node["ps"], "auto", server_node["id"], int(server_node["aid"]), server_node["net"], server_node["type"], server_node["host"], server_node["path"], server_node["tls"], ) except: logger.error(traceback.format_exc()) return None
def get_next_episode(file_path=None): redis = redis_connect() if file_path is not None: file_path = utils.base64_encode(file_path) episode = get_current_episode(file_path) while is_episode_over(episode) == True: current_tv_show_name_b64 = redis_circular_list.current( redis, "STATE.USB_STORAGE.LIBRARY.TV_SHOWS") current_tv_show_name = utils.base64_decode(current_tv_show_name_b64) file_path_b64 = redis_circular_list.next( redis, f"STATE.USB_STORAGE.LIBRARY.TV_SHOWS.{current_tv_show_name_b64}") print(file_path_b64) episode = get_current_episode(file_path_b64) return episode
def data_cleaning(can_be_used): vmess_list = [] index = 0 for subscribe_vmess in can_be_used: index += 1 try: v = json.loads( utils.base64_decode(subscribe_vmess.url.replace( "vmess://", ""))) v["ps"] = "{}-{}".format(index, title_service.get()) vmess_list.append("vmess://" + utils.base64_encode(v)) except: logger.error("err: {}".format(traceback.format_exc())) vmess_list.append(subscribe_vmess.url) return vmess_list
def next(request): result = {"message": "failed"} try: # 1.) Get State ensure_usb_drive_is_mounted() redis = redis_connect() config = redis.get("CONFIG.LOCAL_STORAGE_CONTROLLER_SERVER") config = json.loads(config) vlc_config = config["vlc"] # 2.) Advance to Next TV Show in Circular List next_tv_show_name_b64 = redis_circular_list.next( redis, "STATE.USB_STORAGE.LIBRARY.TV_SHOWS") next_tv_show_name = utils.base64_decode(next_tv_show_name_b64) # 3.) Advance to Next Episode in TV Show even though current one might be un-finished file_path_b64 = redis_circular_list.next( redis, f"STATE.USB_STORAGE.LIBRARY.TV_SHOWS.{next_tv_show_name_b64}") episode = get_current_episode(file_path_b64) # 4.) Start Episode vlc = VLCController(vlc_config) vlc.add(episode["file_path"]) time.sleep(1) if int(episode["current_time"]) > 5: vlc.seek(int(episode["current_time"]) - 5) vlc.volume_set(100) time.sleep(3) vlc.fullscreen_on() # 5.) Get Status result["status"] = vlc.get_common_info() pprint(result["status"]) # 6.) Update Duration update_duration_metadata(result["status"]["status"]["duration"], result["status"]["status"]["file_path"]) result["message"] = "success" except Exception as e: print(e) result["error"] = str(e) return json_result(result)
def server_handshake(self): try: handshake_init = self.locked_socket.recv(timeout=10, max_data_size=1024) except: raise HandshakeError handshake_init_re = re.search("^session:(.+)$", handshake_init) if not handshake_init_re: raise HandshakeError session_key_b64 = handshake_init_re.group(1) if not utils.isBase64(session_key_b64): raise HandshakeError session_key_rsa_encrypted = utils.base64_decode(session_key_b64) self.session_key = PKCS1_OAEP.new( self.key).decrypt(session_key_rsa_encrypted) if len(self.session_key) != 16 and len(self.session_key) != 32 and len( self.session_key) != 24: raise HandshakeError try: handshake_verify = self.send("handshake_verify") except LockedSocket.SocketConnectionClosed: raise LockedSocket.SocketConnectionClosed except EncryptionError: raise EncryptionError try: handshake_client_verify = self.recv(max_data_size=1024, timeout=2) except Exception as e: raise HandshakeError if handshake_client_verify != "handshake_verify2": raise HandshakeError
def rebuild_tv_shows( self ): print( "Rebuilding TV Shows" ) self.redis.delete( "STATE.USB_STORAGE.LIBRARY.TV_SHOWS" ) for key in self.redis.scan_iter( "STATE.USB_STORAGE.LIBRARY.TV_SHOWS.*" ): self.redis.delete( key ) # Testing Delete All via CLI # redis-cli -n 1 --raw keys "STATE.USB_STORAGE.LIBRARY.*" | xargs redis-cli -n 1 del print( self.paths["tv_shows"] ) tv_shows = self.scan_posix_path( self.paths["tv_shows"] ) tv_shows_map = {} for index , posix_episode in enumerate( tv_shows ): print( str( posix_episode ) ) items = str( posix_episode ).split( str( self.paths["tv_shows"] ) + "/" )[ 1 ].split( "/" ) if len( items ) == 3: show_name = items[ 0 ] season_name = items[ 1 ] episode_name = items[ 2 ] elif len( items ) == 2: show_name = items[ 0 ] season_name = items[ 1 ] episode_name = items[ 2 ] elif len( items ) == 1: show_name = "SINGLES" season_name = "000" episode_name = items[ 0 ] else: print( "wadu" ) print( items ) continue # Don't Ask show_name_b64 = utils.base64_encode( show_name ) season_name_b64 = utils.base64_encode( season_name ) episode_name_b64 = utils.base64_encode( episode_name ) if show_name_b64 not in tv_shows_map: tv_shows_map[ show_name_b64 ] = {} if season_name_b64 not in tv_shows_map[ show_name_b64 ]: tv_shows_map[ show_name_b64 ][ season_name_b64 ] = [] tv_shows_map[ show_name_b64 ][ season_name_b64 ].append( episode_name_b64 ) # Also Don't Ask # since you did, its just some bulll shit to double verify that they order is correct. # glob sorts it fine, but why not sort it again 4Head Pepega # also, why not encode and decode the same thing like 50 times tv_shows_map_organized = {} show_names_b64 = tv_shows_map.keys() show_names = [ utils.base64_decode( x ) for x in show_names_b64 ] show_names.sort() for index , show_name in enumerate( show_names ): season_names_b64 = tv_shows_map[ utils.base64_encode( show_name ) ].keys() tv_shows_map_organized[ show_name ] = [ utils.base64_decode( x ) for x in season_names_b64 ] tv_shows_map_organized[ show_name ].sort() for season_index , season in enumerate( tv_shows_map_organized[ show_name ] ): episode_names_b64 = tv_shows_map[ utils.base64_encode( show_name ) ][ utils.base64_encode( season ) ] episode_names = [ utils.base64_decode( x ) for x in episode_names_b64 ] episode_names.sort() tv_shows_map_organized[ show_name ][ season_index ] = episode_names # Finally Store into Redis #pprint( tv_shows_map_organized ) # 1.) Store All Show Names into Circular List show_keys = tv_shows_map_organized.keys() show_names_b64 = [ utils.base64_encode( x ) for x in show_keys ] for x in show_names_b64: self.redis.rpush( "STATE.USB_STORAGE.LIBRARY.TV_SHOWS" , x ) self.redis.set( "STATE.USB_STORAGE.LIBRARY.TV_SHOWS.INDEX" , 0 ) # 2.) Store All Episodes into Giant List for show_index , show in enumerate( show_keys ): list_key = f"STATE.USB_STORAGE.LIBRARY.TV_SHOWS.{show_names_b64[show_index]}" for season_index , season in enumerate( tv_shows_map_organized[ show ] ): for episode_index , episode in enumerate( tv_shows_map_organized[ show ][ season_index ] ): final_path = str( self.paths["tv_shows"].joinpath( show , str( season_index + 1 ).zfill( 2 ) , episode ) ) self.redis.rpush( list_key , utils.base64_encode( final_path ) )
# today8: dead_time = today8 elif now < today20: dead_time = today20 else: dead_time = ( # datetime.datetime.now().replace(hour=8, minute=0, second=0, microsecond=0) + datetime.timedelta( # days=1)).timestamp() dead_time = int(dead_time) logger.info("free-ss-80 的下次更新时间为 {}".format(dead_time)) # add_new_node(v2ray_url, 0, dead_time=dead_time) last_update_info["free-ss-80"] = dead_time except: # traceback.print_exc() # if (last_update_info.get("freev2ray") is not None) and ( # (last_update_info.get("freev2ray") > now) or (last_update_info.get("freev2ray") == 0)): # try: # url = "https://xxx.freev2ray.org/" # data = requests.get(url, timeout=10).text # # soup = etree.HTML(data) # v2ray_url = ( # soup.xpath('//*[@id="intro"]/div/div/footer/ul[1]/li[2]/button/@data-clipboard-text')[0]) # add_new_vmess(v2ray_url) # except: # traceback.print_exc() # finally: # last_update_info["freev2ray"] = now + int(random.uniform(0.5, 1.5) * 60 * 60) + int(time.time()) except: logger.error("err: {}".format(traceback.format_exc())) finally: time.sleep(60) if __name__ == "__main__": v2ray_url = "vmess://Y2hhY2hhMjAtcG9seTEzMDU6OTUxMzc4NTctNzBmYS00YWM4LThmOTAtNGUyMGFlYjY2MmNmQHVuaS5raXRzdW5lYmkuZnVuOjQ0Mw==?network=h2&h2Path=/v2&aid=0&tls=1&allowInsecure=0&tlsServer=uni.kitsunebi.fun&mux=0&muxConcurrency=8&remark=H2%20Test%20Outbound" print(utils.base64_decode(v2ray_url.replace("vmess://", ""))) print(json.loads(utils.base64_decode(v2ray_url.replace("vmess://", ""))))
def start_command_handler(update: telegram.Update, context: telegram.ext.CallbackContext) -> None: message = update.message if message is None: return bot = context.bot message_id = message.message_id chat_id = message.chat_id user = message.from_user args = context.args or [] query = ' '.join(args) try: query = utils.base64_decode(query) except UnicodeDecodeError: pass if user is not None: create_or_update_user(bot, user) analytics_handler.track(context, analytics.AnalyticsType.COMMAND, user, f'/start {query}') if query: bot.send_chat_action(chat_id, telegram.ChatAction.TYPING) if user is not None: analytics_handler.track(context, analytics.AnalyticsType.MESSAGE, user, query) links_toggle = False (definitions, offset) = utils.get_query_definitions(update, context, query, links_toggle, analytics_handler, cli_args, BOT_NAME) if len(definitions) == 0: telegram_utils.send_no_results_message(bot, chat_id, message_id, query) else: definition = definitions[offset] reply_markup = telegram.InlineKeyboardMarkup( definition.inline_keyboard_buttons) bot.send_message(chat_id=chat_id, text=definition.html, reply_markup=reply_markup, parse_mode=telegram.ParseMode.HTML, disable_web_page_preview=True, reply_to_message_id=message_id) if user is not None: utils.send_subscription_onboarding_message_if_needed( bot=bot, user=user, chat_id=chat_id) else: reply_button = telegram.InlineKeyboardButton( 'Încearcă', switch_inline_query='cuvânt') reply_markup = telegram.InlineKeyboardMarkup([[reply_button]]) first_phrase = 'Salut, sunt un bot care caută definiții pentru cuvinte folosind' link = telegram_utils.escape_v2_markdown_text_link( text='dexonline.ro', url='http://dexonline.ro') second_phrase_1 = 'Poți scrie direct cuvântul căutat aici în chat sau poți să scrii "@' second_phrase_2 = '_cuvânt_"' second_phrase_3 = 'în orice alt chat.' bot.send_message( chat_id=chat_id, text= (f'{telegram_utils.escape_v2_markdown_text(first_phrase)} {link}{telegram_utils.ESCAPED_FULL_STOP}\n' f'{telegram_utils.escape_v2_markdown_text(second_phrase_1)}{BOT_NAME} ' f'{second_phrase_2} {telegram_utils.escape_v2_markdown_text(second_phrase_3)}' ), reply_markup=reply_markup, parse_mode=telegram.ParseMode.MARKDOWN_V2)