Skip to content

Commit 5c12007

Browse files
committed
Update to megatools 1.11.0
1 parent 7e820f4 commit 5c12007

File tree

3 files changed

+30
-17
lines changed

3 files changed

+30
-17
lines changed

PKGBUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Maintainer: Benjamin Lopez <contact@scotow.com>
22

33
pkgname=mego
4-
pkgver=1.2.1
4+
pkgver=1.3.0
55
pkgrel=1
66
pkgdesc="A simple megadl wrapper with auto-retry and download list"
77
arch=('x86_64')

README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,41 @@
11
# mego 💾
22

3-
Mego is a simple [megatools](https://github.com/megous/megatools) command wrapper, allowing you to use the `megadl` command with a download list of links and add an auto-try tool.
3+
Mego is a simple [megatools](https://megatools.megous.com) command wrapper, allowing you to use the `megatools dl` command with a download list of links and add an auto-try tool.
44

55
### Ideas
66

77
Megatools is a collection of programs for accessing Mega.nz service from a command line of your desktop or server.
88

99
#### Auto-retry
1010

11-
While using the `megadl` command to download a bunch of large files, I often found myself being blocked by Mega because I exceeded the bandwidth limit (aka. error 509).
11+
While using the `megatools dl` command to download a bunch of large files, I often found myself being blocked by Mega because I exceeded the bandwidth limit (aka. error 509).
1212

1313
Indeed, Mega allows users to download a few (apparently not fixed) number of GB per day (once again, apparently not fixed).
1414

15-
By default `megadl` only retries 3 times when this error occurred, preventing the download of file during the night or while being away from the computer. To fix this problem, `mego` check the error code returned by `megadl`, and retry if the command failed.
15+
By default `megatools dl` only retries 3 times when this error occurred, preventing the download of file during the night or while being away from the computer. To fix this problem, `mego` check the error code returned by `megatools dl`, and retry if the command failed.
1616

1717
#### List of files
1818

19-
Another problem that I found while using `megadl` is the lack of options to download multiple files at once, and keeping track of the done ones.
19+
Another problem that I found while using `megatools dl` is the lack of options to download multiple files at once, and keeping track of the done ones.
2020

2121
To solve this problem, `mego` accepts as arguments a path of file(s) containing a list of Mega download links. `mego` will open the file and start downloading the files listed in it. Once the download of the file successfully terminated, `mego` will add a `#` before the link and write it in the file, preventing the next execution to re-download the file. `mego` will also mark invalid links it found with the `#-` string.
2222

2323
#### Compatibility
2424

25-
Because this script is a wrapper around the `megadl` command, it heavily depends on the outputs of the command. If you have problems using this script, be sure to use the version 1.10.2 of `megatools`.
25+
Because this script is a wrapper around the `megatools` command, it heavily depends on the outputs of the command. If you have problems using this script, be sure to use the version 1.11.0 (04.04.20) of `megatools`. You can download the latest version [here](https://megatools.megous.com/builds/experimental/).
2626

2727
### Usage
2828

2929
```
3030
Usage of mego:
3131
32-
mego [-l SPEED] [-r DURATION] [-p] MEGA_LINK... LIST_PATH...
32+
mego [-c COMMAND_PATH] [-s SPEED] [-p] [-r INTERVAL] LINK... LINK_PATH...
3333
34-
-l uint speed limit passed to megadl as --limit-speed
35-
-r duration interval between two retries (default 1m0s)
36-
-p pipe megadl's stdout and stderr
34+
Application Options:
35+
-s, --speed-limit=SPEED Speed limit passed to megatools dl as --limit-speed (default: 0)
36+
-p, --pipe-outputs Pipe megatools's stdout and stderr
37+
-r, --retry=INTERVAL Interval between two retries (default: 15min)
38+
-c, --command=COMMAND_PATH Path to the megatools command (default: megatools)
3739
```
3840

3941
NB: The whole content of a *list file* is read and kept in memory. Every time a file is downloaded, the content of the *list file* will be overwritten. So please do not use a *list file* as a queue during execution.

mego.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ import (
1616
)
1717

1818
type options struct {
19-
Speed uint `short:"s" long:"speed-limit" description:"Speed limit passed to megadl as --limit-speed" default:"0" value-name:"SPEED"`
20-
Pipe bool `short:"p" long:"pipe-outputs" description:"Pipe megadl's stdout and stderr"`
21-
Retry time.Duration `short:"r" long:"retry" description:"Interval between two retries" default:"15min" value-name:"INTERVAL"`
19+
Speed uint `short:"s" long:"speed-limit" description:"Speed limit passed to megatools dl as --limit-speed" default:"0" value-name:"SPEED"`
20+
Pipe bool `short:"p" long:"pipe-outputs" description:"Pipe megatools's stdout and stderr"`
21+
Retry time.Duration `short:"r" long:"retry" description:"Interval between two retries" default:"15min" value-name:"INTERVAL"`
22+
CommandPath string `short:"c" long:"command" description:"Path to the megatools command" default:"megatools" value-name:"COMMAND_PATH"`
2223
}
2324

2425
var (
2526
opts options
26-
linkRegex = regexp.MustCompile(`^(?:https?://)?mega\.nz/#.+$`)
27+
linkRegex = regexp.MustCompile(`^(?:https?://)?mega\.nz/(?:(?:file|folder).+)?#.+$`)
2728
)
2829

2930
var (
@@ -40,7 +41,7 @@ func isAlreadyDownloadedError(line, link string) bool {
4041
return true
4142
}
4243
// Typo in the original program.
43-
if strings.HasPrefix(line, fmt.Sprintf("ERROR: Download failed for '%s': Can't rename donwloaded temporary file ", link)) {
44+
if strings.HasPrefix(line, fmt.Sprintf("ERROR: Download failed for '%s': Local file already exists:", link)) {
4445
return true
4546
}
4647
return false
@@ -56,7 +57,7 @@ func downloadRepeat(link string) {
5657
}
5758

5859
func downloadCommand(link string) bool {
59-
cmd := exec.Command("megadl", fmt.Sprintf("--limit-speed=%d", opts.Speed), link)
60+
cmd := exec.Command(opts.CommandPath, "dl", fmt.Sprintf("--limit-speed=%d", opts.Speed), link)
6061

6162
var errBuff bytes.Buffer
6263
if opts.Pipe {
@@ -131,9 +132,14 @@ func writeFilesList(path string, links []string) {
131132
}
132133
}
133134

135+
func commandExists(cmd string) bool {
136+
_, err := exec.LookPath(cmd)
137+
return err == nil
138+
}
139+
134140
func main() {
135141
parser := flags.NewParser(&opts, flags.Default)
136-
parser.Usage = "[-s SPEED] [-p] [-r INTERVAL] LINK... LINK_PATH..."
142+
parser.Usage = "[-c COMMAND_PATH] [-s SPEED] [-p] [-r INTERVAL] LINK... LINK_PATH..."
137143

138144
args, err := parser.Parse()
139145
if err != nil {
@@ -149,6 +155,11 @@ func main() {
149155
os.Exit(1)
150156
}
151157

158+
if !commandExists(opts.CommandPath) {
159+
errLogger.Printf("Cannot find command \"%s\".\n", opts.CommandPath)
160+
os.Exit(1)
161+
}
162+
152163
for _, arg := range args {
153164
if isValidLink(arg) {
154165
downloadRepeat(arg)

0 commit comments

Comments
 (0)