Added tests for the playlist
This commit is contained in:
parent
a5ca86eaaf
commit
029eaf9fb4
63
package-lock.json
generated
Normal file
63
package-lock.json
generated
Normal file
@ -0,0 +1,63 @@
|
||||
{
|
||||
"name": "iptv",
|
||||
"version": "0.0.1",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
"axios": {
|
||||
"version": "0.18.0",
|
||||
"resolved": "http://registry.npmjs.org/axios/-/axios-0.18.0.tgz",
|
||||
"integrity": "sha1-MtU+SFHv3AoRmTts0AB4nXDAUQI=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"follow-redirects": "^1.3.0",
|
||||
"is-buffer": "^1.1.5"
|
||||
}
|
||||
},
|
||||
"debug": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
|
||||
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"ms": "2.0.0"
|
||||
}
|
||||
},
|
||||
"follow-redirects": {
|
||||
"version": "1.5.9",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.9.tgz",
|
||||
"integrity": "sha512-Bh65EZI/RU8nx0wbYF9shkFZlqLP+6WT/5FnA3cE/djNSuKNHJEinGGZgu/cQEkeeb2GdFOgenAmn8qaqYke2w==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"debug": "=3.1.0"
|
||||
}
|
||||
},
|
||||
"is-buffer": {
|
||||
"version": "1.1.6",
|
||||
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz",
|
||||
"integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==",
|
||||
"dev": true
|
||||
},
|
||||
"ms": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
||||
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=",
|
||||
"dev": true
|
||||
},
|
||||
"playlist-parser": {
|
||||
"version": "0.0.12",
|
||||
"resolved": "https://registry.npmjs.org/playlist-parser/-/playlist-parser-0.0.12.tgz",
|
||||
"integrity": "sha1-QlDlsRdxrWghOYO/m7bsq2Td9SY=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"xmldom": "0.1.16"
|
||||
}
|
||||
},
|
||||
"xmldom": {
|
||||
"version": "0.1.16",
|
||||
"resolved": "https://registry.npmjs.org/xmldom/-/xmldom-0.1.16.tgz",
|
||||
"integrity": "sha1-zyYCgysatcPmgT/KCP5wGWuhXow=",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
}
|
24
package.json
Normal file
24
package.json
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "iptv",
|
||||
"version": "0.0.1",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/freearhey/iptv.git"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"bugs": {
|
||||
"url": "https://github.com/freearhey/iptv/issues"
|
||||
},
|
||||
"homepage": "https://github.com/freearhey/iptv#readme",
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"axios": "^0.18.0",
|
||||
"playlist-parser": "0.0.12"
|
||||
}
|
||||
}
|
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()
|
Loading…
Reference in New Issue
Block a user