GithubHelp home page GithubHelp logo

imclab / node-ytdl-core Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fent/node-ytdl-core

0.0 2.0 0.0 3.98 MB

Youtube video downloader in javascript.

License: MIT License

JavaScript 100.00%

node-ytdl-core's Introduction

node-ytdl-core Build Status

Yet another youtube downloading module. This time written with only Javascript and a more node-friendly streaming interface.

For a CLI version of this, check out ytdl and pully.

Usage

var fs = require('fs');
var ytdl = require('ytdl-core');

ytdl('http://www.youtube.com/watch?v=A02s8omM_hI')
  .pipe(fs.createWriteStream('video.flv'));

API

ytdl(url, options)

Attempts to download a video from the given url. Returns a readable stream. options can have the following keys

  • quality - Video quality to download. Can be an itag value value, or highest/lowest. Defaults to highest.
  • filter - Can be video to filter for formats that contain video, videoonly for formats that contain video and no additional audio track. Can also be audio or audioonly. You can give a filtering function that gets called with each format available. Used to decide what format to download. This function is given the format object as its first argument, and should return true if the format is preferable.
  • format - This can be a specific format object returned from getInfo. This is primarily used to download specific video or audio streams. Note: Supplying this option will ignore the filter and quality options since the format is explicitly provided.
  • range - A byte range in the form INT-INT that specifies a part of the video to download. ie 10355705-12452856.
// Example with `filter` option.
ytdl(url, { filter: function(format) { return format.container === 'mp4'; } })
  .pipe(fs.createWriteStream('vide.mp4'));

options can also have any request options.

The returned readable stream emits these additional events.

Event: 'info'

  • Object - Info.
  • Object - Format.

Emitted when the a video's info hash is fetched. Along with the chosen format metadata to download. format.url might be different if start was given. format.size will also be available.

Info and format may look like this.

ytdl.getInfo(url, [options], callback(err, info))

Use this if you only want to get metainfo from a video.

options gets passed to the request(), it can also have a downloadURL property set to true if you want ytdl to include the download url instead of the regular one. In some cases, a signature needs to be deciphered, and will require ytdl to make additional requests.

ytdl.downloadFromInfo(info, options)

Once you have received metadata from a video with the getInfo function, you may pass that info, along with other options to downloadFromInfo.

Note: Be sure to set the downloadURL option to true when you call getInfo or you will receive a 403 error when you call downloadFromInfo.

The returned readable stream emits these additional events:

Event: 'format'

  • Object - Format.

Emitted when a format metadata has been chosen. format.size will also be available.

Tips

Handling Separate Streams

Typically 1080p or better video does not have audio encoded with it. The audio must be downloaded separately and merged via an appropriate encoding library. ffmpeg is the most widely used tool, with many Node.js modules available. Use the format objects returned from ytdl.getInfo to download specific streams to combine to fit your needs.

Install

npm install ytdl-core

Tests

Tests are written with mocha

npm test

License

MIT

node-ytdl-core's People

Contributors

andrewrk avatar coderaiser avatar edef1c avatar fent avatar liuhenry avatar max-mapper avatar

Watchers

 avatar  avatar

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.