利用aria2分析并下载torrent种子

行云流水
2022-12-11 / 0 评论 / 227 阅读 / 正在检测是否收录...

前言

上一篇文章分享了如何将吃灰的旧手机改造成服务器,大功告成。就要利用起来,平时就用来下剧吧。

安装

apt inatall -y aria2

使用

下载直链

# 直链
aria2c http://xx.com/xx 

# 重命名yy
aria2c -o yy  http://xx.com/xx

# 分2线程2段下载
aria2c -s 2 -x 2 http://xx.com/xx

bt下载

# 下载整个种子
aria2c a.torrent

# 磁力链接
aria2c  '链接'

# 列出种子内容
aria2c -S a.torrent

# 下载种子内198,226,227,228的文件到指定目录
screen aria2c  -d /data/res/th  --select-file=198,226-228 a.torrent

限速

# 单文件
aria2c --max-download-limit=300K -s10 -x10 'http://xx.com/xx' 

# 整体限速
aria2c --max-overall-download-limit=300k -s10 -x10 'http://xx.com/xx' 

批量修改文件名

#导入模块
import os
import re

# 保留中文、大小写、数字
def remove_special_characters(old_s):
    # 匹配不是中文、大小写、数字的其他字符
    cop = re.compile("[^\u4e00-\u9fa5^a-z^A-Z^0-9]")
    # 将old_s中匹配到的字符替换成空s字符
    nwe_s = cop.sub('_', old_s)
    return nwe_s

#得到当前目录下所有的文件
def get_all_dir(path, sp = ""):
    filesList = os.listdir(path)

    #处理每一个文件
    sp += "-"
    for filename in filesList:
        #判断一个文件是否为目录(用绝对路径)  join拼判断接法
        if os.path.isdir(os.path.join(path, filename)):
            final_filename = remove_special_characters(filename)
            print("{}  {}||{}".format(sp, filename, final_filename))

            #重命名
            os.rename(os.path.join(path, filename), os.path.join(path, final_filename))

            #递归调用 自己调用自己
            get_all_dir(os.path.join(path, final_filename), sp)
        else:
            temp_filename, file_extension = os.path.splitext(filename)
            final_filename = remove_special_characters(temp_filename) + file_extension
            print("{}  {}||{}".format(sp, filename, final_filename))

            #重命名
            os.rename(os.path.join(path, filename), os.path.join(path, final_filename))

#等待用户确认函数
def wait_commit():
    '''
    请用户手动输入yes确认操作
    '''
    tag = input('请手动输入yes确认操作:')
    if tag == 'yes' or tag == 'y':
        return True
    else:
        return False


#主函数
if __name__ == '__main__':
    #待处理的目录
    fdir=os.getcwd()
    print('将要批量修改文件名! 目录:{}'.format(fdir))
    if wait_commit():
        get_all_dir(fdir)
    else:
        print('被拒绝,退出')

文件服务器

caddy file-server --browse --root ~/Downloads/th

FAQ

aria2c下载报错

mkdir /root/.cache/aria2/ && cd /root/.cache/aria2/
wget https://github.com/P3TERX/aria2.conf/blob/master/dht.dat

评论 (0)

取消
只有登录/注册用户才可评论