Permalink
Browse files

remove ytdl-core parts

  • Loading branch information...
1 parent b624a3b commit b53822229dbb43723e2722bfd578b049ad272637 @fent committed Jun 30, 2014
View
@@ -1,66 +1,10 @@
# node-ytdl [![Build Status](https://secure.travis-ci.org/fent/node-ytdl.png)](http://travis-ci.org/fent/node-ytdl)
-Yet another youtube downloading module. This time written with only Javascript and a more node-friendly streaming interface.
-
+A youtube downloader written in Javascript. To be used with the command line. If you're looking to use it in your node program, check out [ytdl-core](https://github.com/fent/node-ytdl-core).
# Usage
-```js
-var fs = require('fs');
-var ytdl = require('ytdl');
-
-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](http://en.wikipedia.org/wiki/YouTube#Quality_and_codecs) value, `highest`, or `lowest`. Defaults to `highest`.
-* `filter` - 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.
-* `range` - A byte range in the form `INT-INT` that specifies a part of the video to download. ie 10355705-12452856.
-
-```js
-// Example with `filter` option.
-ytdl(url, { filter: function(format) { return format.container === 'mp4'; } })
- .pipe(fs.createWriteStream('vide.mp4'));
-```
-
-`options` can also have any [request](https://github.com/mikeal/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](https://gist.github.com/fent/6c8251132e1addb5121e).
-
-### 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.cache
-
-A [memory cache](https://github.com/hij1nx/EventVat) is used to store information about recently retrieved videos. This is used to prevent double requests on videos that you want to retrieve the info of, and then download.
-
-
-# Install
-
- npm install ytdl
-
-# CLI
-
-ytdl can be used from the command line too. Install with the `-g` flag to use it.
-
- ytdl http://www.youtube.com/watch?v=_HSylqgVYQI > cat.flv
+ ytdl http://www.youtube.com/watch?v=_HSylqgVYQI > myvideo.flv
And it streams!
@@ -81,6 +25,10 @@ And it streams!
--unfilter-encoding REGEXP Filter out format encoding.
-i, --info Print video info without downloading
+# Install
+
+ [sudo] npm -g install ytdl
+
# Tests
Tests are written with [mocha](http://visionmedia.github.com/mocha/)
View
@@ -2,8 +2,9 @@
var path = require('path');
var fs = require('fs');
-var ytdl = require('..');
+var ytdl = require('ytdl-core');
var cliff = require('cliff');
+var util = require('../lib/util');
require('colors');
@@ -80,31 +81,6 @@ var opts = require('nomnom')
;
-/**
- * Converts seconds into human readable time hh:mm:ss
- *
- * @param {Number} seconds
- * @return {String}
- */
-function toHumanTime(seconds) {
- var h = Math.floor(seconds / 3600);
- var m = Math.floor(seconds / 60) % 60;
-
- var time;
- if (h > 0) {
- time = h + ':';
- if (m < 10) { m = '0' + m; }
- } else {
- time = '';
- }
-
- var s = seconds % 60;
- if (s < 10) { s = '0' + s; }
-
- return time + m + ':' + s;
-}
-
-
/**
* Prints basic video information.
*
@@ -118,7 +94,7 @@ function printVideoInfo(info) {
info.avg_rating.toFixed(1) : info.avg_rating;
console.log('average rating: '.grey.bold + rating);
console.log('view count: '.grey.bold + info.view_count);
- console.log('length: '.grey.bold + toHumanTime(info.length_seconds));
+ console.log('length: '.grey.bold + util.toHumanTime(info.length_seconds));
}
@@ -219,24 +195,14 @@ readStream.on('error', function(err) {
process.exit(1);
});
-// Converst bytes to human readable unit.
-// Thank you Amir from StackOverflow.
-var units = ' KMGTPEZYXWVU';
-function toHumanSize(bytes) {
- if (bytes <= 0) { return 0; }
- var t2 = Math.min(Math.floor(Math.log(bytes) / Math.log(1024)), 12);
- return (Math.round(bytes * 100 / Math.pow(1024, t2)) / 100) +
- units.charAt(t2).replace(' ', '') + 'B';
-}
-
// Print progress bar and some video info if not streaming to stdout.
if (output) {
readStream.on('info', function(info, format) {
printVideoInfo(info);
console.log('container: '.grey.bold + format.container);
console.log('resolution: '.grey.bold + format.resolution);
console.log('encoding: '.grey.bold + format.encoding);
- console.log('size: '.grey.bold + toHumanSize(format.size));
+ console.log('size: '.grey.bold + util.toHumanSize(format.size));
console.log('output: '.grey.bold + output);
console.log();
View
@@ -0,0 +1,2 @@
+console.warn('This module is meant to be used by cli. If you want to use ytdl programmatically, visit https://github.com/fent/node-ytdl-core');
+module.exports = require('ytdl-core');
View
@@ -1,39 +0,0 @@
-var request = require('request');
-var EventVat = require('eventvat');
-
-var ytdl = {};
-// Circular dependency.
-process.nextTick(function() {
- // Cache for recently looked up video infos.
- ytdl = require('./index');
-});
-
-/**
- * Makes a request and caches the body so that additional requests
- * to the same url don't require network IO.
- *
- * @param {Object|String} options
- * @param {Function} callback
- */
-module.exports = function(options, callback) {
- var url = options.url || options.uri || options;
- if (ytdl.cache && ytdl.cache.exists(url)) {
- process.nextTick(function() {
- callback(null, ytdl.cache.get(url));
- });
- } else {
- request(options, function(err, res, body) {
- if (err) return callback(err);
- if (res.statusCode !== 200) {
- return callback(new Error('status code ' + res.statusCode));
- }
- if (ytdl.cache) {
- ytdl.cache.set(url, body);
- }
- callback(null, body);
- });
- }
-};
-
-// Export cache.
-module.exports.cache = new EventVat({ autoexpire: 30 });
Oops, something went wrong.

0 comments on commit b538222

Please sign in to comment.