ActivityPub-federated video streaming platform using P2P directly in your web browser
Merge branch 'develop' into cli-wrapper
Chocobozzz0491173a61ae
diff --cc package.jsonindex cc4f6be5ce,53e07a72bb..d5cf95b83c--- a/package.json+++ b/package.json@@@ -116,9 -111,9 +116,10 @@@"jsonld-signatures": "https://github.com/Chocobozzz/jsonld-signatures#rsa2017","lodash": "^4.17.10","magnet-uri": "^5.1.4",+ "memoizee": "^0.4.14","morgan": "^1.5.3","multer": "^1.1.0",+ "netrc-parser": "^3.1.6","nodemailer": "^4.4.2","parse-torrent": "^6.0.0","password-generator": "^2.0.2",diff --cc server/helpers/youtube-dl.tsindex 8b2bc17824,db2bddf78c..25e719cc36--- a/server/helpers/youtube-dl.ts+++ b/server/helpers/youtube-dl.ts@@@ -48,6 -52,74 +52,64 @@@ function downloadYoutubeDLVideo (url: s})}+ // Thanks: https://github.com/przemyslawpluta/node-youtube-dl/blob/master/lib/downloader.js+ // We rewrote it to avoid sync calls+ async function updateYoutubeDLBinary () {+ logger.info('Updating youtubeDL binary.')++ const binDirectory = join(root(), 'node_modules', 'youtube-dl', 'bin')+ const bin = join(binDirectory, 'youtube-dl')+ const detailsPath = join(binDirectory, 'details')+ const url = 'https://yt-dl.org/downloads/latest/youtube-dl'++ await ensureDir(binDirectory)++ return new Promise(res => {+ request.get(url, { followRedirect: false }, (err, result) => {+ if (err) {+ logger.error('Cannot update youtube-dl.', { err })+ return res()+ }++ if (result.statusCode !== 302) {+ logger.error('youtube-dl update error: did not get redirect for the latest version link. Status %d', result.statusCode)+ return res()+ }++ const url = result.headers.location+ const downloadFile = request.get(url)+ const newVersion = /yt-dl\.org\/downloads\/(\d{4}\.\d\d\.\d\d(\.\d)?)\/youtube-dl/.exec(url)[ 1 ]++ downloadFile.on('response', result => {+ if (result.statusCode !== 200) {+ logger.error('Cannot update youtube-dl: new version response is not 200, it\'s %d.', result.statusCode)+ return res()+ }++ downloadFile.pipe(createWriteStream(bin, { mode: 493 }))+ })++ downloadFile.on('error', err => {+ logger.error('youtube-dl update error.', { err })+ return res()+ })++ downloadFile.on('end', () => {+ const details = JSON.stringify({ version: newVersion, path: bin, exec: 'youtube-dl' })+ writeFile(detailsPath, details, { encoding: 'utf8' }, err => {+ if (err) {+ logger.error('youtube-dl update error: cannot write details.', { err })+ return res()+ }++ logger.info('youtube-dl updated to version %s.', newVersion)+ return res()+ })+ })+ })+ })+ }+-// -----------------------------------------------------------------------------export {- updateYoutubeDLBinary,- downloadYoutubeDLVideo,- getYoutubeDLInfo-}--// ----------------------------------------------------------------------------async function safeGetYoutubeDL () {let youtubeDL@@@ -62,16 -134,6 +124,17 @@@return youtubeDL}+// ---------------------------------------------------------------------------++export {++ updateYoutubeDLBinary,+ downloadYoutubeDLVideo,+ getYoutubeDLInfo,+ safeGetYoutubeDL+}++// ---------------------------------------------------------------------------+function normalizeObject (obj: any) {const newObj: any = {}