當前位置:
首頁 >
用Python3在Win10上自动更新Aria2的BT Trackers,提升Aria2的BT下载速度,非常实用。
發布時間:2023/12/10
53
豆豆
生活随笔
收集整理的這篇文章主要介紹了
用Python3在Win10上自动更新Aria2的BT Trackers,提升Aria2的BT下载速度,非常实用。
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
# 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/TrackersListCollectionimport bs4
import requests
import logging
import os
import time# 全局配置:
# url_trackers_best = "https://trackerslist.com/all.txt" # 這個是普通版的,可以用在其它BT用戶端上
url_trackers_best = "https://trackerslist.com/all_aria2.txt" # 這個是aria2友好版,為aria2專門設計的
aria2_config = "D:\\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)returndef 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).contentsoup = bs4.BeautifulSoup(response, 'html5lib') # 解析all_trackers = soup.find(name='body').get_text() # 復制print(all_trackers)log(logging.DEBUG, "更新Trackers【結束】{0}".format(all_trackers))return all_trackersexcept BaseException as e:log(logging.ERROR, "更新Trackers【異?!縶0}".format(e))return Nonedef update_config(all_trackers):"更新aria2.conf文件 bt-tracker=all_trackers"try:btTrackerIndex = -1cfgList = 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)breakif btTrackerIndex >= 0:cfgList.pop(btTrackerIndex)if btTrackerIndex - 1 >= 0 and cfgList[btTrackerIndex - 1].startswith("#更新于"):cfgList.pop(btTrackerIndex - 1)btTrackerIndex = btTrackerIndex - 1else:btTrackerIndex = 0cfgList.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:\\aria2\\aria2.conf", "w", encoding='utf8') as cfgFile: # 存儲cfgFile.writelines(cfgList)return Trueexcept BaseException as e:log(logging.ERROR, "更新aria2.conf文件【異?!縶0}".format(e))return Falsedef reset_config():"aria2c --conf-path=D:\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")
這是更新后的aria2.conf文件的效果,我上次更新是在2020年2月18日。
### BT/PT Setting bt-enable-lpd=true bt-max-peers=999 follow-torrent=true listen-port=51413 enable-dht=true enable-dht6=false enable-peer-exchange=true bt-seed-unverified=true rpc-save-upload-metadata=true bt-hash-check-seed=true bt-remove-unselected-file bt-request-peer-speed-limit=512K bt-tracker-connect-timeout=90 bt-tracker-interval=60 be-tracker-timeout=120 seed-ratio=2 seed-time=720 bt-stop-timeout=10800#更新于2020-02-18 14:04:37 bt-tracker=http://104.**.198.**:8000/announce,…(此處省略百萬字)…,udp://z0y.x:1337/announce這樣就可以提升aria2的bt下載速度啦,Considerably!
總結
以上是生活随笔為你收集整理的用Python3在Win10上自动更新Aria2的BT Trackers,提升Aria2的BT下载速度,非常实用。的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql获取离当前数据最近的数据_My
- 下一篇: RHEL 集群(RHCS)配置小记 --