From 5f03e6eca617d96bc8ff0e091dfb99dfca1f6163 Mon Sep 17 00:00:00 2001 From: freearhey Date: Wed, 7 Aug 2019 17:28:11 +0300 Subject: [PATCH] Update util.js - added getBasename() function - added addToCache() function - added checkCache() function - added getUrlPath() function --- helpers/util.js | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/helpers/util.js b/helpers/util.js index c147f3659a..39e1704603 100644 --- a/helpers/util.js +++ b/helpers/util.js @@ -3,7 +3,10 @@ const path = require('path') const M3U8FileParser = require('m3u8-file-parser') const https = require("https") const zlib = require("zlib") -const DOMParser = require('xmldom').DOMParser; +const DOMParser = require('xmldom').DOMParser +const urlParser = require('url') + +let cache = {} class Playlist { constructor(data) { @@ -167,6 +170,30 @@ function createFile(filename, data) { fs.writeFileSync(path.resolve(__dirname) + '/../' + filename, data) } +function getBasename(filename) { + return path.basename(filename, path.extname(filename)) +} + +function addToCache(url) { + let id = getUrlPath(url) + + cache[id] = true +} + +function checkCache(url) { + let id = getUrlPath(url) + + return cache.hasOwnProperty(id) +} + +function getUrlPath(u) { + let parsed = urlParser.parse(u) + let searchQuery = parsed.search || '' + + return parsed.host + parsed.pathname + searchQuery +} + + module.exports = { parsePlaylist, sortByTitle, @@ -174,5 +201,8 @@ module.exports = { createFile, readFile, loadEPG, - createChannel + createChannel, + getBasename, + addToCache, + checkCache } \ No newline at end of file