Skip to content

Commit

Permalink
feat: add skip-on-error flag
Browse files Browse the repository at this point in the history
  • Loading branch information
hareku committed Oct 25, 2024
1 parent b49dd54 commit fb62ee7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ The latest binary can be downloaded [here](https://github.com/hareku/fanbox-dl/r
| dir-by-post | Separates content saved into directories based on the title of the post. <br>Stored inside the plan directory when accompanied by the `dir-by-plan` flag. | `--dir-by-post` | `false` |
| all | Will ensure that all content is downloaded from creators. <br>Will also redownload content that might already be present locally. | `--all` | `false` |
| skip-files | Will skip downloading non-image files from creators. | `--skip-files` | `false` |
| skip-on-error | Will skip downloading instead of exiting when an error occurs. | `--skip-on-error` | `false` |
| dry-run | Will skip downloading all content from creators. | `--dry-run` | `false` |
| verbose | Gives more detailed information about commands being executed by the application. <br>Useful for debugging errors. | `--verbose` | `false` |
| save-dir | Root directory to save content. <br>Put directory in double quotes `"` if it contains spaces. <br> Supports relative and absolute directories. | `--savedir ./content` | `./images` |
Expand Down
7 changes: 7 additions & 0 deletions cmd/fanbox-dl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ var verboseFlag = &cli.BoolFlag{
Value: false,
Usage: "Whether to output debug logs.",
}
var skipOnErrorFlag = &cli.BoolFlag{
Name: "skip-on-error",
Value: false,
Usage: "Whether to skip downloading instead of exiting when an error occurred.",
}

var app = &cli.App{
Name: "fanbox-dl",
Expand All @@ -118,6 +123,7 @@ var app = &cli.App{
skipFiles,
dryRunFlag,
verboseFlag,
skipOnErrorFlag,
},
Action: func(c *cli.Context) error {
logger := fanbox.NewLogger(&fanbox.NewLoggerInput{
Expand Down Expand Up @@ -148,6 +154,7 @@ var app = &cli.App{
CheckAllPosts: c.Bool(allFlag.Name),
DryRun: c.Bool(dryRunFlag.Name),
SkipFiles: c.Bool(skipFiles.Name),
SkipOnError: c.Bool(skipOnErrorFlag.Name),
OfficialAPIClient: api,
Storage: &fanbox.LocalStorage{
SaveDir: c.String(saveDirFlag.Name),
Expand Down
8 changes: 6 additions & 2 deletions pkg/fanbox/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Client struct {
CheckAllPosts bool
DryRun bool
SkipFiles bool
SkipOnError bool
OfficialAPIClient *OfficialAPIClient
Storage *LocalStorage
Logger *Logger
Expand Down Expand Up @@ -109,8 +110,11 @@ func (c *Client) Run(ctx context.Context, creatorID string) error {

c.Logger.Infof("Downloading %dth %s of %s\n", order, assetType, post.Title)
if err := c.downloadWithRetry(ctx, post, order, d); err != nil {
c.Logger.Errorf("Download error; skipping file. %s", err.Error())
continue
if c.SkipOnError {
c.Logger.Errorf("Skip downloading, because of an error: %s", err.Error())
continue
}
return fmt.Errorf("download: %w", err)
}
}
}
Expand Down

0 comments on commit fb62ee7

Please sign in to comment.