Skip to content

Commit c993ad1

Browse files
authored
Merge pull request #28 from sibbl/codex/add-encoding-settings-adjustment
Add configurable AAC bitrate
2 parents 0b7e64c + 3988c43 commit c993ad1

File tree

6 files changed

+28
-8
lines changed

6 files changed

+28
-8
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,12 @@ relations.
4343

4444
You can limit how many episodes are stored per language by adjusting `episodesToKeep` in `config.mjs`. By default all episodes are kept. Uncomment the sample block in `config.mjs` and change the numbers to fit your needs:
4545

46+
You may also set `audioBitrate` to control the bitrate of the AAC files. Lower values reduce file size, e.g. `80` results in about 80 kbit/s.
47+
4648
```javascript
4749
export default {
4850
languages: ["de", "en"],
51+
// audioBitrate: 80, // encode using ~80 kbit/s AAC
4952
// episodesToKeep: {
5053
// de: 30,
5154
// en: 20

config.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
export default {
22
languages: ["de", "en"],
3+
// Uncomment the line below to adjust the AAC encoding bitrate
4+
// audioBitrate: 80,
35
// Uncomment the block below to limit how many episodes are kept per locale
46
// episodesToKeep: {
57
// de: 30, // keep the latest 30 German episodes

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "blinkist-podcast-server",
3-
"version": "1.1.2",
3+
"version": "1.1.3",
44
"description": "A Node.js server providing the daily blinks of blinkist.com as an audio podcast",
55
"main": "index.js",
66
"engines": {

src/runner.mjs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import cron from "cron";
33
import { pruneOldBooksAsync } from "./utils/storage.mjs";
44

55
export default class Runner {
6-
constructor({ languages, episodesToKeep = {}, scraperCron, scrapeParallel, headless }) {
6+
constructor({ languages, episodesToKeep = {}, scraperCron, scrapeParallel, headless, audioBitrate }) {
77
this.languages = languages;
88
this.scrapeParallel = scrapeParallel;
99
this.headless = headless;
10+
this.audioBitrate = audioBitrate;
1011
this.episodesToKeep = episodesToKeep;
1112

1213
this.cronJob = new cron.CronJob(scraperCron, () => {
@@ -31,7 +32,11 @@ export default class Runner {
3132
}
3233

3334
async singleRun(language) {
34-
const scraper = new Scraper({ language, headless: this.headless });
35+
const scraper = new Scraper({
36+
language,
37+
headless: this.headless,
38+
audioBitrate: this.audioBitrate,
39+
});
3540
await scraper.scrape();
3641
const keep = this.episodesToKeep?.[language];
3742
const limit = Number.isFinite(keep) ? keep : Infinity;

src/utils/audio.mjs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export async function getChaptersWithAudioLengthsAsync(book) {
4747
);
4848
}
4949

50-
export async function concatAudioFilesAsync(book, outFilePath) {
50+
export async function concatAudioFilesAsync(book, outFilePath, audioBitrate) {
5151
await trySetFfmpegPathsAsync();
5252
const chapterFilePaths = await Promise.all(
5353
book.chapters.map((chapter) => {
@@ -76,8 +76,13 @@ export async function concatAudioFilesAsync(book, outFilePath) {
7676
resolve();
7777
})
7878
.addOptions(["-movflags", "+faststart"])
79-
.audioCodec("aac")
80-
.mergeToFile(outFilePath);
79+
.audioCodec("aac");
80+
81+
if (audioBitrate) {
82+
proc.audioBitrate(audioBitrate);
83+
}
84+
85+
proc.mergeToFile(outFilePath);
8186
});
8287
}
8388

src/utils/scraper.mjs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ import Crawler from "./crawler.mjs";
2020
const BASE_URL = "https://www.blinkist.com";
2121

2222
export default class Scraper {
23-
constructor({ language, headless }) {
23+
constructor({ language, headless, audioBitrate }) {
2424
this.language = language;
2525
this.headless = headless;
26+
this.audioBitrate = audioBitrate;
2627
}
2728
async scrape() {
2829
console.log("Start scraping", this.language);
@@ -68,7 +69,11 @@ export default class Scraper {
6869
bookDetails.title
6970
);
7071
const concatAudioFilePath = getBookAudioRawFilePath(bookDetails.id);
71-
await concatAudioFilesAsync(bookDetails, concatAudioFilePath);
72+
await concatAudioFilesAsync(
73+
bookDetails,
74+
concatAudioFilePath,
75+
this.audioBitrate
76+
);
7277

7378
const enrichedAudioFilePath = getBookAudioFinalFilePath(bookDetails.id);
7479

0 commit comments

Comments
 (0)