Giter Site home page Giter Site logo

Comments (4)

Kikobeats avatar Kikobeats commented on May 30, 2024 1

Thanks for this great suggestion!

I added the .raw method to make possibleto access stream objects at [email protected]:

const youtubedl = require('youtube-dl-exec')
const fs = require('fs')

const subprocess = youtubedl.raw('https://example.com', { dumpJson: true })

console.log(`Running subprocess as ${subprocess.pid}`)

subprocess.stdout.pipe(fs.createWriteStream('stdout.txt'))
subprocess.stderr.pipe(fs.createWriteStream('stderr.txt'))

setTimeout(subprocess.cancel, 30000)

from youtube-dl-exec.

jcohenho avatar jcohenho commented on May 30, 2024

@Kikobeats This is great, thank you! I wrote a script to pipe the stream object to a stream passthrough in order to directly upload to S3, but the resulting video file is corrupt. Am I misunderstanding something here? I can successfully download the Twitter link in this code example using the normal youtubedl method.

const youtubedl = require('youtube-dl-exec')
const AWS = require('aws-sdk');
const stream = require('stream');

const s3 = new AWS.S3();
const uploadStream = ({ Bucket, Key, Metadata }) => {
  const pass = new stream.PassThrough();
  return {
    writeStream: pass,
    promise: s3.upload({ Bucket, Key, Body: pass }).promise(),
  };
}

const { videoId, filename } = {
  "videoId": "732194327145906176",
  "filename": "sample_video",
}
const url = `https://twitter.com/i/status/${videoId}`
const { writeStream, promise } = uploadStream({ Bucket: process.env.S3_BUCKET, Key: `${filename}.mp4`});

youtubedl.raw(url, {
  noCallHome: true,
  noCheckCertificate: true,
  preferFreeFormats: true,
  format: 'mp4',
  youtubeSkipDashManifest: true,
  output: '%(id)s.%(ext)s'
}).stdout.pipe(writeStream);

const data = await promise;
return {
  statusCode: 200,
  body: data,
};

from youtube-dl-exec.

Kikobeats avatar Kikobeats commented on May 30, 2024

The script looks nice to me but I can't say too much there since I didn't have a use case like that before.

What I can recommend you to do is get the streaming source video URL via Microlink API:

https://api.microlink.io/?url=https://twitter.com/eejohnnnn/status/732194327145906176&video

It uses youtube-dl (and this library) under the hood, then you can do a simple HTTP GET and pipe to your s3 bucket.

from youtube-dl-exec.

jcohenho avatar jcohenho commented on May 30, 2024

@Kikobeats amazing! Wasn't aware of this API, thank you!

from youtube-dl-exec.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.