mirror of
https://github.com/Einundzwanzig-Podcast/einundzwanzig.space.git
synced 2025-12-11 15:26:50 +00:00
Episode Download Script
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,4 +1,5 @@
|
||||
/dist
|
||||
/episodes
|
||||
/generated
|
||||
/log
|
||||
/node_modules
|
||||
|
||||
@@ -24,3 +24,11 @@ npm start
|
||||
```
|
||||
|
||||
This will bring up the dev server on [localhost:3000](http://localhost:3000).
|
||||
|
||||
## Episode download
|
||||
|
||||
Download all episode mp3 and image files:
|
||||
|
||||
```bash
|
||||
EPISODES_DIR=./episodes npm run episodes
|
||||
```
|
||||
|
||||
1871
package-lock.json
generated
1871
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -17,6 +17,7 @@
|
||||
"scripts": {
|
||||
"clean": "rm -rf dist generated && mkdir -p dist generated",
|
||||
"fetch": "node tasks/fetch_feed.js",
|
||||
"episodes": "npm run fetch && mkdir -p episodes && node tasks/fetch_episodes.js",
|
||||
"copy": "cp -r static/* dist && cp node_modules/amplitudejs/dist/amplitude.min.js dist/js/player.js",
|
||||
"init": "npm-run-all clean -p fetch copy build:data",
|
||||
"start": "NODE_ENV=development npm-run-all init -p start:*",
|
||||
@@ -43,7 +44,7 @@
|
||||
"amplitudejs": "5.3.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"autoprefixer": "10.4.0",
|
||||
"autoprefixer": "10.4.1",
|
||||
"broken-link-checker": "0.7.8",
|
||||
"browser-sync": "2.27.7",
|
||||
"csso-cli": "3.0.0",
|
||||
@@ -57,18 +58,18 @@
|
||||
"node-file-rev": "1.1.4",
|
||||
"npm-run-all": "4.1.5",
|
||||
"onchange": "7.1.0",
|
||||
"postcss": "8.4.4",
|
||||
"postcss": "8.4.5",
|
||||
"postcss-calc": "8.0.0",
|
||||
"postcss-cli": "9.1.0",
|
||||
"postcss-custom-media": "8.0.0",
|
||||
"postcss-extend": "1.0.5",
|
||||
"postcss-import": "14.0.2",
|
||||
"postcss-media-variables": "2.0.1",
|
||||
"postcss-nesting": "10.0.2",
|
||||
"postcss-nesting": "10.1.1",
|
||||
"pug": "3.0.2",
|
||||
"serve": "13.0.2",
|
||||
"start-server-and-test": "1.14.0",
|
||||
"sync-request": "6.1.0",
|
||||
"xml-formatter": "2.5.1"
|
||||
"xml-formatter": "2.6.0"
|
||||
}
|
||||
}
|
||||
|
||||
31
tasks/fetch_episodes.js
Normal file
31
tasks/fetch_episodes.js
Normal file
@@ -0,0 +1,31 @@
|
||||
const { statSync, writeFileSync } = require('fs')
|
||||
const { join, resolve } = require('path')
|
||||
const request = require('sync-request')
|
||||
const episodes = require('../generated/episodes.json')
|
||||
|
||||
const dir = process.env.EPISODES_DIR || resolve(__dirname, '..', 'episodes')
|
||||
const write = (name, data) => writeFileSync(join(dir, name), data)
|
||||
const exists = filePath => {
|
||||
try {
|
||||
const stat = statSync(filePath)
|
||||
return stat.isFile() || stat.isDirectory()
|
||||
} catch (err) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
const download = (url, name) => {
|
||||
const filePath = join(dir, name)
|
||||
if (exists(filePath)) {
|
||||
console.log(`${name} already exists`)
|
||||
} else {
|
||||
console.log(`Downloading ${name}`)
|
||||
write(name, request('GET', url).getBody())
|
||||
}
|
||||
}
|
||||
|
||||
episodes.forEach(e => {
|
||||
const { slug, enclosure: { url: mp3Url }, image: imgUrl } = e
|
||||
if (mp3Url.startsWith('http')) download(mp3Url, `${slug}.mp3`)
|
||||
if (imgUrl.startsWith('http')) download(imgUrl, `${slug}.jpg`)
|
||||
})
|
||||
Reference in New Issue
Block a user