From eefb7fce421d3504e1df6ba46c80997a27050db1 Mon Sep 17 00:00:00 2001 From: ming zhou Date: Wed, 16 Aug 2023 09:42:22 +0800 Subject: [PATCH 1/4] add `-re` option to rename file --- README.md | 17 +++++++++++++++++ app/app.go | 12 ++++++++++++ 2 files changed, 29 insertions(+) diff --git a/README.md b/README.md index 7d58a39b9..15a51d39d 100644 --- a/README.md +++ b/README.md @@ -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 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 diff --git a/app/app.go b/app/app.go index e689e7c6f..b8ae4bddf 100644 --- a/app/app.go +++ b/app/app.go @@ -7,6 +7,7 @@ import ( "os" "sort" "strings" + "time" "github.com/fatih/color" "github.com/urfave/cli/v2" @@ -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: "Avoid duplicate names causing download failures; (name-timestamp)", + }, // Aria2 &cli.BoolFlag{ @@ -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()) + } + } + if c.Bool("json") { e := json.NewEncoder(os.Stdout) e.SetIndent("", "\t") From dcec31bf29c4c668a2eae0f13e408af6aa05b4f0 Mon Sep 17 00:00:00 2001 From: ShowMaker <86963093+Snowmanazz@users.noreply.github.com> Date: Wed, 16 Aug 2023 13:55:43 +0800 Subject: [PATCH 2/4] Update README.md Co-authored-by: Xinzhao Xu --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 15a51d39d..ad5ce0c9a 100644 --- a/README.md +++ b/README.md @@ -319,7 +319,7 @@ $ lux -re "https://www.bilibili.com/video/BV1KF411Z7d9/" 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 +17.88 MiB / 17.88 MiB [===================================] 3.74 MiB p/s 100.00% 5.0s ``` From 8a1e38a184e61d4538a5cb29799244ab20f0f515 Mon Sep 17 00:00:00 2001 From: ShowMaker <86963093+Snowmanazz@users.noreply.github.com> Date: Wed, 16 Aug 2023 13:57:49 +0800 Subject: [PATCH 3/4] update rename usage Co-authored-by: Xinzhao Xu --- app/app.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/app.go b/app/app.go index b8ae4bddf..3998056af 100644 --- a/app/app.go +++ b/app/app.go @@ -156,7 +156,7 @@ func New() *cli.App { &cli.BoolFlag{ Name: "rename", Aliases: []string{"re"}, - Usage: "Avoid duplicate names causing download failures; (name-timestamp)", + Usage: "Rename the file with timestamp suffix", }, // Aria2 From 21dd33a46cf76ac86569446910b46afb42f06e31 Mon Sep 17 00:00:00 2001 From: ShowMaker <86963093+Snowmanazz@users.noreply.github.com> Date: Wed, 16 Aug 2023 13:58:08 +0800 Subject: [PATCH 4/4] Update README.md Co-authored-by: Xinzhao Xu --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ad5ce0c9a..239f08351 100644 --- a/README.md +++ b/README.md @@ -305,7 +305,7 @@ 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 file with timestamp suffix +You can use the `-re` option to rename the file with timestamp suffix: ```console $ lux -re "https://www.bilibili.com/video/BV1KF411Z7d9/"