initial commit
Esse commit está contido em:
@@ -0,0 +1,4 @@
|
||||
.DS_Store
|
||||
node_modules/
|
||||
.idea/
|
||||
test.mp4
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Simon Kusterer
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
# castnow
|
||||
|
||||
castnow is commandline utility which can be used to playback media files on
|
||||
your chromecast device. It supports playback of local video files, youtube
|
||||
clips, videos on the web and torrents.
|
||||
You can toggle beween play and pause with the space-key.
|
||||
|
||||
### Usage
|
||||
|
||||
```
|
||||
|
||||
// start playback of a local video file
|
||||
castnow ./myvideo.mp4
|
||||
|
||||
// start playback of some mp4 file over the web
|
||||
castnow http://commondatastorage.googleapis.com/gtv-videos-bucket/ED_1280.mp4
|
||||
|
||||
// start playback of some youtube clip
|
||||
castnow https://www.youtube.com/watch?v=pcVRrlmpcWk
|
||||
|
||||
// start playback of some video over torrent
|
||||
castnow <url-to-torrent-file OR magnet> --torrent
|
||||
|
||||
// re-attach to an currently running playback session
|
||||
castnow
|
||||
|
||||
```
|
||||
|
||||
### Installation
|
||||
|
||||
`npm install castnow -g`
|
||||
|
||||
## License
|
||||
Copyright (c) 2014 Simon Kusterer
|
||||
Licensed under the MIT license.
|
||||
Arquivo executável
+82
@@ -0,0 +1,82 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var player = require('chromecast-player')();
|
||||
var opts = require('minimist')(process.argv.slice(2));
|
||||
var chalk = require('chalk');
|
||||
var keypress = require('keypress');
|
||||
var log = require('single-line-log').stdout;
|
||||
|
||||
// Plugins
|
||||
var localfile = require('./plugins/localfile');
|
||||
var torrent = require('./plugins/torrent');
|
||||
var youtube = require('./plugins/youtube');
|
||||
|
||||
if (opts._.length) {
|
||||
opts.path = opts._[0];
|
||||
}
|
||||
|
||||
delete opts._;
|
||||
|
||||
var ctrl = function(err, p, ctx) {
|
||||
if (err) {
|
||||
console.log(chalk.red(err));
|
||||
process.exit();
|
||||
}
|
||||
|
||||
keypress(process.stdin);
|
||||
process.stdin.setRawMode(true);
|
||||
process.stdin.resume();
|
||||
|
||||
var isPlaying = function() {
|
||||
return p.currentSession.playerState === 'PLAYING';
|
||||
};
|
||||
|
||||
process.stdin.on('keypress', function(ch, key) {
|
||||
if (key.name === 'space') {
|
||||
if (isPlaying()) {
|
||||
p.pause();
|
||||
} else {
|
||||
p.play();
|
||||
}
|
||||
}
|
||||
if (key && key.ctrl && key.name == 'c') {
|
||||
process.exit();
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
var circulate = function(arr) {
|
||||
var len = arr.length, pos = -1;
|
||||
return !len ? void 0 : function() {
|
||||
return arr[pos = ++pos % len];
|
||||
}
|
||||
};
|
||||
|
||||
var logState = (function() {
|
||||
var inter;
|
||||
var dots = circulate(['.', '..', '...', '....']);
|
||||
return function(status) {
|
||||
if (inter) clearInterval(inter);
|
||||
inter = setInterval(function() {
|
||||
log(chalk.grey('player status: ') + chalk.green(status + dots()) + "\n");
|
||||
}, 300);
|
||||
};
|
||||
})();
|
||||
|
||||
player.use(function(ctx, next) {
|
||||
ctx.on('status', logState)
|
||||
next();
|
||||
});
|
||||
|
||||
player.use(torrent);
|
||||
player.use(localfile);
|
||||
player.use(youtube);
|
||||
|
||||
if (!opts.path) {
|
||||
player.attach(opts, ctrl);
|
||||
} else {
|
||||
player.launch(opts, ctrl);
|
||||
}
|
||||
|
||||
module.exports = player;
|
||||
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"name": "castnow",
|
||||
"version": "0.0.1",
|
||||
"description": "commandline chromecast player",
|
||||
"main": "index.js",
|
||||
"bin": {
|
||||
"castnow": "./index.js"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "Simon Kusterer",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git@github.com:xat/castnow.git"
|
||||
},
|
||||
"keywords": [
|
||||
"chromecast",
|
||||
"media",
|
||||
"player",
|
||||
"video",
|
||||
"torrent",
|
||||
"peerflix",
|
||||
"commandline",
|
||||
"cast"
|
||||
],
|
||||
"dependencies": {
|
||||
"castv2-client": "0.0.6",
|
||||
"chalk": "^0.5.1",
|
||||
"chromecast-player": "0.1.0",
|
||||
"get-port": "^1.0.0",
|
||||
"get-youtube-id": "^0.1.3",
|
||||
"internal-ip": "^1.0.0",
|
||||
"keypress": "^0.2.1",
|
||||
"minimist": "^1.1.0",
|
||||
"peercast": "^1.1.2",
|
||||
"peerflix": "^0.19.1",
|
||||
"read-torrent": "^1.0.0",
|
||||
"single-line-log": "^0.4.1"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
var http = require('http');
|
||||
var getPort = require('get-port');
|
||||
var internalIp = require('internal-ip');
|
||||
var fs = require('fs');
|
||||
|
||||
var isFile = function(path) {
|
||||
return fs.existsSync(path) && fs.statSync(path).isFile();
|
||||
};
|
||||
|
||||
var localfile = function(ctx, next) {
|
||||
if (ctx.mode === 'attach') return next();
|
||||
if (!isFile(ctx.options.path)) return next();
|
||||
var filePath = ctx.options.path;
|
||||
|
||||
getPort(function(err, port) {
|
||||
ctx.options.path = 'http://' + internalIp() + ':' + port;
|
||||
ctx.options.type = 'video/mp4';
|
||||
http.createServer(function(req, res) {
|
||||
fs.createReadStream(filePath).pipe(res);
|
||||
}).listen(port);
|
||||
next();
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = localfile;
|
||||
@@ -0,0 +1,18 @@
|
||||
var readTorrent = require('read-torrent');
|
||||
var peerflix = require('peerflix');
|
||||
var internalIp = require('internal-ip');
|
||||
|
||||
var torrent = function(ctx, next) {
|
||||
if (ctx.mode === 'attach' || !ctx.options.torrent) return next();
|
||||
readTorrent(ctx.options.path, function(err, torrent) {
|
||||
if (err) return next();
|
||||
var engine = peerflix(torrent);
|
||||
engine.server.once('listening', function() {
|
||||
ctx.options.path = 'http://'+internalIp()+':'+engine.server.address().port;
|
||||
ctx.options.type = 'video/mp4';
|
||||
next();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = torrent;
|
||||
@@ -0,0 +1,38 @@
|
||||
var Api = require('chromecast-player').api;
|
||||
var castv2Cli = require('castv2-client');
|
||||
var RequestResponseController = castv2Cli.RequestResponseController;
|
||||
var inherits = require('util').inherits;
|
||||
var getYouTubeId = require('get-youtube-id');
|
||||
|
||||
var Yt = function() {
|
||||
Api.apply(this, arguments);
|
||||
this.ytreq = this.createController(RequestResponseController,
|
||||
'urn:x-cast:com.google.youtube.mdx');
|
||||
};
|
||||
|
||||
Yt.APP_ID = '233637DE';
|
||||
|
||||
inherits(Yt, Api);
|
||||
|
||||
Yt.prototype.load = function(opts, cb) {
|
||||
var opts = {
|
||||
type: 'flingVideo',
|
||||
data: {
|
||||
currentTime: 0,
|
||||
videoId: opts.path
|
||||
}
|
||||
};
|
||||
this.ytreq.request(opts);
|
||||
cb();
|
||||
};
|
||||
|
||||
var youtube = function(ctx, next) {
|
||||
if (ctx.mode === 'attach') return next();
|
||||
var id = getYouTubeId(ctx.options.path);
|
||||
if (!id) return next();
|
||||
ctx.api = Yt;
|
||||
ctx.options.path = id;
|
||||
next();
|
||||
};
|
||||
|
||||
module.exports = youtube;
|
||||
Referência em uma Nova Issue
Bloquear um usuário