|
32 | 32 |
|
33 | 33 | __version__ = "2.1" |
34 | 34 |
|
35 | | -os.system("") |
36 | | - |
37 | 35 |
|
38 | 36 | class ConnectionInfo: |
39 | 37 | """Class to store connection information""" |
@@ -64,6 +62,8 @@ def __init__(self): |
64 | 62 | self.no_blacklist = False |
65 | 63 | self.auto_blacklist = False |
66 | 64 | self.quiet = False |
| 65 | + self.not_check_update = False |
| 66 | + self.hide_banner = False |
67 | 67 |
|
68 | 68 |
|
69 | 69 | class IBlacklistManager(ABC): |
@@ -902,14 +902,12 @@ def __init__( |
902 | 902 | async def check_for_updates(self): |
903 | 903 | """Check for updates""" |
904 | 904 |
|
905 | | - if self.config.quiet: |
906 | | - return None |
907 | | - |
908 | 905 | try: |
909 | 906 | loop = asyncio.get_event_loop() |
910 | 907 |
|
911 | 908 | def sync_check(): |
912 | 909 | try: |
| 910 | + # self.logger.debug("Check for updates") |
913 | 911 | req = Request( |
914 | 912 | "https://gvcoder09.github.io/nodpi_site/api/v1/update_info.json", |
915 | 913 | ) |
@@ -939,95 +937,101 @@ def sync_check(): |
939 | 937 | async def print_banner(self) -> None: |
940 | 938 | """Print startup banner""" |
941 | 939 |
|
942 | | - self.update_check_task = asyncio.create_task(self.check_for_updates()) |
| 940 | + if self.config.quiet: |
| 941 | + return |
| 942 | + |
| 943 | + if not self.config.not_check_update: |
| 944 | + self.update_check_task = asyncio.create_task(self.check_for_updates()) |
943 | 945 |
|
944 | | - try: |
945 | | - await asyncio.wait_for(self.update_event.wait(), timeout=2.0) |
946 | | - except asyncio.TimeoutError: |
947 | | - if self.update_check_task and not self.update_check_task.done(): |
948 | | - self.update_check_task.cancel() |
949 | | - try: |
950 | | - await self.update_check_task |
951 | | - except asyncio.CancelledError: |
952 | | - pass |
| 946 | + try: |
| 947 | + await asyncio.wait_for(self.update_event.wait(), timeout=2.0) |
| 948 | + except asyncio.TimeoutError: |
| 949 | + if self.update_check_task and not self.update_check_task.done(): |
| 950 | + self.update_check_task.cancel() |
| 951 | + try: |
| 952 | + await self.update_check_task |
| 953 | + except asyncio.CancelledError: |
| 954 | + pass |
953 | 955 |
|
954 | 956 | self.logger.info("\033]0;NoDPI\007") |
955 | 957 |
|
956 | 958 | if sys.platform == "win32": |
957 | 959 | os.system("mode con: lines=33") |
958 | 960 |
|
959 | | - if sys.stdout.isatty(): |
960 | | - console_width = os.get_terminal_size().columns |
961 | | - else: |
962 | | - console_width = 80 |
963 | | - |
964 | | - disclaimer = ( |
965 | | - "DISCLAIMER. The developer and/or supplier of this software " |
966 | | - "shall not be liable for any loss or damage, including but " |
967 | | - "not limited to direct, indirect, incidental, punitive or " |
968 | | - "consequential damages arising out of the use of or inability " |
969 | | - "to use this software, even if the developer or supplier has been " |
970 | | - "advised of the possibility of such damages. The developer and/or " |
971 | | - "supplier of this software shall not be liable for any legal " |
972 | | - "consequences arising out of the use of this software. This includes, " |
973 | | - "but is not limited to, violation of laws, rules or regulations, " |
974 | | - "as well as any claims or suits arising out of the use of this software. " |
975 | | - "The user is solely responsible for compliance with all applicable laws " |
976 | | - "and regulations when using this software." |
977 | | - ) |
978 | | - wrapped_text = textwrap.TextWrapper(width=70).wrap(disclaimer) |
979 | | - |
980 | | - left_padding = (console_width - 76) // 2 |
| 961 | + if not self.config.hide_banner: |
| 962 | + if sys.stdout.isatty(): |
| 963 | + console_width = os.get_terminal_size().columns |
| 964 | + else: |
| 965 | + console_width = 80 |
| 966 | + # self.logger.debug("console_width=", console_width) |
| 967 | + |
| 968 | + disclaimer = ( |
| 969 | + "DISCLAIMER. The developer and/or supplier of this software " |
| 970 | + "shall not be liable for any loss or damage, including but " |
| 971 | + "not limited to direct, indirect, incidental, punitive or " |
| 972 | + "consequential damages arising out of the use of or inability " |
| 973 | + "to use this software, even if the developer or supplier has been " |
| 974 | + "advised of the possibility of such damages. The developer and/or " |
| 975 | + "supplier of this software shall not be liable for any legal " |
| 976 | + "consequences arising out of the use of this software. This includes, " |
| 977 | + "but is not limited to, violation of laws, rules or regulations, " |
| 978 | + "as well as any claims or suits arising out of the use of this software. " |
| 979 | + "The user is solely responsible for compliance with all applicable laws " |
| 980 | + "and regulations when using this software." |
| 981 | + ) |
| 982 | + wrapped_text = textwrap.TextWrapper(width=70).wrap(disclaimer) |
981 | 983 |
|
982 | | - self.logger.info("\n\n\n") |
983 | | - self.logger.info( |
984 | | - "\033[91m" + " " * left_padding + "╔" + "═" * 72 + "╗" + "\033[0m" |
985 | | - ) |
| 984 | + left_padding = (console_width - 76) // 2 |
986 | 985 |
|
987 | | - for line in wrapped_text: |
988 | | - padded_line = line.ljust(70) |
| 986 | + self.logger.info("\n\n\n") |
989 | 987 | self.logger.info( |
990 | | - "\033[91m" + " " * left_padding + |
991 | | - "║ " + padded_line + " ║" + "\033[0m" |
| 988 | + "\033[91m" + " " * left_padding + "╔" + "═" * 72 + "╗" + "\033[0m" |
992 | 989 | ) |
993 | 990 |
|
994 | | - self.logger.info( |
995 | | - "\033[91m" + " " * left_padding + "╚" + "═" * 72 + "╝" + "\033[0m" |
996 | | - ) |
| 991 | + for line in wrapped_text: |
| 992 | + padded_line = line.ljust(70) |
| 993 | + self.logger.info( |
| 994 | + "\033[91m" + " " * left_padding + |
| 995 | + "║ " + padded_line + " ║" + "\033[0m" |
| 996 | + ) |
997 | 997 |
|
998 | | - time.sleep(1) |
| 998 | + self.logger.info( |
| 999 | + "\033[91m" + " " * left_padding + "╚" + "═" * 72 + "╝" + "\033[0m" |
| 1000 | + ) |
999 | 1001 |
|
1000 | | - update_message = None |
1001 | | - if self.update_check_task and self.update_check_task.done(): |
1002 | | - try: |
1003 | | - update_message = self.update_check_task.result() |
1004 | | - except (asyncio.CancelledError, Exception): |
1005 | | - pass |
| 1002 | + time.sleep(1) |
1006 | 1003 |
|
1007 | | - self.logger.info("\033[2J\033[H") |
| 1004 | + self.logger.info("\033[2J\033[H") |
1008 | 1005 |
|
1009 | | - self.logger.info( |
1010 | | - """ |
1011 | | -\033[92m ██████ █████ ██████████ ███████████ █████ |
| 1006 | + self.logger.info( |
| 1007 | + """\033[92m |
| 1008 | + ██████ █████ ██████████ ███████████ █████ |
1012 | 1009 | ░░██████ ░░███ ░░███░░░░███ ░░███░░░░░███░░███ |
1013 | 1010 | ░███░███ ░███ ██████ ░███ ░░███ ░███ ░███ ░███ |
1014 | 1011 | ░███░░███░███ ███░░███ ░███ ░███ ░██████████ ░███ |
1015 | 1012 | ░███ ░░██████ ░███ ░███ ░███ ░███ ░███░░░░░░ ░███ |
1016 | 1013 | ░███ ░░█████ ░███ ░███ ░███ ███ ░███ ░███ |
1017 | 1014 | █████ ░░█████░░██████ ██████████ █████ █████ |
1018 | | - ░░░░░ ░░░░░ ░░░░░░ ░░░░░░░░░░ ░░░░░ ░░░░░\033[0m |
1019 | | - """ |
1020 | | - ) |
1021 | | - self.logger.info(f"\033[92mVersion: {__version__}".center(50)) |
1022 | | - self.logger.info( |
1023 | | - "\033[97m" + |
1024 | | - "Enjoy watching! / Наслаждайтесь просмотром!".center(50) |
1025 | | - ) |
| 1015 | + ░░░░░ ░░░░░ ░░░░░░ ░░░░░░░░░░ ░░░░░ ░░░░░ |
| 1016 | +\033[0m""" |
| 1017 | + ) |
| 1018 | + self.logger.info(f"\033[92mVersion: {__version__}".center(console_width)) |
| 1019 | + self.logger.info( |
| 1020 | + "\033[97m" + |
| 1021 | + "Enjoy watching! / Наслаждайтесь просмотром!".center(console_width) |
| 1022 | + ) |
1026 | 1023 |
|
1027 | | - self.logger.info("\n") |
| 1024 | + self.logger.info("\n") |
1028 | 1025 |
|
1029 | | - if update_message: |
1030 | | - self.logger.info(update_message) |
| 1026 | + if not self.config.not_check_update: |
| 1027 | + update_message = None |
| 1028 | + if self.update_check_task and self.update_check_task.done(): |
| 1029 | + try: |
| 1030 | + update_message = self.update_check_task.result() |
| 1031 | + except (asyncio.CancelledError, Exception): |
| 1032 | + pass |
| 1033 | + if update_message: |
| 1034 | + self.logger.info(update_message) |
1031 | 1035 |
|
1032 | 1036 | self.logger.info( |
1033 | 1037 | f"\033[92m[INFO]:\033[97m Proxy is running on {self.config.host}:{self.config.port} at {datetime.now().strftime('%H:%M on %Y-%m-%d')}" |
@@ -1155,6 +1159,8 @@ def load_from_args(args) -> ProxyConfig: |
1155 | 1159 | config.no_blacklist = args.no_blacklist |
1156 | 1160 | config.auto_blacklist = args.autoblacklist |
1157 | 1161 | config.quiet = args.quiet |
| 1162 | + config.not_check_update = args.not_check_update |
| 1163 | + config.hide_banner = args.hide_banner |
1158 | 1164 | return config |
1159 | 1165 |
|
1160 | 1166 |
|
@@ -1294,6 +1300,9 @@ def parse_args(): |
1294 | 1300 | """Parse command line arguments""" |
1295 | 1301 |
|
1296 | 1302 | parser = argparse.ArgumentParser() |
| 1303 | + parser.add_argument( |
| 1304 | + "-q", "--quiet", action="store_true", help="Remove UI output" |
| 1305 | + ) |
1297 | 1306 | parser.add_argument("--host", default="127.0.0.1", help="Proxy host") |
1298 | 1307 | parser.add_argument("--port", type=int, |
1299 | 1308 | default=8881, help="Proxy port") |
@@ -1333,7 +1342,10 @@ def parse_args(): |
1333 | 1342 | "--log-error", required=False, help="Path to log file for errors" |
1334 | 1343 | ) |
1335 | 1344 | parser.add_argument( |
1336 | | - "-q", "--quiet", action="store_true", help="Remove UI output" |
| 1345 | + "--not-check-update", action="store_true", help="Do not check for updates" |
| 1346 | + ) |
| 1347 | + parser.add_argument( |
| 1348 | + "--hide-banner", action="store_true", help="Suppress printing banner" |
1337 | 1349 | ) |
1338 | 1350 |
|
1339 | 1351 | autostart_group = parser.add_mutually_exclusive_group() |
|
0 commit comments