mirror of
https://github.com/iptv-org/iptv
synced 2026-04-20 17:57:11 -04:00
Added tests for the playlist
This commit is contained in:
68
test/index.js
Normal file
68
test/index.js
Normal file
@@ -0,0 +1,68 @@
|
||||
var parsers = require('playlist-parser');
|
||||
var M3U = parsers.M3U;
|
||||
var fs = require("fs");
|
||||
var axios = require('axios')
|
||||
var path = require('path')
|
||||
|
||||
var errorLog = path.resolve(__dirname) + '/../error.log'
|
||||
|
||||
var instance = axios.create({ timeout: 10000, maxRedirects: 0 })
|
||||
|
||||
function _writeToLog(test, msg, url) {
|
||||
var now = new Date()
|
||||
var line = `${now.toISOString()} ${test}(): ${msg} '${url}'`
|
||||
fs.appendFileSync(errorLog, line + '\n')
|
||||
}
|
||||
|
||||
function _getFullPathToFile(parent, file) {
|
||||
if(/(http|https)/i.test(file) || !parent) {
|
||||
return file
|
||||
}
|
||||
|
||||
var parsedUrl = parent.substring(0, parent.lastIndexOf("/"))
|
||||
|
||||
return parsedUrl + '/' + file
|
||||
}
|
||||
|
||||
function _parsePlaylist(parent, playlist) {
|
||||
playlist.forEach(async (item) => {
|
||||
if(!item) return
|
||||
|
||||
var file = _getFullPathToFile(parent, item.file)
|
||||
|
||||
if(/(\.m3u|\.m3u8)/i.test(file)) {
|
||||
|
||||
try{
|
||||
var response = await instance.get(file)
|
||||
console.log(file)
|
||||
console.log(response.status)
|
||||
|
||||
var sublist = M3U.parse(response.data);
|
||||
// console.log(sublist)
|
||||
_parsePlaylist(file, sublist)
|
||||
|
||||
} catch(err) {
|
||||
console.log(file)
|
||||
console.log('Error:',err.message)
|
||||
|
||||
if(err.response && /(404)/.test(err.response.status)) {
|
||||
_writeToLog('testThatAllLinksIsWorking', err.message, file)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
})
|
||||
}
|
||||
|
||||
function testThatAllLinksIsWorking() {
|
||||
|
||||
var playlist = M3U.parse(fs.readFileSync(path.resolve(__dirname) + "/../index.m3u", { encoding: "utf8" }));
|
||||
// playlist = playlist.slice(1600, 1700)
|
||||
|
||||
_parsePlaylist(null, playlist)
|
||||
|
||||
}
|
||||
|
||||
testThatAllLinksIsWorking()
|
||||
Reference in New Issue
Block a user