aria2 rpc

Post your working scripts, libraries and tools for AHK v1.1 and older
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

aria2 rpc

08 Sep 2014, 15:38

What is aria2?
aria2 is a lightweight multi-protocol & multi-source command-line download utility. It supports HTTP/HTTPS, FTP, BitTorrent and Metalink. aria2 can be manipulated via built-in JSON-RPC and XML-RPC interfaces.
How the aria2 RPC works?
Spoiler
sample.ahk
And here is a simple GUI:

(If you start aria2c with aria2c --enable-rpc --rpc-listen-all -c --rpc-secret=ahk123, you need set the --rpc-secret with ahk123 in the GUI.)

Image

Github Page

Some aria2 web frontend:
Last edited by tmplinshi on 31 Aug 2019, 23:27, edited 4 times in total.
User avatar
huyaowen
Posts: 109
Joined: 28 Jul 2014, 01:15

Re: aria2 rpc

13 Sep 2014, 06:57

ding!
hed0nist
Posts: 1
Joined: 13 Sep 2014, 15:02

Re: aria2 rpc

13 Sep 2014, 15:25

Thanks!

I am a real beginner with AHK , with no programming skill at all.
I started this afternoon with the same idea : have an interaction with aria2 using AHK script ...

Here is my code :

Code: Select all

#NoEnv
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#Persistent
#SingleInstance

If !FileExist("ahk-aria2.ini") 
{
  MsgBox, 64, ahk-aria2, Settings file ahk-aria2.ini not found , creating a new one.`nThen do not forget to enter Options in the tray menu to set them properly.
  IniWrite, 0, ahk-aria2.ini, Paths, aria2
  IniWrite, 0, ahk-aria2.ini, Paths, webui
}

IniRead, Aria2Path, ahk-aria2.ini, Paths, aria2
IniRead, WebUIPath, ahk-aria2.ini, Paths, webui

IfNotExist, %Aria2Path%
{
  MsgBox, 65, ahk-aria2, aria2c.exe not found , download available there : http://sourceforge.net/projects/aria2/files/stable/aria2-1.18.7/`n`nDo you want to get the latest stable build right now ?
  IfMsgBox OK
    MsgBox, 36, ahk-aria2, Get the x64 build ? ( answer No will let you get the x32 build )`nZip file containing the executable will be available in ahk-aria2 directory.
      IfMsgBox Yes
        UrlDownloadToFile, http://sourceforge.net/projects/aria2/files/stable/aria2-1.18.7/aria2-1.18.7-win-64bit-build1.zip/download, aria2c_win64.zip  
      IfMsgBox No
        UrlDownloadToFile, http://sourceforge.net/projects/aria2/files/stable/aria2-1.18.7/aria2-1.18.7-win-32bit-build1.zip/download, aria2c_win32.zip
}

IfNotExist, %WebUIPath%
{
  MsgBox, 36, ahk-aria2, ziahamza/webui-aria2 not found , download available there : https://github.com/ziahamza/webui-aria2`n`nDo you want to get the latest stable release right now ?`nZip file containing the webUI will be available in ahk-aria2 directory.
  IfMsgBox Yes
    UrlDownloadToFile, https://github.com/ziahamza/webui-aria2/archive/master.zip, webui.zip
}

Destination = %A_MyDocuments%
Threads = 2

Menu, Tray, NoStandard
Menu, Tray, add, Add URL, ShowMainGui
Menu, Tray, add
Menu, Tray, add, Settings, ShowSettingsGui
Menu, Tray, add, Launch Aria2, LaunchAria2
Menu, Tray, add, Close Aria2, CloseAria2
Menu, Tray, add, Launch Web-UI, LaunchWebUI
Menu, Tray, add
Menu, Tray, add, Exit, AhkAria2Close

UpdateTray_Aria2_ON()
{
  Menu, Tray, disable, Launch Aria2
  Menu, Tray, enable, Close Aria2
  Menu, Tray, enable, Launch Web-UI
}

UpdateTray_Aria2_OFF()
{
  Menu, Tray, enable, Launch Aria2
  Menu, Tray, disable, Close Aria2
  Menu, Tray, disable, Launch Web-UI
}

Process, Exist, aria2c.exe
Aria2PID = %ErrorLevel%
  
If (%Aria2PID% = 0)
{
  UpdateTray_Aria2_OFF()
}
else
{
  UpdateTray_Aria2_ON()
}

return

ShowMainGui:
{
  Gui, New
  Gui, Add, Edit, x16 y34 w410 h20 vDownloadLink gDownloadLink, Paste URL here !
  Gui, Add, DropDownList, x176 y74 w40 h10 R5 vThreads gThreads, 1|2||3|4|5|6|7|8|9|10|11|12
  Gui, Add, Radio, x26 y114 w120 h30 Group Checked gDefaultDestination, My Documents
  Gui, Add, Radio, x26 y154 w120 h30 gDestination, Open folder
  Gui, Add, DropDownList, x176 y114 w150 h10 R5 vCategory gCategory, Archives|Video|Audio|Programs|Misc
  Gui, Add, Button, x310 y150 w100 h30 gDownload, DOWNLOAD
  Gui, Add, ListBox, x6 y184 w430 h90 ReadOnly +HScroll vListBox
  Gui -Resize -MaximizeBox +MinimizeBox
  ; Generated using SmartGUI Creator for SciTE
  Gui, Show, w445 h280 , ahk-aria2
  return
}

ShowSettingsGui:
{
  Gui, New
  Gui, Add, Button, x16 y14 w400 h30 gAria2PathConfig, Aria2c
  Gui, Add, Button, x16 y94 w400 h30 gWebUIPathConfig, WebUI
  Gui, Add, Edit, x16 y54 w400 h20 ReadOnly vAria2Path
  Gui, Add, Edit, x16 y134 w400 h20 ReadOnly vWebUIPath
  ; Generated using SmartGUI Creator for SciTE
  Gui, Show, w434 h186, ahk-aria2 Settings
  IniRead, Aria2Path, ahk-aria2.ini, Paths, aria2
  IniRead, WebUIPath, ahk-aria2.ini, Paths, webui
  GuiControl,, Aria2Path, %Aria2Path%
  GuiControl,, WebUIPath, %WebUIPath%
  return
}

Aria2PathConfig:
{
  FileSelectFile, Aria2Path, 1, aria2c.exe, Select aria2c executable, (*.exe)
  GuiControl,, Aria2Path, %Aria2Path%
  IniWrite, %Aria2Path%, ahk-aria2.ini, Paths, aria2
  return
}

WebUIPathConfig:
{
  FileSelectFile, WebUIPath, 1, index.html, Select webUI startpage file, (*.html)
  GuiControl,, WebUIPath, %WebUIPath%
  IniWrite, %WebUIPath%, ahk-aria2.ini, Paths, webui
  return
}

LaunchAria2:
{
  IniRead, Aria2Path, ahk-aria2.ini, Paths, aria2
  IfNotExist, %Aria2Path% 
    { 
      MsgBox, 16, ahk-aria2, Please specify aria2 directory path `in the settings.`n 
    }
  IfExist, %Aria2Path% 
    { 
      Run, %Aria2Path% --enable-rpc --rpc-listen-all,, Min, Aria2PID
      UpdateTray_Aria2_ON()
    }
  return
}

CloseAria2:
{
  Process, Close, %Aria2PID%
  UpdateTray_Aria2_OFF()
  return
}

LaunchWebUI:
{
  IniRead, WebUIPath, ahk-aria2.ini, Paths, webui
  IfNotExist, %WebUIPath% 
    {
      MsgBox, 16, ahk-aria2, Please specify webUI directory path `in the settings.`n 
    }
  IfExist, %WebUIPath% 
    { 
      Run, %WebUIPath%,, Max
    }
  return
}

DownloadLink:
{
  Gui, Submit, NoHide
  FormatTime, Time,, HH:mm:ss 
  GuiControl,, ListBox, %Time% - Download link set to %DownloadLink%||
  return
}

Threads:
{
  Gui, Submit, NoHide
  FormatTime, Time,, HH:mm:ss 
  GuiControl,, ListBox, %Time% - Number of threads set to %Threads%||
  return
}

Destination:
{
  Gui, Submit, NoHide
  FileSelectFolder, Destination,, 3
  GuiControl,, ListBox, %Time% - Destination folder set to %Destination%||
  return
}

DefaultDestination:
{
  Gui, Submit, NoHide
  Destination = %A_MyDocuments%
  GuiControl,, ListBox, %Time% - Destination folder set to %Destination%||
  return
}

Category: 
{
  Gui, Submit, NoHide
  FormatTime, Time,, HH:mm:ss
  GuiControl,, ListBox, %Time% - Download category changed : %Category%||
  return
}

Download:
{
  IniRead, Aria2Path, ahk-aria2.ini, Paths, aria2
  If !Destination 
  { 
    MsgBox, ERROR 
  }
  ; MsgBox, %Aria2Path% -x %Threads% -d %Destination% --file-allocation=none %DownloadLink%
  Run, %Aria2Path% -x %Threads% -d %Destination% --file-allocation=none %DownloadLink%
  return
}

AhkAria2Close:
ExitApp
As you can see it is ugly. And probably there are some bugs and bad use of a lot of things.
Basically :
- Check for INI and settings , proposing the download of aria and webui if not found.
- Run in system tray , menu reachable via right-click
- Start/Close aria2 RPC and webui
- Quick URL downloader with basic options ( threads and destination folder )

But of course with my knowledge , no JSON or other libs. And there was absolutely no "output" from aria2 inside the script as your code provide ( love the progress bar and all the timers info !! )
Thanks again for sharing ! I will try to understand ( and eventually learn ) the most i can.
Will add minor features from mine to your nice piece of art.
hitman
Posts: 21
Joined: 10 Aug 2014, 06:47

Re: aria2 rpc

20 Aug 2017, 21:06

good!
brutus_skywalker
Posts: 175
Joined: 24 Dec 2016, 13:16
Location: Antarctica

Re: aria2 rpc

21 Aug 2017, 03:07

RAD!
Outsourcing Clicks & Presses Since 2004.
User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: aria2 rpc

21 Aug 2017, 19:46

I can't tell but is the code for the GUI at the end included somewhere?
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: aria2 rpc

21 Aug 2017, 23:35

@kczx3 click Download :P
ginneylover
Posts: 1
Joined: 30 Nov 2017, 07:33

Re: aria2 rpc

30 Nov 2017, 08:02

Very good. Ding!

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: Google [Bot] and 78 guests