上传视频并获取流媒体的直接网址

时间:2015-10-14 10:58:03

标签: url video youtube streaming youtube-dl

我想上传视频并获取直接网址(不是YouTube页面,只是服务器上的原始视频文件)。我在这里读到youtube-dl可以从YT视频中获得这样的直接链接,但它返回的内容如下:

https://r5---sn-f5f7ln7s.googlevideo.com/videoplayback?id=5e338da1be872622&itag=
140&source=youtube&requiressl=yes&mm=31&pl=17&mn=sn-f5f7ln7s&mv=m&ms=au&ratebypa
ss=yes&mime=audio/mp4&gir=yes&clen=615762&lmt=1444814917264017&dur=38.730&key=dg
_yt0&signature=85FE55338A7ECBCA4895DFA3084A6C8CB7C09654.28AD612266C937BFBBD20135
D03031E824806B53&sver=3&mt=1444818958&fexp=9405191,9408210,9408710,9414764,94154
35,9415868,9416126,9417707,9418199,9418401,9418702,9420439,9420933,9421923,94220
62,9422545&upn=5cQZ5KNCvl0&ip=89.74.115.72&ipbits=0&expire=1444840721&sparams=ip
,ipbits,expire,id,itag,source,requiressl,mm,pl,mn,mv,ms,ratebypass,mime,gir,clen
,lmt,dur

问题是,它播放但没有显示任何内容(实际上,它作为视频文件打开)。所以看起来YT在某种程度上受到了保护,不受此类行为的影响。

你知道任何允许我这样做的网站吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

youtube-dl可以从各种网站下载视频,而不仅仅是YT

youtube-dl -c -l https://www.youtube.com/watch?v=fT88iVceBn4

在服务器(或本地计算机)上有媒体文件(音频/视频)后,以下nodejs服务器会将其流式传输到URL ...

将节点代码保存到文件media_server.js中然后一旦安装了nodejs就启动下面的代码

node ./media_server.js 

然后将浏览器指向http://localhost:8888/

它是一个小型媒体服务器,响应所有标准媒体导航小部件......玩得开心

var http = require('http'),
    fs = require('fs'),
    util = require('util');

// var path = "/path/to/audio/or/video/file/local/to/server/cool.mp4"; // put any audio or video file here
var path = "/home/stens/Videos/kehoe/OliverSacks_2009-480p.mp4"; // put any audio or video file here

var port = 8888;
var host = "localhost";

http.createServer(function (req, res) {

  var stat = fs.statSync(path);
  var total = stat.size;

  if (req.headers.range) {  // meaning client (browser) has moved the forward/back slider
                            // which has sent this request back to this server logic ... cool
    var range = req.headers.range;
    var parts = range.replace(/bytes=/, "").split("-");
    var partialstart = parts[0];
    var partialend = parts[1];

    var start = parseInt(partialstart, 10);
    var end = partialend ? parseInt(partialend, 10) : total-1;
    var chunksize = (end-start)+1;
    console.log('RANGE: ' + start + ' - ' + end + ' = ' + chunksize);

    var file = fs.createReadStream(path, {start: start, end: end});
    res.writeHead(206, { 'Content-Range': 'bytes ' + start + '-' + end + '/' + total, 'Accept-Ranges': 'bytes', 'Content-Length': chunksize, 'Content-Type': 'video/mp4' });
    file.pipe(res);

  } else {

    console.log('ALL: ' + total);
    res.writeHead(200, { 'Content-Length': total, 'Content-Type': 'video/mp4' });
    fs.createReadStream(path).pipe(res);
  }
}).listen(port, host);

console.log("Server running at http://" + host + ":" + port + "/");