mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-22 15:39:34 +00:00
convert mp4 to mp3
parent
96f93dbc8e
commit
7817ae4db0
1 changed files with 44 additions and 24 deletions
|
|
@ -40,34 +40,54 @@ Simple example of running bash scripts with help of `TerminalRun`.
|
|||
const isMp3 = (a) => /\.mp3$/.test(a);
|
||||
|
||||
export default {
|
||||
'F - Convert flac to mp3': async ({DOM, CloudCmd}) => {
|
||||
const {IO, CurrentInfo} = DOM;
|
||||
const isMp3 = (a) => /\.mp3$/.test(a);
|
||||
|
||||
const root = CloudCmd.config('root');
|
||||
const cwd = `${root}${CurrentInfo.dirPath}`;
|
||||
|
||||
const convert = 'for f in *.flac; do ffmpeg -vsync 2 -i "$f" -b:a 320k "${f%flac}mp3"; done';
|
||||
const exitCode = await CloudCmd.TerminalRun.show({
|
||||
cwd,
|
||||
command: `bash -c '${convert}'`,
|
||||
export default {
|
||||
'F - Convert flac to mp3': async ({DOM, CloudCmd}) => {
|
||||
const command = 'for f in *.flac; do ffmpeg -vsync 2 -i "$f" -b:a 320k "${f%flac}mp3"; done';
|
||||
convert(command, {
|
||||
DOM,
|
||||
CloudCmd,
|
||||
});
|
||||
},
|
||||
'M - Convert mp4 to mp3': async ({DOM, CloudCmd}) => {
|
||||
const command = 'for f in *.mp4; do ffmpeg -i "$f" "${f%mp4}mp3"; done';
|
||||
convert(command, {
|
||||
DOM,
|
||||
CloudCmd,
|
||||
});
|
||||
|
||||
if (exitCode)
|
||||
return;
|
||||
|
||||
await IO.createDirectory('/mp3');
|
||||
await CloudCmd.refresh();
|
||||
|
||||
const names = DOM.getFilenames(CurrentInfo.files);
|
||||
const mp3Names = names.filter(isMp3);
|
||||
|
||||
const from = CurrentInfo.dirPath;
|
||||
const to = `${from}mp3`
|
||||
|
||||
await IO.move(from, to, mp3Names);
|
||||
await CloudCmd.refresh();
|
||||
},
|
||||
};
|
||||
|
||||
async function convert(command, {DOM, CloudCmd}) {
|
||||
const {IO, Dialog, CurrentInfo} = DOM;
|
||||
|
||||
const root = CloudCmd.config('root');
|
||||
const cwd = `${root}${CurrentInfo.dirPath}`;
|
||||
|
||||
const exitCode = await CloudCmd.TerminalRun.show({
|
||||
cwd,
|
||||
command: `bash -c '${command}'`,
|
||||
});
|
||||
|
||||
if (exitCode === -1)
|
||||
return Dialog.alert(`☝️ Looks like Terminal is disabled, start Cloud Coammnder with '--terminal' flag.`);
|
||||
|
||||
if (exitCode)
|
||||
return Dialog.alert(`☝️ Looks like something bad happend. Exit code: ${exitCode}`);
|
||||
|
||||
await IO.createDirectory(`${cwd}/mp3`);
|
||||
await CloudCmd.refresh();
|
||||
|
||||
const names = DOM.getFilenames(CurrentInfo.files);
|
||||
const mp3Names = names.filter(isMp3);
|
||||
|
||||
const from = CurrentInfo.dirPath;
|
||||
const to = `${from}mp3`
|
||||
|
||||
await IO.move(from, to, mp3Names);
|
||||
await CloudCmd.refresh();
|
||||
}
|
||||
```
|
||||
|
||||
## Create User Menu File
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue