Browse Source

expanded ideas in sayRouter et al

master
Rich Brown 4 months ago
parent
commit
9c270d8b83
6 changed files with 113 additions and 56 deletions
  1. +83
    -28
      public/index.html
  2. +1
    -1
      src/episodeCount.txt
  3. +10
    -11
      src/funcs/concatEndsToMP3.js
  4. +2
    -1
      src/funcs/deleteTempFiles.js
  5. +10
    -4
      src/funcs/sayPhrase.js
  6. +7
    -11
      src/sayRouter.js

+ 83
- 28
public/index.html View File

@@ -5,35 +5,88 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Make-a-Howard</title>
<style>
#wrap {
display: grid;
grid-template-columns: 1fr 6fr 1fr;
grid-auto-rows: max-content;
width: 100%;
min-height: 98vh;
background: #3d3d3d;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}
h1 {
grid-column: 2 / 3;
color: white;
}
form {
margin: 2rem 0;
}
#form {
grid-column: 2 / 3;
background: grey;
}
#form2 {
grid-column: 2 / 3;
background: orange;
}
#reply {
grid-column: 2 / 3;
background: white;
min-height: 2rem;
}
</style>
</head>
<body>
<form id="form" action="*">
<fieldset>
<label for="code">
<input id="code" placeholder="secret code" type="text"></input>
</label>
<label for="go">
<input type="submit" id="go">this one makes a new podcast episode</input>
</label>
</fieldset>
<p id="reply"></p>
<div id="chicken"></div>
</form>
<form id="form2" action="*">
<fieldset>
<label for="code2">
<input id="code2" placeholder="secret code" type="text"></input>
</label>
<label for="say">
<input type="submit" id="say">this one just calls daniel to 'say' what you type here: </input>
</label>
<label>
<div id="wrap">
<h1>howar'd you do that?</h1>
<form id="form" action="*">
<p>this one just makes a new podcast episode</p>
<br />
<fieldset>
<label for="code">
<input id="code" placeholder="secret code" type="text"></input>
</label>
<input type="submit" id="go"></input>
</fieldset>
</form>

<form id="form2" action="*">
<p>custom weirdness</p><br />
<fieldset>
<label for="say-text">
daniel will 'say' what you type here: <br />
</label>
<input type="text" id="say-text"></input>
</label>
</fieldset>
<p id="reply"></p>
<div id="chicken"></div>
</form>
<br />
<label for="intro">
<input type="checkbox" class="box" id="intro" name="intro" value="intro">
Add intro
</label>
<label for="outro">
<input type="checkbox" class="box" id="outro" name="outro" value="outro">
Add outro
</label>
<label for="wamps">
<input type="checkbox" class="box" id="wamps" name="wamps" value="wamps">
Add wamps
</label>
<label for="really">
<input type="checkbox" class="box" id="really" name="really" value="really">
Actually make this an episode?
</label>
<br /><br />
<label for="code2">
<input id="code2" placeholder="secret code" type="text"></input>
</label>
<label for="say">
<input type="submit" id="say"></input>
</label>
</fieldset>
</form>
<p id="reply"> </p>
</div>

<script>
const form = document.getElementById("form");
const form2 = document.getElementById("form2");
@@ -42,12 +95,14 @@
e.preventDefault();
const code2 = document.getElementById("code2").value;
const text = document.getElementById("say-text").value;
const boxes = document.getElementsByClassName("box");
const b = Array.from(boxes).map(box => box.checked ? box.value : null);
fetch("/say", {
method: "POST",
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ code: code2, string: text }),
body: JSON.stringify({ code: code2, string: text, boxes: b }),
})
.then(response => response.json())
.then(json => {
@@ -73,7 +128,7 @@
.then(response => response.json())
.then(json => {
if (json.string) {
document.getElementById("reply").innerText = json.string;
document.getElementById("reply").innerText = `created a podcast: ${json.string}`;
}
});
});


+ 1
- 1
src/episodeCount.txt View File

@@ -1 +1 @@
74
75

+ 10
- 11
src/funcs/concatEndsToMP3.js View File

@@ -2,22 +2,21 @@ import {execSync} from 'child_process';

const intro = './scratch/4pIntro.mp3';
const closingad = './scratch/adseattle.mp3';
const sting = './scratch/wampwamp.mp3';
const stinger = './scratch/wampwamp.mp3';

