Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
opening ceremonies to MP3
Browse files Browse the repository at this point in the history
  • Loading branch information
wslyvh committed Feb 14, 2023
1 parent 6d316f3 commit c34cc67
Show file tree
Hide file tree
Showing 21 changed files with 4,081 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"extends": ["plugin:@typescript-eslint/recommended", "prettier"],
"plugins": ["prettier"],
"rules": {
"prettier/prettier": ["error"]
},
"env": {
"node": true
}
}
39 changes: 39 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/.next/
/out/
/build
/dist

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# local env files
.env
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
7 changes: 7 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"trailingComma": "es5",
"semi": false,
"singleQuote": true,
"printWidth": 150,
"bracketSameLine": true
}
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["esbenp.prettier-vscode"]
}
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
Binary file added output/mp3/opening-ceremonies-aya.mp3
Binary file not shown.
Binary file added output/mp3/opening-ceremonies-carl.mp3
Binary file not shown.
Binary file added output/mp3/opening-ceremonies-danny.mp3
Binary file not shown.
Binary file added output/mp3/opening-ceremonies-intro.mp3
Binary file not shown.
Binary file added output/mp3/opening-ceremonies-jonathan.mp3
Binary file not shown.
Binary file added output/mp3/opening-ceremonies-tim.mp3
Binary file not shown.
Binary file added output/mp3/opening-ceremonies-vitalik.mp3
Binary file not shown.
76 changes: 76 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"name": "media-tools",
"description": "Tools to manage our events' media, streaming, recording and archiving ",
"version": "0.1.0",
"license": "MIT",
"scripts": {
"build": "tsc",
"start": "NODE_PATH=./dist node ./dist/index",
"dev": "nodemon ./src/index.ts",
"test": "NODE_ENV=test jest --detectOpenHandles --watchAll --no-cache",
"test:coverage": "NODE_ENV=test jest --coverage --detectOpenHandles --no-cache",
"lint": "eslint --fix",
"prettier": "prettier './src' --write",
"run:mp3": "nodemon ./src/mp3.ts",
"run:mp3-opening": "nodemon ./src/mp3-opening.ts"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"./src": [
"lint",
"prettier"
]
},
"jest": {
"preset": "ts-jest",
"testEnvironment": "node",
"rootDir": "./src",
"coverageDirectory": "../coverage",
"moduleDirectories": [
"node_modules",
"src"
],
"moduleFileExtensions": [
"js",
"ts"
]
},
"dependencies": {
"@ethersproject/providers": "^5.7.1",
"@types/fluent-ffmpeg": "^2.1.20",
"cross-fetch": "^3.1.5",
"dayjs": "^1.11.7",
"dotenv": "^16.0.3",
"ethereum-blockies-base64": "^1.0.2",
"fluent-ffmpeg": "^2.1.2",
"gray-matter": "^4.0.3",
"markdown-it": "^13.0.1",
"slugify": "^1.6.5",
"ytdl-core": "^4.11.2"
},
"devDependencies": {
"@tsconfig/recommended": "^1.0.2",
"@types/dotenv": "^8.2.0",
"@types/jest": "^29.2.5",
"@types/markdown-it": "^12.2.3",
"@types/node": "^18.11.18",
"@typescript-eslint/eslint-plugin": "^5.48.2",
"@typescript-eslint/parser": "^5.48.2",
"eslint": "8.23.1",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-prettier": "^4.2.1",
"husky": "^8.0.3",
"jest": "^29.3.1",
"lint-staged": "^13.1.0",
"nodemon": "^2.0.20",
"prettier": "^2.8.3",
"ts-jest": "^29.0.5",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.1.2",
"typescript": "^4.9.4"
}
}
13 changes: 13 additions & 0 deletions src/actions/ffmpeg.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import ffmpeg from 'fluent-ffmpeg'
import { Readable } from 'stream'
import { CONFIG } from 'utils/config'

export async function ToMp3(id: string, stream: Readable, bitrate = CONFIG.BITRATE) {
console.log('Convert to mp3', id)

try {
ffmpeg(stream).audioBitrate(bitrate).format('mp3').save(`${CONFIG.OUTPUT_FOLDER}/mp3/${id}.mp3`).on('error', console.error)
} catch (error) {
console.log('Unable to convert to mp3', id, error)
}
}
26 changes: 26 additions & 0 deletions src/actions/youtube.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import ytdl from 'ytdl-core'

export async function GetVideoInfo(id: string) {
console.log('Get YouTube video info', id)
return await ytdl.getInfo(id)
}

export async function GetVideoStream(id: string, quality: 'highestvideo' | 'highestaudio' = 'highestvideo') {
console.log('Get YouTube video stream', id)

try {
return ytdl(id, {
quality: quality,
})
} catch (e) {
console.log('Unable to fetch video stream', id, e)
}
}

export async function UpdateMetadata(id: string, session: any) {
console.log('Update YouTube metadata for', id)
}

export async function UploadThumbnail(id: string, thumbnail: string) {
console.log('Upload YouTube thumbnail for', id)
}
9 changes: 9 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { CONFIG } from 'utils/config'

console.log('Running in', CONFIG.NODE_ENV, 'mode')

Run()

async function Run() {
process.exit(0)
}
25 changes: 25 additions & 0 deletions src/mp3-opening.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ToMp3 } from 'actions/ffmpeg'
import { GetVideoStream } from 'actions/youtube'
import { GetSessions } from 'sources/api'
import { CONFIG } from 'utils/config'

console.log('Running in', CONFIG.NODE_ENV, 'mode')

Run()

async function Run() {
const sessions = await GetSessions()
const opening = ['UihMqcj-cqc', 'noXPewi5qOk', 'GGXveC7dn7o', 'iF6_JMf6CDM', 'ql082HLTndA', 'xUAbw3QhP5c', '1C5W7iCLDPY']

opening.forEach(async (s) => {
const session = sessions.find((i: any) => i.sources_youtubeId === s)
if (!session) return
// if (session.sources_youtubeId === 'xjEK8PrH9kQ' || session.sources_youtubeId === 'FS9PPDSK6wc' || session.sources_youtubeId === 'okaoDabqt_E') return

const stream = await GetVideoStream(s, 'highestaudio')
if (!stream) return

await ToMp3(session.id, stream)
await new Promise((r) => setTimeout(r, 1000))
})
}
8 changes: 8 additions & 0 deletions src/sources/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import fetch from 'cross-fetch'

export async function GetSessions() {
console.log('Fetching sessions from Devcon API')
const response = await fetch('https://devcon-api.onrender.com/sessions/')
const result = await response.json()
return result.data
}
13 changes: 13 additions & 0 deletions src/utils/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { join } from 'path'
import dotenv from 'dotenv'

dotenv.config()

export const CONFIG = {
NODE_ENV: process.env.NODE_ENV || 'development',

OUTPUT_FOLDER: process.env.OUTPUT_FOLDER || join(process.cwd(), 'output'),
BITRATE: process.env.BITRATE || 128,

GITHUB_TOKEN: process.env.GITHUB_TOKEN,
}
15 changes: 15 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "@tsconfig/recommended/tsconfig.json",
"compilerOptions": {
"target": "ES2017",
"resolveJsonModule": true,
"isolatedModules": false,
"outDir": "dist",
"baseUrl": "./src"
},
"ts-node": {
"require": ["tsconfig-paths/register"]
},
"include": ["./src"],
"exclude": ["node_modules", "./src/**/*.test.ts", "./src/**/*.spec.ts"]
}
Loading

0 comments on commit c34cc67

Please sign in to comment.