def __start_task(self, gid): aria2 = Aria2RPC() try: aria2.unpause(gid) self.msgSignal.emit("startSuccess") except: self.msgSignal.emit("startFail")
def __remove_task(self, gid): aria2 = Aria2RPC() try: aria2.remove(gid) self.msgSignal.emit("removeSuccess") except: self.msgSignal.emit("removeFail")
def __pause_task(self, gid): aria2 = Aria2RPC() try: aria2.pause(gid) self.msgSignal.emit("pauseSuccess") except: self.msgSignal.emit("pauseFail")
def download_image(referer, url, output): if not url.startswith('http'): return file_dir = os.path.dirname(output) file_name = output.split('/')[-1] rpc = Aria2RPC() options = {"dir": file_dir, "out": file_name} try: rpc.addUri([url], options=options) time.sleep(5) except Exception: parsed_url = urlparse(referer) origin = '{uri.scheme}://{uri.netloc}'.format(uri=parsed_url) headers = { 'referer': referer, 'Origin': origin, 'User-Agent': random.choice(ua) } try: # 部分域名需要关闭ssl验证 # response = requests.get(url, headers=headers, stream=True, verify=False) response = requests.get(url, headers=headers, stream=True) if response.status_code != 200: print(url + '下载失败。 ' + str(response.status_code)) return with open(output, 'wb') as f: f.write(response.content) except Exception as error: print(url + '下载失败。 ') print(error) return
def get_file_from_url(link, file_name): jsonrpc = Aria2RPC() set_dir = os.path.dirname(__file__) options = { "dir": set_dir, "out": file_name, } #print ("dir=%s"%set_dir) res = jsonrpc.addUri([link], options=options)
def __init__(self, config): self.config = config # 初始化 aria2 rpc logging.info('初始化 aria2 rpc') self.aria2Token = self.config.get('global', 'aria2Token') self.aria2Url = self.config.get('global', 'aria2Url') self.downloadDir = os.path.abspath( self.config.get('global', 'downloadDir')) self.xmlrpc = Aria2RPC(url=self.aria2Url, token=self.aria2Token) self.xmlrpcOptions = {'dir': self.downloadDir}
def __sel_task(self): aria2 = Aria2RPC() res = aria2.multicall([{ 'methodName': 'aria2.getGlobalStat' }, { 'methodName': 'aria2.tellActive' }, { 'methodName': 'aria2.tellWaiting', 'params': [0, 1000] }, { 'methodName': 'aria2.tellStopped', 'params': [0, 1000] }]) self.processSignal.emit(QVariant(res))
def download(link, filename): jsonrpc = Aria2RPC() set_dir = os.path.dirname(__file__) options = { "dir": set_dir, "out": filename, "load-cookies": 'e:\\1.txt', } try: res = jsonrpc.addUri([link], options=options) log(res) except ConnectionRefusedError: log('Aria2c is not running, try to start')
def __init__(self): self.conf = '' self.data = { "dhtport": "--dht-listen-port=6666", "btport": "--listen-port=51314", "s": "-s16", "x": "-x10", "j": "-j3", "c": "-c", "speed": "--max-download-limit=8000k", "daemon": "" } for cus in self.data: self.conf = self.conf + self.data[cus] + ' ' self.jsonrpc = Aria2RPC('http://localhost:2333/rpc') set_dir = os.path.dirname(__file__) self.options = {"dir": set_dir}
def __add_task(self, url, options, flag): aria2 = Aria2RPC() if options is None: options = {} else: options = options.toVariant() try: id = aria2.addUri([url], options=options) if flag is None: self.msgSignal.emit("addSuccess") else: self.flagMsgSignal.emit("addSuccess", flag, id) except: if flag is None: self.msgSignal.emit("addFail") else: self.flagMsgSignal.emit("addFail", flag, None)
def download_aria2(url, filename, work_path="/srv/dev-disk-by-label-cache/_download/"): if os.path.exists(work_path + "/" + filename): log.info("aria2 exists path:[%s] url:[%s] filename:[%s]", work_path, url, filename) return if not os.path.exists(work_path): log.warning("makedirs:[%s]", work_path) os.makedirs(work_path, mode=0o777, exist_ok=False) log.info("aria2down path:[%s] url:[%s] filename:[%s]", work_path, url, filename) jsonrpc = Aria2RPC(url="http://127.0.0.1:6800/rpc") options = { "dir": work_path, "out": filename, } hook_id = jsonrpc.addUri([url], options=options) log.info("aria2down path:[%s] url:[%s] filename:[%s] hookid:[%s]", work_path, url, filename, hook_id)
def __init__(self, url=Config.aria2rpc, token=Config.aria2token): self.rpc = Aria2RPC(url=url, token=token)
import os import time from pyaria2 import Aria2RPC # from pyaria2 import Jsonrpc # jsonrpc = Jsonrpc('localhost', 6800) # resp = jsonrpc.addUris('https://music.snowmusic.cc/radio/13714_1507261169_4.mp3', options={"out": "aa.mp3"}) jsonrpc = Aria2RPC() def get_file_from_url(link, file_name): set_dir = os.path.dirname(__file__) options = { "dir": set_dir, "out": file_name, } res = jsonrpc.addUri([link], options=options) def get_file_from_cmd(link): exe_path = r'D:\aria2-1.35.0-win-64bit-build1\aria2c.exe' order = exe_path + ' -s16 -x10 ' + link os.system(order) def active_task_num(): active = jsonrpc.tellActive() return len(active) def get_waitting_paths():
def __sel_task_id(self, gid): aria2 = Aria2RPC() file_state = aria2.getFiles(gid) self.taskStateSignal.emit(gid, QVariant(file_state))
def __init__(self, urls): super().__init__() self.jsonrpc = Aria2RPC() self.gid = None self.downloadUrls = urls
def __stop_aria2(self): aria2 = Aria2RPC() aria2.saveSession() if self.popen is not None: self.popen.kill() self.aria2StopedSignal.emit()
for i, s in enumerate(symbols): prefix[s] = 1 << (i + 1) * 10 for s in reversed(symbols): if n >= prefix[s]: value = float(n) / prefix[s] return '%.1f%s' % (value, s) return '%sB' % n config = GetConfig().getConfig() #查询文件 aria2Token = config.get('global', 'aria2Token') aria2Url = config.get('global', 'aria2Url') downloadDir = os.path.abspath(config.get('global', 'downloadDir')) xmlrpc = Aria2RPC(url=aria2Url, token=aria2Token) xmlrpcReturn = xmlrpc.getFiles(sys.argv[1]) fileCount = sys.argv[2] title = 'autoGetEpisodes ' + fileCount + '个文件下载完成' message = '以下文件下载完成:\n----------------------\n' for i in xmlrpcReturn: message += '[' + i[ 'index'] + ']:' + i['path'] + ' | ' + '大小:' + bytes2human( int(i['length'])) + '\n----------------------\n' mail = Pmail(config.smtpServerHost, config.smtpServerPort, config.mailFrom, config.smtpPwd) emailObj = mail.getEmailObj('AutoGetEpisodes ' + sys.argv[2] + '个文件下载完成', config.mailFrom, [config.mailTo])
#! -coding:utf8 -*- from pyaria2 import Aria2RPC import sys import os # ['/Users/csx/GitProject/snowmusic/pyaria2-jsonrpc/hook.py', 'e3f97be6d4490a5a', '1', './temp/aa.mp3'] Argv = sys.argv # 这里自己编写任意的回调函数,可以进行更新数据库等操作 def Hook(Argv): print(Argv) jsonrpc = Aria2RPC(url="http://192.168.11.11:6800/rpc") set_dir = os.path.dirname(__file__) work_path = "/srv/dev-disk-by-label-cache/_download/" file_name = 'test_2bFwkbFt.mp4' options = {"dir": work_path, "out": file_name, } link = "https://d2.xia12345.com/down/109/2020/04/2bFwkbFt.mp4" res = jsonrpc.addUri([link], options = options) print(res) resp = jsonrpc.addUri('https://music.snowmusic.cc/radio/13714_1507261169_4.mp3', options={"out": "aa.mp3"})
def get_file_from_url_by_windows(path, link, file_name): jsonrpc = Aria2RPC() options = {"dir": path, "out": file_name, } res = jsonrpc.addUri([link], options=options)
def download(url, filename): jsonrpc = Aria2RPC() set_dir = os.path.dirname(__file__) options = {"dir": set_dir, "out": filename, } res = jsonrpc.addUri([url], options=options)
def downlaod(link, file_name,save_file): jsonrpc = Aria2RPC() set_dir = save_file options = {"dir": set_dir, "out": file_name, } res = jsonrpc.addUri([link], options = options) return res #返回MD5代码
from pyaria2 import Aria2RPC rpc = Aria2RPC(url="http://localhost:6800/rpc") def download(url, route, fn): rpc.addUri([url], { "dir": route, "out": fn, })