我是一名學生,試圖建立一個用于練習目的的電影網站專案。
但我只知道電影的資料庫會很大,所以我只是想“如果我只是從另一個網站借電影怎么辦”,所以我查找并找到了一個術語,叫做“抓取或抓取資料”,當然,非商業用途,我只是想讓我的專案作業。因此,如果這是非法的或不正確的做法,請在下面發表評論,我會考慮到這一點。
但如果這樣做沒問題,我有什么辦法可以獲得 m3u8 播放串列嗎?我不知道該怎么做(完全,說實話)。所以我真的需要一個指南或一些指導,我需要做的方向。
由于我的研究,我計劃使用一些cheerio,Axios并嘗試以某種方式弄清楚。
更具體地說,每當我播放視頻時,如果我檢查它,在網路選項卡中,它將包含一個檔案呼叫 playlist.m3u8,其中包含許多小的 .ts 檔案。我想以某種方式獲取它并將其轉移到我的專案中觀看。
uj5u.com熱心網友回復:
playlist.m3u8 檔案只是一個播放串列,包含有關視頻的資料和視頻檔案/塊的鏈接,或包含該檔案的塊串列的鏈接。
根據您的專案,它可能已經內置了查看 m3u8 檔案的方式,在基于瀏覽器的專案中,您只需將視頻元素的 url 設定為 .m3u8 的 url。
如果已經沒有辦法使用 m3u8 檔案,您將不得不下載決議器或自己撰寫一個決議器。
這是 JS 中的一個簡單決議器,它會按順序讀取每個 ts 并將它們附加到視頻的末尾,因為它會忽略計時資料和所有其他額外資訊,它會非常有問題,但這只是一個簡單的例子。
//This is a simple example that is non-reliable and should not be relied upon.
const fs = require('fs');
const http = require('http');
const source_domain = "http://sourcehost.com/";
const playlist_path = "playlist.m3u8";
var video_file = fs.createWriteStream("test.mp4");
GetPlaylist(source_domain playlist_path);
function GetPlaylist(url){
return new Promise((resolve, reject) => {
http.request(url, (res) => {
var data = '';
res.on('data', (chunk) =>{
data = chunk;
});
res.on('end', async () => {
var lines = data.split("\n");
for(var line of lines){
if(line.indexOf(".ts") !== -1){
await GetChunk(source_domain line);
}
}
video_file.end();
});
res.on('timeout', () => {
reject('timeout');
});
}).end();
});
}
function GetChunk(chunk_path){
return new Promise((resolve, reject) => {
http.request(chunk_path, (res) => {
res.setEncoding('binary');
res.on('data', (chunk) =>{
video_file.write(chunk, 'binary');
});
res.on('end', () => {
resolve();
});
res.on('timeout', () => {
reject('timeout');
});
}).end();
});
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/381180.html
標籤:javascript 节点.js 反应 网页抓取 网络爬虫
