Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add -re option to rename file #1265

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,23 @@ You can use the `-start`, `-end` or `-items` option to specify the download rang
-items
File lines to download. Separated by commas like: 1,5,6,8-10
```
You can use the `-re` option to rename the file with timestamp suffix:

```console
$ lux -re "https://www.bilibili.com/video/BV1KF411Z7d9/"

Site: 哔哩哔哩 bilibili.com
Title: 每一种热爱都值得全力以赴!-1692149347
Type: video
Stream:
[32-7] -------------------
Quality: 清晰 480P avc1.64001F
Size: 17.88 MiB (18753237 Bytes)
# download with: lux -f 32-7 ...

17.88 MiB / 17.88 MiB [===================================] 3.74 MiB p/s 100.00% 5.0s

```

### Resume a download

Expand Down
12 changes: 12 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"sort"
"strings"
"time"

"github.com/fatih/color"
"github.com/urfave/cli/v2"
Expand Down Expand Up @@ -152,6 +153,11 @@ func New() *cli.App {
Value: 10,
Usage: "The number of download thread (only works for multiple-parts video)",
},
&cli.BoolFlag{
Name: "rename",
Aliases: []string{"re"},
Usage: "Rename the file with timestamp suffix",
},

// Aria2
&cli.BoolFlag{
Expand Down Expand Up @@ -285,6 +291,12 @@ func download(c *cli.Context, videoURL string) error {
return err
}

if c.Bool("rename") {
for _, v := range data {
v.Title += fmt.Sprintf("-%v", time.Now().Unix())
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If more than one file is downloaded at a time, the timestamp is the same inside this loop

}
}

if c.Bool("json") {
e := json.NewEncoder(os.Stdout)
e.SetIndent("", "\t")
Expand Down