Aria2在windows10下的配置
1、aria2
设置aira2.conf
文件
1 | #下载文件默认保存路径 |
2、aria2
开机启动设置
创建一个Start.vbs
,内容如下,将其快捷方式或者直接复制start.vbs
,放到C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp
路径下即可。1
CreateObject("wscript.shell").Run "D:\Programs\Aria2\aria2c.exe --conf-path=D:\Programs\Aria2\aria2.conf",0
或者下面的vbs
批处理命令1
2
3# currentpath = createobject("Scripting.FileSystemObject").GetFile(Wscript.ScriptFullName).ParentFolder.Path
currentpath = createobject("Scripting.FileSystemObject").GetFolder(".").Path
CreateObject("wscript.shell").Run currentpath+"\aria2c.exe --conf-path=aria2.conf",0
3、 更新trackers
批处理命令
(1)powershell
下运行新建trackersList.psl
的批处理文件,输入以下内容
1 | 'aria2.conf位置、要下载的trackers文件,在这里修改 |
【ps版本运行会出错,待解决】或者 cmd
下运行新建trackersList.bat
的批处理文件,trackersList.bat
输入以下内容1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23@echo off
:: aria2.conf位置、要下载的trackers文件,在这里修改
::set CONF_FILE=%USERPROFILE%\.aria2\aria2.conf
set CONF_FILE=E:\Aria2\aria2.conf
set TRACKER_FILE=trackers_best.txt
set DOWNLOAD_LINK=https://raw.githubusercontent.com/ngosang/trackerslist/master/%TRACKER_FILE%
::下载 trackerlist
::aria2c --dir=%TEMP% --allow-overwrite=true "%DOWNLOAD_LINK%"
aria2c --dir=%~dp0 --allow-overwrite=true "%DOWNLOAD_LINK%"
::用 sed 整理 trackerlist 格式
sed.exe -i ":a;N;s/\n/ /; ta;" %~dp0%TRACKER_FILE%
sed.exe -i "1s/^/bt-tracker=/g; s/ /,/g; s/ $//;" %~dp0%TRACKER_FILE%
::删除当前 aria2 配置 中的 trackerlist
sed.exe -i "/^bt-tracker=/d" %CONF_FILE%
type %~dp0%TRACKER_FILE% >> %CONF_FILE%
del .\sed*
del .\trackers_best.txt
①需要安装sed.exe
,安装git
,git下载地址后自带sed.exe
程序文件,安装完成后(32位路径)如:E:\Program Files\Git\usr\bin
【或者单独下载windows系统下的sed
软件,需要下载以下两个链接的文件,解压到同一文件夹,Bin
文件内的 sed.exe
和 dll
不能删除。
sed-4.2.1-bin
sed-4.2.1-dep】
②将sed.exe
加入到环境变量方法:运行
→sysdm.cpl
→高级
→环境变量
→用户环境变量里面 选中“path”
→编辑
→新建
→E:\Program Files\Git\usr\bin
参考:
Aria2 Tracker 更新脚本
Aria2 bt-tracker自动更新脚本
(2)利用python
更新
新建trackerslist.py
文件,输入以下内容1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date : 2021-06-04 15:29:54
# @Author : KY (owenyk@g.com)
# @Link : http://example.org
# @Version : $Id$
# PepTrader & PepCoder
# 一切从兴趣开始...
# It all starts with interests...
# I am PepCoder
# This is a Windows version of BT Trackers Updater via Python 3.6.6
# Original work belongs to @zmr, you can find his original work at
# 最初代码源来自于 @zmr,您可以在以下网址找到其最初的作品版本
# https://gitee.com/Zero_gitee/UpdateTrackers
# Trackers的代码源是来自于: https://github.com/XIU2/TrackersListCollection
#--------- 安装库------------#
# PS E:\Aria2> pip3 install bs4
# PS E:\Aria2> pip install lxml
# PS E:\Aria2> pip install requests
# PS E:\Aria2> pip install html5lib
#---------------------------#
import bs4
import requests
import logging
import os
import time
# 全局配置:
# url_trackers_best = "https://trackerslist.com/all.txt" # 这个是普通版的,可以用在其它BT用户端上
url_trackers_best = "https://trackerslist.com/best.txt" # 这个是aria2友好版,为aria2专门设计的
aria2_config = "D:\\Programs\\Aria2\\aria2.conf" # 设定好您的aira2所在位置,因为每个人放aria2的文件夹都不一样。
logFile = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'logger.log')
# 配置日志参数
logging.basicConfig(filename=logFile,
format="%(asctime)s \n%(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
filemode='w',
level=40)
def log(level, message):
"写日志"
logging.log(level, message)
return
def getTrackers(url):
"更新Trackers"
t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
log(logging.DEBUG, "更新Trackers【开始】{0}\n url = {1}".format(t, url))
try:
# 获取最新数据
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) '
'AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/67.0.3396.99 Safari/537.36'
}
response = requests.get(url, headers=headers).content
soup = bs4.BeautifulSoup(response, 'html5lib') # 解析
all_trackers = soup.find(name='body').get_text().replace("\n\n",",") # 复制
print(all_trackers)
log(logging.DEBUG, "更新Trackers【结束】{0}".format(all_trackers))
return all_trackers
except BaseException as e:
log(logging.ERROR, "更新Trackers【异常】{0}".format(e))
return None
def update_config(all_trackers):
"更新aria2.conf文件 bt-tracker=best_tracker"
try:
btTrackerIndex = -1
cfgList = list()
with open(aria2_config, 'r', encoding='utf8') as cfgFile:
lines = cfgFile.readlines()
cfgList = list(lines)
print(cfgList)
for line in cfgList:
if line.startswith("bt-tracker="): # 在.conf里遍历寻找这一行设置
btTrackerIndex = cfgList.index(line)
break
if btTrackerIndex >= 0:
cfgList.pop(btTrackerIndex)
if btTrackerIndex - 1 >= 0 and cfgList[btTrackerIndex - 1].startswith("#更新于"):
cfgList.pop(btTrackerIndex - 1)
btTrackerIndex = btTrackerIndex - 1
else:
btTrackerIndex = 0
cfgList.insert(btTrackerIndex, "bt-tracker="+all_trackers+"\n") # 覆盖写入更新内容
update_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
cfgList.insert(btTrackerIndex, "#更新于"+update_time+"\n")
with open("D:\\Programs\\Aria2\\aria2.conf", "w", encoding='utf8') as cfgFile: # 存储
cfgFile.writelines(cfgList)
return True
except BaseException as e:
log(logging.ERROR, "更新aria2.conf文件【异常】{0}".format(e))
return False
def reset_config():
"aria2c --conf-path=D:\Programs\Aria2\aria2.conf"
try:
os.system("aria2c.exe --conf-path=" + aria2_config)
except BaseException as e:
log(logging.ERROR, "重新载入配置文件【异常】{0}".format(e))
return False
# 配置日志输出级别
logger = logging.getLogger()
logger.setLevel(logging.ERROR)
# 开始更新操作
log(logging.DEBUG, "开始更新操作【开始】")
all_trackers = getTrackers(url_trackers_best)
update_config(all_trackers)
reset_config()
log(logging.DEBUG, "开始更新操作【结束】\n")
trackerlist的开源项目:
XIU2/TrackersListCollection