Skip to content

Commit 3d62930

Browse files
committed
Ariang rpcHost regex pattern fixed
1 parent 9e5bf3b commit 3d62930

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

OneClickRun.ipynb

+26-22
Original file line numberDiff line numberDiff line change
@@ -1019,18 +1019,22 @@
10191019
"import urllib.request, requests\n",
10201020
"from IPython.display import HTML, clear_output\n",
10211021
"from urllib.parse import urlparse\n",
1022+
"import subprocess\n",
1023+
"import psutil\n",
10221024
"\n",
10231025
"#####################################\n",
1026+
"\n",
10241027
"USE_FREE_TOKEN = True # @param {type:\"boolean\"}\n",
10251028
"REGION = \"JP\" #@param [\"US\", \"EU\", \"AP\", \"AU\", \"SA\", \"JP\", \"IN\"]\n",
1029+
"\n",
10261030
"# Aria2 Service\n",
10271031
"Aria2_rpc = True # @param {type:\"boolean\"}\n",
10281032
"Ariang_WEBUI = True # @param {type:\"boolean\"}\n",
10291033
"TOKEN = \"\" # @param {type:\"string\"}\n",
10301034
"PORT_FORWARD = \"localhost\" #@param [\"ngrok\", \"localhost\", \"argotunnel\"]\n",
1031-
"# OUTPUT_DIR = \"\" # @param {type:\"string\"}\n",
10321035
"PORT = 8221\n",
10331036
"HOME = os.path.expanduser(\"~\")\n",
1037+
"BASE_PATH = 'tools/ariang'\n",
10341038
"\n",
10351039
"if not os.path.exists(f\"{HOME}/.ipython/ocr.py\"):\n",
10361040
" hCode = \"https://raw.githubusercontent.com/biplobsd/\" \\\n",
@@ -1049,8 +1053,6 @@
10491053
"\n",
10501054
"loadingAn()\n",
10511055
"\n",
1052-
"BASE_PATH = 'tools/ariang'\n",
1053-
"\n",
10541056
"# Ariang SETUP\n",
10551057
"runSh('apt install -y aria2')\n",
10561058
"os.makedirs(BASE_PATH, exist_ok=True)\n",
@@ -1063,12 +1065,25 @@
10631065
" htmlF = urlopen(link+\"/releases/latest\").read().decode('UTF-8')\n",
10641066
" return re.findall(r'.+\\/tag\\/([.0-9A-Za-z]+)\".+/', htmlF)[0]\n",
10651067
"\n",
1068+
"def run_process(command, shell=False, cwd=None, env=None):\n",
1069+
" for proc in psutil.process_iter():\n",
1070+
" try:\n",
1071+
" # Get process info as a named tuple containing the process name and command-line arguments\n",
1072+
" process_info = proc.as_dict(attrs=['pid', 'name', 'cmdline'])\n",
1073+
" process_cmdline = process_info['cmdline']\n",
1074+
"\n",
1075+
" # Check if the command matches the process command-line arguments\n",
1076+
" if process_cmdline == command.split():\n",
1077+
" print(\"Killing process with PID\", process_info['pid'])\n",
1078+
" proc.kill()\n",
1079+
" except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):\n",
1080+
" pass\n",
1081+
"\n",
1082+
" print(\"Starting process with command\", command)\n",
1083+
" subprocess.Popen(command, shell=shell, cwd=cwd, env=env)\n",
1084+
"\n",
10661085
"# Downloading latest version of ariang\n",
10671086
"if not os.path.exists(f\"{BASE_PATH}/index.html\"):\n",
1068-
" # BASE_URL = r\"https://github.com/mayswind/AriaNg\"\n",
1069-
" # LATEST_TAG = latestTag(BASE_URL)\n",
1070-
" # urlF = f'{BASE_URL}/releases/download/{LATEST_TAG}/' \\\n",
1071-
" # f'AriaNg-{LATEST_TAG}-AllInOne.zip'\n",
10721087
" urllib.request.urlretrieve(\n",
10731088
" findPackageR('mayswind/AriaNg', 'AllInOne.zip'),\n",
10741089
" f'{BASE_PATH}/new.zip')\n",
@@ -1080,15 +1095,7 @@
10801095
" pass\n",
10811096
"\n",
10821097
"# START_ARIANG_WEBUI_AND_ARIA2_RPC\n",
1083-
"try:\n",
1084-
" if not OUTPUT_DIR:\n",
1085-
" OUTPUT_DIR = f\"downloads/\"\n",
1086-
" elif not os.path.exists(OUTPUT_DIR):\n",
1087-
" clear_output()\n",
1088-
" print(\"Error: Your set path not found! Create path!\")\n",
1089-
" exx()\n",
1090-
"except:\n",
1091-
" OUTPUT_DIR = f\"{CWD}/downloads/\"\n",
1098+
"OUTPUT_DIR = f\"{CWD}/downloads/\"\n",
10921099
"if Aria2_rpc:\n",
10931100
" if not findProcess(\"aria2c\", \"--enable-rpc\"):\n",
10941101
" try:\n",
@@ -1137,15 +1144,12 @@
11371144
" read_data = f.read()\n",
11381145
" f.seek(0)\n",
11391146
" f.truncate(0)\n",
1140-
" read_data = re.sub(r'(rpcHost:\"\\w+.\")|rpcHost:\"\"', \n",
1141-
" f'rpcHost:\"{Host}\"', read_data)\n",
1147+
" read_data = re.sub(r'(rpcHost:\"[^\"]+.)|rpcHost:\"\"', f'rpcHost:\"{Host}\"', read_data)\n",
11421148
" read_data = re.sub(r'protocol:\"\\w+.\"', r'protocol:\"ws\"', read_data)\n",
11431149
" read_data = re.sub(r'rpcPort:\"\\d+.\"', f'rpcPort:\"{port}\"', read_data)\n",
11441150
" f.write(read_data)\n",
1145-
" try:\n",
1146-
" urllib.request.urlopen(f\"http://localhost:{PORT}\")\n",
1147-
" except:\n",
1148-
" runSh(f\"python3 -m http.server {PORT} &\", shell=True, cd=BASE_PATH)\n",
1151+
" \n",
1152+
" run_process(f\"python3 -m http.server {PORT} &\", shell=True, cwd=BASE_PATH)\n",
11491153
" \n",
11501154
" Server = PortForward_wrapper(\n",
11511155
" PORT_FORWARD, TOKEN, USE_FREE_TOKEN, [['Ariang', PORT, 'http']], REGION.lower(), \n",

0 commit comments

Comments
 (0)