mirror of
https://github.com/IllusionMan1212/ffui.git
synced 2026-10-24 02:12:35 +00:00
WIP: listing files in chosen directory
This commit is contained in:
@@ -20,7 +20,9 @@ var checkmark = lipgloss.NewStyle().Foreground(lipgloss.Color("#22FF33")).Render
|
||||
var x = lipgloss.NewStyle().Foreground(lipgloss.Color("#FF2233")).Render("✖️")
|
||||
|
||||
const (
|
||||
Cfg Screen = iota
|
||||
None Screen = iota
|
||||
Files
|
||||
Cfg
|
||||
Main
|
||||
)
|
||||
|
||||
@@ -106,7 +108,7 @@ func (m model) updateConfigFocusedOptions() {
|
||||
}
|
||||
|
||||
func (m model) Init() tea.Cmd {
|
||||
return tea.Batch(m.Spinner.Tick, initCfg)
|
||||
return tea.Batch(m.Spinner.Tick, m.statFiles)
|
||||
}
|
||||
|
||||
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
@@ -117,9 +119,30 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
m.ErrQuitMessage = msg.msg
|
||||
m.ErrQuit = true
|
||||
return m, m.cleanUp
|
||||
case filesStatMsg:
|
||||
m.FileCount = msg.fileCount
|
||||
m.Files = msg.files
|
||||
|
||||
if len(m.Files) == 1 {
|
||||
m.Screen = Cfg
|
||||
} else if len(m.Files) > 1 {
|
||||
m.Screen = Files
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
switch m.Screen {
|
||||
case Files:
|
||||
// TODO: navigate files and select them and stuff
|
||||
switch msg := msg.(type) {
|
||||
case tea.KeyMsg:
|
||||
key := msg.String()
|
||||
switch key {
|
||||
case "ctrl+c", "esc":
|
||||
return m, tea.Quit
|
||||
}
|
||||
}
|
||||
case Cfg:
|
||||
switch msg := msg.(type) {
|
||||
case tea.KeyMsg:
|
||||
@@ -178,7 +201,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
case parsedCfgMsg:
|
||||
m.Screen = Main
|
||||
m.ParsedConfig = msg.parsedConfig
|
||||
return m, tea.Batch(m.Spinner.Tick, m.statFile)
|
||||
return m, tea.Batch(m.Spinner.Tick, startEncoding)
|
||||
}
|
||||
case Main:
|
||||
switch msg := msg.(type) {
|
||||
@@ -194,10 +217,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
return m, tea.Quit
|
||||
}
|
||||
case initUi:
|
||||
m.FileCount = msg.fileCount
|
||||
m.Files = msg.files
|
||||
|
||||
case encodingStartedMsg:
|
||||
if m.DryRun {
|
||||
return m, gracefullyQuit
|
||||
}
|
||||
@@ -274,6 +294,19 @@ func parseConfig(cfg []Config) ParsedConfig {
|
||||
}
|
||||
}
|
||||
|
||||
func FilesScreenView(m model) string {
|
||||
view := ""
|
||||
|
||||
// TODO: Create a nice view where we can select different videos and then select the encoding options and start
|
||||
// encoding.
|
||||
for _, file := range m.Files {
|
||||
view += filepath.Base(file)
|
||||
view += "\n"
|
||||
}
|
||||
|
||||
return view
|
||||
}
|
||||
|
||||
func CfgScreenView(m model) string {
|
||||
view := ""
|
||||
|
||||
@@ -393,6 +426,8 @@ func (m model) View() string {
|
||||
}
|
||||
|
||||
switch m.Screen {
|
||||
case Files:
|
||||
return FilesScreenView(m)
|
||||
case Cfg:
|
||||
return CfgScreenView(m)
|
||||
case Main:
|
||||
|
||||
@@ -25,24 +25,24 @@ type ffmpegProcessStart struct {
|
||||
cmd *exec.Cmd
|
||||
}
|
||||
|
||||
type initUi struct {
|
||||
type filesStatMsg struct {
|
||||
fileCount int
|
||||
files []string
|
||||
}
|
||||
|
||||
func (m *model) statFile() tea.Msg {
|
||||
func (m *model) statFiles() tea.Msg {
|
||||
if m.IsDirectory {
|
||||
entries, _ := os.ReadDir(m.Path)
|
||||
|
||||
sort.Sort(DirEntrySlice(entries))
|
||||
|
||||
for _, entry := range entries {
|
||||
fullFilePath := filepath.Join(m.Path, entry.Name())
|
||||
|
||||
if entry.IsDir() {
|
||||
if entry.IsDir() || !entry.Type().IsRegular() {
|
||||
continue
|
||||
}
|
||||
|
||||
fullFilePath := filepath.Join(m.Path, entry.Name())
|
||||
|
||||
mType, err := mimetype.DetectFile(fullFilePath)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@@ -55,17 +55,27 @@ func (m *model) statFile() tea.Msg {
|
||||
m.FileCount++
|
||||
m.Files = append(m.Files, fullFilePath)
|
||||
}
|
||||
|
||||
if len(m.Files) == 0 {
|
||||
return errQuitMsg{"Chosen directory has no video files"}
|
||||
}
|
||||
} else {
|
||||
m.FileCount = 1
|
||||
m.Files = append(m.Files, m.Path)
|
||||
}
|
||||
|
||||
return initUi{
|
||||
return filesStatMsg{
|
||||
fileCount: m.FileCount,
|
||||
files: m.Files,
|
||||
}
|
||||
}
|
||||
|
||||
type encodingStartedMsg struct{}
|
||||
|
||||
func startEncoding() tea.Msg {
|
||||
return encodingStartedMsg{}
|
||||
}
|
||||
|
||||
type encodeVideoMsg struct{}
|
||||
|
||||
func encodeVideo() tea.Msg {
|
||||
@@ -78,12 +88,6 @@ func gracefullyQuit() tea.Msg {
|
||||
return quitMsg{}
|
||||
}
|
||||
|
||||
type initCfgMsg struct{}
|
||||
|
||||
func initCfg() tea.Msg {
|
||||
return initCfgMsg{}
|
||||
}
|
||||
|
||||
type parsedCfgMsg struct {
|
||||
parsedConfig ParsedConfig
|
||||
dryRun bool
|
||||
@@ -117,6 +121,10 @@ type errQuitMsg struct {
|
||||
}
|
||||
|
||||
func (m *model) cleanUp() tea.Msg {
|
||||
if len(m.Files) == 0 {
|
||||
return tea.Quit()
|
||||
}
|
||||
|
||||
fullFilePath := m.Files[len(m.Files)-1]
|
||||
fileName := filepath.Base(fullFilePath)
|
||||
|
||||
@@ -124,7 +132,7 @@ func (m *model) cleanUp() tea.Msg {
|
||||
extensionIndex := strings.LastIndex(fileName, ".")
|
||||
newFileName := fileName[:extensionIndex]
|
||||
extension := fileName[extensionIndex:]
|
||||
newFileFullPath := filepath.Join(parentDir, newFileName+fmt.Sprintf(" [%s] [%s]", m.ParsedConfig.VideoEncoder, m.ParsedConfig.AudioEncoder)+extension)
|
||||
newFileFullPath := filepath.Join(parentDir, newFileName+fmt.Sprintf("_[%s]_[%s]", m.ParsedConfig.VideoEncoder, m.ParsedConfig.AudioEncoder)+extension)
|
||||
|
||||
os.Remove(newFileFullPath)
|
||||
|
||||
|
||||
@@ -92,9 +92,7 @@ func buildFFmpegCmdArgs(fullFilePath string, outFullFilePath string, cfg ParsedC
|
||||
args = append(args, cfg.AudioEncoder)
|
||||
}
|
||||
|
||||
for _, arg := range additionalArgs {
|
||||
args = append(args, arg)
|
||||
}
|
||||
args = append(args, additionalArgs...)
|
||||
|
||||
// Output file
|
||||
args = append(args, outFullFilePath)
|
||||
|
||||
Reference in New Issue
Block a user