export default ({filename, string, concatEnds }) => new Promise((resolve, reject) => {
export default ({filename, string, ends }) => new Promise((resolve, reject) => {
// note that unlike other funcs, this one needs to resolve 3 values, not just 2.
// along with filename and string, this one must output a `fullfileMP3`
// to be used by the next func in the chain
const endsArray = ends || ["intro", "outro", "wamps"];
try {
if (!concatEnds) {
// if concatEnds is false (this is uncommon unless you're posting to the /say route), simply set all the metadata.
execSync(`ffmpeg -y -i "concat:${filename}.mp3" -metadata title="${string}" -metadata artist="Howard Chicken" -metadata album="Quotes from Howard Chicken" -hide_banner -loglevel panic -acodec copy ${filename}POSTCONCAT.mp3`);
resolve({filename, string, fullfileMP3: `${filename}POSTCONCAT.mp3`});
} else {
// if concatEnds is true (this is the default on /go, and NOT the default on /say), chain together the intro, the main file, the closing ad, then the sting, then add metadata
execSync(`ffmpeg -y -i "concat:${intro}|${filename}.mp3|${closingad}|${sting}" -metadata title="${string}" -metadata artist="Howard Chicken" -metadata album="Quotes from Howard Chicken" -hide_banner -loglevel panic -acodec copy ${filename}POSTCONCAT.mp3`);
resolve({filename, string, fullfileMP3: `${filename}POSTCONCAT.mp3`});
}
let concatCommand = "concat:";
if (endsArray.includes("intro")) concatCommand += `${intro}|`;
concatCommand += `${filename}.mp3`;
if (endsArray.includes("outro")) concatCommand += `|${closingad}`;
if (endsArray.includes("wamps")) concatCommand += `|${stinger}`;
execSync(`ffmpeg -y -i "${concatCommand}" -metadata title="${string}" -metadata artist="Howard Chicken" -metadata album="Quotes from Howard Chicken" -hide_banner -loglevel panic -acodec copy ${filename}POSTCONCAT.mp3`);
resolve({filename, string, fullfileMP3: `${filename}POSTCONCAT.mp3`});
}
catch(e) {
console.log(e)


+ 2
- 1
src/funcs/deleteTempFiles.js View File

@@ -10,6 +10,7 @@ export default ({ filename, string }) => new Promise((resolve, reject) => {
resolve({ filename, string})
}
catch {
reject("error deleting TXT, AAC, MP3 (x2) and/or MD files in /phrases subdir")
console.log("error deleting something in /phrases subdir.");
resolve({ filename, string})
}
});

+ 10
- 4
src/funcs/sayPhrase.js View File

@@ -2,25 +2,31 @@ import savePhraseAsText from "./savePhraseAsText.js";
import saveTextAsAudio from "./saveTextAsAudio.js";
import convertAACtoMP3 from "./convertAACtoMP3.js";
import concatEndsToMP3 from "./concatEndsToMP3.js";
import convertToMd from "./convertToMd.js";
import publishMdtoGithub from "./publishMdtoGithub.js";
import deleteTempFiles from "./deleteTempFiles.js";
import saveMP3toFileserver from "./saveMP3toFileserver.js";
import isProd from "./isProd";

const doAll = ({ phrase, concatEnds }) => {
const makePodcast = array => array.includes("really");

const doAll = ({ phrase, ends }) => {
const string = phrase;
return savePhraseAsText(string)
.then(({filename, string}) => saveTextAsAudio({filename, string}))
.then(({filename, string}) => convertAACtoMP3({filename, string}))
.then(({filename, string}) => concatEndsToMP3({filename, string, concatEnds}))
.then(({filename, string}) => concatEndsToMP3({filename, string, ends}))
.then(({filename, string, fullfileMP3}) => makePodcast(ends) ? convertToMd({ filename, string, fullfileMP3 }) : { filename, string })
.then(({filename, string}) => makePodcast(ends) ? publishMdtoGithub({ filename, string}) : {filename, string })
.then(({filename, string}) => saveMP3toFileserver({ filename, string}))
.then(({filename, string}) => isProd ? deleteTempFiles({ filename, string }) : {filename, string})
.then(result => result)
.catch(e => console.log(e));
}

export default ({phrase, concatEnds}) => new Promise(async (resolve, reject) => {
export default ({phrase, ends}) => new Promise(async (resolve, reject) => {
try {
resolve(doAll({phrase, concatEnds}));
resolve(doAll({phrase, ends}));
} catch(e) {
reject(new Error(e));
}


+ 7
- 11
src/sayRouter.js View File

@@ -10,21 +10,17 @@ const sayRouter = express.Router();
{
code: "a string with the code from the .env file",
string: "A string to be read by Daniel",
ends: false
boxes: an array, for now. ["intro", "outro", "wamps"] or nulls in their place
}
* ends is optional, defaults to false. If sent in and set to true
* the returned file will have intro and ad wrapped around the string
* being read by Daniel
*
* */
sayRouter.use("/", (req, res) => {
if (req.body && req.body.code && req.body.code === process.env.CODE) {
const phr = req.body && req.body.string ? req.body.string : "Just Daniel here.";
const ends = req.body && req.body.ends ? req.body.ends : false;
return sayPhrase({phrase: phr, concatEnds: ends})
.then(file => {
console.log(file);
const filename = file.filename.replace('./phrases/', '');
const phrase = req.body && req.body.string ? req.body.string : "Just Daniel here.";
const ends = req.body && req.body.boxes ? req.body.boxes : [null, null, null, null];
return sayPhrase({phrase, ends})
.then(result => {
console.log(result);
const filename = result.filename.replace('./phrases/', '');
return res.json({ filename: `https://www.porknachos.com/files/podcasts/howard/${filename}.mp3`});
})
.catch(e => console.log(e))


Loading…
Cancel
Save