|
1 | 1 | # idm
|
| 2 | +Golang wrapper for Internet Download Manager (IDM) CLI. |
| 3 | + |
| 4 | +### Install |
| 5 | + |
| 6 | +To use in a go project: |
| 7 | +``` |
| 8 | +go get github.com/Navid2zp/idm |
| 9 | +``` |
| 10 | + |
| 11 | +### Usage |
| 12 | + |
| 13 | +```go |
| 14 | +package main |
| 15 | + |
| 16 | +import ( |
| 17 | + "fmt" |
| 18 | + "github.com/Navid2zp/idm" |
| 19 | + "time" |
| 20 | +) |
| 21 | + |
| 22 | +func main() { |
| 23 | + download, _ := idm.NewDownload("https://codeload.github.com/Navid2zp/idm/zip/master") |
| 24 | + // Silent mode and quit after finish |
| 25 | + download.Silent().QuitAfterFinish() |
| 26 | + // set download path |
| 27 | + download.SetFilePath("C:") |
| 28 | + // Start the download |
| 29 | + _ = download.Start() |
| 30 | + |
| 31 | + // Wait till file is appeared in the given path |
| 32 | + err := download.VerifyDownload(time.Second * 10) |
| 33 | + if err != nil { |
| 34 | + fmt.Println("couldn't verify file download:", err.Error()) |
| 35 | + } |
| 36 | +} |
| 37 | +``` |
| 38 | + |
| 39 | +#### Parameters |
| 40 | +Check out the IDM methods here: https://www.internetdownloadmanager.com/support/command_line.html |
| 41 | + |
| 42 | +```go |
| 43 | +// Turns on the silent mode when IDM doesn't ask any questions |
| 44 | +download.Silent() |
| 45 | + |
| 46 | +// IDM will hang up your connection after the successful downloading |
| 47 | +download.HangUpAfterFinish() |
| 48 | + |
| 49 | +// IDM will exit after the successful downloading. |
| 50 | +// This parameter works only for the first copy |
| 51 | +download.QuitAfterFinish() |
| 52 | + |
| 53 | +// Defines the local path where to save the file |
| 54 | +download.SetFilePath("C:/Users/MyPC/Downloads") |
| 55 | + |
| 56 | +// Defines local file name to save the file |
| 57 | +download.SetFileName("myFile.zip") |
| 58 | + |
| 59 | +// adds specified file to download queue, but don't start downloading |
| 60 | +download.AddToQueue() |
| 61 | +``` |
| 62 | + |
| 63 | +**Starting the main IDM queue:** |
| 64 | + |
| 65 | +```go |
| 66 | +err := idm.StartMainQueue() |
| 67 | +``` |
| 68 | + |
| 69 | +##### Verify IDM installation |
| 70 | + |
| 71 | +```go |
| 72 | +installed, _ := idm.VerifyIDM() |
| 73 | + |
| 74 | +if !installed { |
| 75 | + fmt.Println("Couldn't find IDM") |
| 76 | +} else { |
| 77 | + fmt.Println("IDM found") |
| 78 | +} |
| 79 | +``` |
| 80 | + |
| 81 | +This package uses [go-win64api][1]'s `InstalledSoftwareList` method to list all the installed applications and checks if IDM is present. Then it will try to find it's path. It fails to verify IDM if `IDMan.exe` won't be present in the same directory as `Uninstall.exe` |
| 82 | + |
| 83 | +You can set the IDM path manually: |
| 84 | + |
| 85 | +```go |
| 86 | +idm.SetIDMPath("path/to/idm.exe") |
| 87 | +``` |
| 88 | + |
| 89 | + |
| 90 | +##### Verify download |
| 91 | + |
| 92 | +There is no way to be sure if a download is completed or not since we can't actually control the IDM. The closest way to check if a download is finished is by checking the download path and look for the file. |
| 93 | + |
| 94 | +```go |
| 95 | +err := download.VerifyDownload(time.second * 30) |
| 96 | +``` |
| 97 | + |
| 98 | +**NOTE:** You have to specify download path using `SetFilePath` method to use this option. Also I recommend setting the file name using `SetFileName` method to make sure that we know where the file is to verify it. |
| 99 | + |
| 100 | +If filename isn't specified, program will try to find it from URL header which might not be available or be different than what IDM chooses causing this method to fail the verification. |
| 101 | + |
| 102 | + |
| 103 | +License |
| 104 | +---- |
| 105 | + |
| 106 | +[MIT][2] |
| 107 | + |
| 108 | +[1]: https://github.com/iamacarpet/go-win64api |
| 109 | +[2]: https://github.com/Navid2zp/idm/blob/master/LICENSE |
0 commit comments