Global

Methods

(async) WDwloadM3u8(url, fp, optopt) → {Promise}

Description:
  • 下載m3u8檔案,核心調用N_m3u8DL-CLI,只能用於Windows作業系統

    N_m3u8DL-CLI: https://github.com/nilaoda/N_m3u8DL-CLI

Source:
Example
import fs from 'fs'
import WDwloadM3u8 from './src/WDwloadM3u8.mjs'

async function test() {

    //url
    let url = `https://cdn.jsdelivr.net/npm/w-demores@1.0.28/res/video/aigen_hls/playlist.m3u8`

    //fp
    let fp = './abc.mp4'

    //funProg
    let funProg = (prog, nn, na) => {
        console.log('prog', `${prog.toFixed(2)}%`, nn, na)
    }

    //WDwloadM3u8
    await WDwloadM3u8(url, fp, {
        clean: true, //單一程序執行時, 事先清除之前暫存檔, 減少浪費硬碟空間
        funProg,
    })

    //len
    let len = fs.statSync(fp).size
    console.log('len', len)

    console.log('done:', fp)
}
test()
    .catch((err) => {
        console.log('catch', err)
    })
// prog 0.00% 0 1
// prog 100.00% 1 1
// len 283236
// done: ./abc.mp4

//node g.mjs
Parameters:
Name Type Attributes Default Description
url String

輸入m3u8網址字串

fp String

輸入儲存mp4檔案路徑字串

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
clean Boolean <optional>
false

輸入預先清除暫存檔布林值,預設false

funProg function <optional>
null

輸入回傳進度函數,傳入參數為prog代表進度百分比、nn代表當前已下載ts檔案數量、na代表全部須下載ts檔案數量,預設null

Returns:

回傳Promise,resolve回傳成功訊息,reject回傳錯誤訊息

Type
Promise