Skip to content

Commit

Permalink
refactor model updating
Browse files Browse the repository at this point in the history
  • Loading branch information
henrygd committed Apr 2, 2024
1 parent 996cd21 commit 13001b1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
20 changes: 9 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.selectedFilePath = path
// get the file name without extension
m.selectedFileName = getFileNameFromPath(m.selectedFilePath)
// update the model
return m.Update(nil)
}
return m, cmd
}
Expand Down Expand Up @@ -166,14 +168,10 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if f, ok := form.(*huh.Form); ok {
m.form = f
}
return m, tea.Sequence(
cmd,
func() tea.Msg {
if m.form.State == huh.StateCompleted {
m.Update(nil)
}
return nil
})
if m.form.State == huh.StateCompleted {
return m.Update(nil)
}
return m, cmd
}

return m, nil
Expand All @@ -193,9 +191,9 @@ func (m Model) View() string {
return appStyle.Render(m.form.View())
}

result := "Converting to x265"
result := "Converting x265 MP4"
result += "\n" + m.x265progress.View()
result += "\n\n" + "Converting to AV1"
result += "\n\n" + "Converting AV1 WebM"
result += "\n" + m.av1progress.View()
result += "\n\n" + helpStyle.Render("Press q to quit")
return appStyle.Render(result)
Expand All @@ -220,7 +218,7 @@ func main() {
updateFlag := flag.BoolP("update", "u", false, "Update to the latest version")
flag.StringVar(&Crf, "crf", Crf, "Constant rate factor")
flag.IntVarP(&Speed, "speed", "s", Speed, fmt.Sprintf("Priority of conversion speed over quality (0-%d)", len(SpeedPresets)-1))
flag.BoolVar(&StripAudio, "strip-audio", StripAudio, "Strip audio from the video")
flag.BoolVar(&StripAudio, "strip-audio", StripAudio, "Remove audio track from output")
flag.BoolVar(&Preview, "preview", Preview, "Converts only the first 3 seconds")
flag.BoolVar(&skipX265, "skip-x265", false, "Skip x265 conversion")
flag.BoolVar(&skipAV1, "skip-av1", false, "Skip AV1 conversion")
Expand Down
31 changes: 21 additions & 10 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Terminal app to create optimized videos for the web.

## Installation

Please install / update `ffmpeg` first as this program requires it.
Please install / update `ffmpeg` first as the program requires it.

Run the command below or download the correct binary for your system on the [releases page](https://github.com/henrygd/webvids/releases).

Expand Down Expand Up @@ -51,16 +51,27 @@ Use both videos in HTML with `source` tags:
</video>
```

## Options
## Command line options

| Flag | Description |
| --------------- | ----------------------------------------- |
| `-h, --help` | Show help |
| `-v, --version` | Print version and exit |
| `-u, --update` | Update to the latest version |
| `-s, --speed` | Priority of conversion speed over quality |
| `--skip-x265` | Skip x265 conversion |
| `--skip-av1` | Skip AV1 conversion |
webvids can run without interaction by passing in a file and form options:

```bash
webvids --crf 26 --preview=false --strip-audio input.mp4
```

The following options are available:

| Flag | Description |
| ----------------- | ----------------------------------------------- |
| `--crf` | Constant rate factor |
| `-h`, `--help` | Show help |
| `--preview` | Converts only the first 3 seconds |
| `--skip-av1` | Skip AV1 conversion |
| `--skip-x265` | Skip x265 conversion |
| `-s`, `--speed` | Priority of conversion speed over quality (0-5) |
| `--strip-audio` | Remove audio track from output |
| `-u`, `--update` | Update to the latest version |
| `-v`, `--version` | Print version and exit |

## Uninstall

Expand Down

0 comments on commit 13001b1

Please sign in to comment.