idm

package module
v0.0.0-...-d97cdf3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2020 License: MIT Imports: 10 Imported by: 1

README

idm

Golang wrapper for Internet Download Manager (IDM) CLI.

Install

To use in a go project:

go get github.com/Navid2zp/idm
Usage
package main

import (
	"fmt"
	"github.com/Navid2zp/idm"
	"time"
)

func main() {
	download, _ := idm.NewDownload("https://codeload.github.com/Navid2zp/idm/zip/master")
	// Silent mode and quit after finish
	download.Silent().QuitAfterFinish()
	// set download path
	download.SetFilePath("C:")
	// Start the download
	_ = download.Start()

	// Wait till file is appeared in the given path
	err := download.VerifyDownload(time.Second * 10)
	if err != nil {
		fmt.Println("couldn't verify file download:", err.Error())
	}
}
Parameters

Check out the IDM methods here: https://www.internetdownloadmanager.com/support/command_line.html

// Turns on the silent mode when IDM doesn't ask any questions
download.Silent()

// IDM will hang up your connection after the successful downloading
download.HangUpAfterFinish()

// IDM will exit after the successful downloading.
// This parameter works only for the first copy
download.QuitAfterFinish()

// Defines the local path where to save the file
download.SetFilePath("C:/Users/MyPC/Downloads")

// Defines local file name to save the file
download.SetFileName("myFile.zip")

// adds specified file to download queue, but don't start downloading
download.AddToQueue()

Starting the main IDM queue:

err := idm.StartMainQueue()
Verify IDM installation
installed, _ := idm.VerifyIDM()

if !installed {
    fmt.Println("Couldn't find IDM")
} else {
    fmt.Println("IDM found")
}

This package uses go-win64api'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

You can set the IDM path manually:

idm.SetIDMPath("path/to/idm.exe")
Verify download

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.

err := download.VerifyDownload(time.second * 30)

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.

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.

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DownloadFilePathNotProvidedError = errors.New("no file path is provided for download. (necessary for download verification)")

DownloadFilePathNotProvidedError represents the error when no file path is provided but one is required

View Source
var FileNameDetectionError = errors.New("file name is not specified and it doesn't exist on url header either")

FileNameDetectionError represents the error when program can't find file name in header and no local file name is provided

View Source
var FileNameHeaderError = errors.New("file name is not available in url headers")

FileNameHeaderError represents the error when the file name isn't present in url headers

View Source
var IDMNotInstalledError = errors.New("idm is not installed")

IDMNotInstalledError represents the error when idm is not installed

View Source
var IDMPathError = errors.New("failed to verify the given idm path")

IDMPathError represents the error when the given IDM path doesn't exist

View Source
var InValidURLError = errors.New("provided url is not a valid url")

InValidURLError represents the error for when the provided url is not a valid url

View Source
var URLStatusCodeError = errors.New("url didn't return status code 200")

URLStatusCodeError represents the error when url didn't return a status code 200

View Source
var WaitForDownloadTimeOutError = errors.New("file didn't appear in specified duration")

WaitForDownloadTimeOutError represents the error when time out duration is reached while waiting for a file download to be complete

Functions

func AddToQueue

func AddToQueue(url string) error

AddToQueue adds the given url to IDM queue File download won't be started

func GetIDMPath

func GetIDMPath() string

GetIDMPath returns the IDM installation path if idm is installed Returns empty string if idm isn't installed or failed to get the applications list Call VerifyIDM first if you're not sure if IDM is installed

func SetIDMPath

func SetIDMPath(path string) error

func StartMainQueue

func StartMainQueue() error

StartMainQueue starts the main queue in IDM

func VerifyIDM

func VerifyIDM() (bool, error)

VerifyIDM verifies the IDM installation on the machine

Types

type ApplicationsListError

type ApplicationsListError struct {
	// contains filtered or unexported fields
}

ApplicationsListError represents the error when program can't list the installed programs NOTE: only windows

func (*ApplicationsListError) Error

func (e *ApplicationsListError) Error() string

type Download

type Download struct {
	URL string
	// /p
	Path string
	// /f
	FileName string
	// /q
	Quit bool
	// /h
	HangUp bool
	// /n
	SilentMode bool
	// Used to extract file size and file name
	URLHeader *http.Response
}

Download represents the IDM parameters and data needed to verify download completion

func NewDownload

func NewDownload(url string) (*Download, error)

NewDownload creates a new download

func (*Download) AddToQueue

func (d *Download) AddToQueue() error

AddToQueue adds specified file to download queue, but don't start downloading Calling Start() after calling this method won't download the queued download (starts a new download in IDM).

func (*Download) GetFullPath

func (d *Download) GetFullPath() (string, error)

GetFullPath returns the full path of the file File path must be provided using SetFilePath method If file name hasn't been set, it will try to get it from url header (returns error if not available in header)

func (*Download) HangUpAfterFinish

func (d *Download) HangUpAfterFinish() *Download

HangUpAfterFinish sets the /h param IDM will hang up your connection after the successful downloading

func (*Download) QuitAfterFinish

func (d *Download) QuitAfterFinish() *Download

QuitAfterFinish sets the /q param IDM will exit after the successful downloading. This parameter works only for the first copy

func (*Download) SetFileName

func (d *Download) SetFileName(name string) *Download

SetFilePath sets the /f param Defines local file name to save the file

func (*Download) SetFilePath

func (d *Download) SetFilePath(path string) *Download

SetFilePath sets the /p param Defines the local path where to save the file

func (*Download) Silent

func (d *Download) Silent() *Download

Silent sets the /n param turns on the silent mode when IDM doesn't ask any questions

func (*Download) Start

func (d *Download) Start() error

Start starts the file download in IDM

func (*Download) VerifyDownload

func (d *Download) VerifyDownload(timeout time.Duration) error

VerifyDownload waits for download to be completed Only works if you specified the download path NOTE: File path must've been provided and file name must either be provided or be present in url header

type URLHeaderError

type URLHeaderError struct {
	// contains filtered or unexported fields
}

URLHeaderError represents the error when something goes wrong while fetching the url header

func (*URLHeaderError) Error

func (e *URLHeaderError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL