-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Remove lib folder - Refactor some tests - General cleanup
- Loading branch information
Showing
27 changed files
with
271 additions
and
235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,6 @@ sandbox.js | |
package-lock.json | ||
coverage | ||
public | ||
yt-dlp | ||
./yt-dlp | ||
.env | ||
dependency-graph.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
export const defaultBackendFlags = { | ||
foo: { | ||
placeholder_url: { | ||
type: 'string', | ||
default: 'bar', | ||
description: 'An example backend flag that isn\'t sent to clients' | ||
default: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ', // rick roll | ||
description: 'The default file to inject into empty feeds' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import fp from 'fastify-plugin' | ||
import { request as undiciRequest } from 'undici' | ||
|
||
/** | ||
* This plugin adds yt-dlp fetching helpeers | ||
*/ | ||
export default fp(async function (fastify, opts) { | ||
fastify.decorate('getYTDLPMetadata', async function getYTDLPMetadata ({ | ||
url, | ||
medium | ||
}) { | ||
const endTimer = fastify.metrics.ytdlpSeconds.startTimer() | ||
try { | ||
const formatOpts = getFormatArg(medium) | ||
const requestURL = new URL(fastify.config.YT_DLP_API_URL) | ||
requestURL.searchParams.set('url', url) | ||
requestURL.searchParams.set('format', formatOpts) | ||
requestURL.pathname = 'info' | ||
|
||
const response = await undiciRequest(requestURL, { | ||
headers: { | ||
Accept: 'application/json', | ||
Authorization: 'Basic ' + btoa(requestURL.username + ':' + requestURL.password) | ||
} | ||
}) | ||
|
||
if (response.statusCode !== 200) { | ||
const text = await response.body.text() | ||
throw new Error('yt-dlp error: ' + text) | ||
} | ||
|
||
const metadata = await response.body.json() | ||
|
||
return metadata | ||
} finally { | ||
endTimer() | ||
} | ||
}) | ||
}, { | ||
name: 'yt-dlp', | ||
dependencies: ['env', 'prom'] | ||
}) | ||
|
||
const videoFormat = 'best[ext=mp4]/best[ext=mov]/mp4/mov' | ||
const audioFormat = 'ba[ext=m4a]/ba[ext=mp4]/ba[ext=mp3]/mp3/m4a' | ||
|
||
export function getFormatArg (medium) { | ||
if (!['video', 'audio'].includes(medium)) throw new Error('format must be video or audio') | ||
|
||
const formatOpts = medium === 'video' | ||
? [videoFormat, audioFormat].join('/') | ||
: medium === 'audio' | ||
? [audioFormat, videoFormat].join('/') | ||
: null | ||
|
||
if (!formatOpts) throw new Error('No format options generated. Please report this bug') | ||
|
||
return formatOpts | ||
} | ||
|
||
export function getFileKey ({ | ||
userId, | ||
episodeId, | ||
sourceUrl, | ||
type, | ||
medium | ||
}) { | ||
return [ | ||
'file', | ||
userId, | ||
episodeId, | ||
sourceUrl, | ||
type, | ||
medium | ||
].join(':') | ||
} |
Oops, something went wrong.