mirror of
https://github.com/iptv-org/iptv.git
synced 2025-05-13 02:20:03 -04:00
Update util.js
- added getBasename() function - added addToCache() function - added checkCache() function - added getUrlPath() function
This commit is contained in:
parent
08c5b93906
commit
5f03e6eca6
1 changed files with 32 additions and 2 deletions
|
@ -3,7 +3,10 @@ const path = require('path')
|
||||||
const M3U8FileParser = require('m3u8-file-parser')
|
const M3U8FileParser = require('m3u8-file-parser')
|
||||||
const https = require("https")
|
const https = require("https")
|
||||||
const zlib = require("zlib")
|
const zlib = require("zlib")
|
||||||
const DOMParser = require('xmldom').DOMParser;
|
const DOMParser = require('xmldom').DOMParser
|
||||||
|
const urlParser = require('url')
|
||||||
|
|
||||||
|
let cache = {}
|
||||||
|
|
||||||
class Playlist {
|
class Playlist {
|
||||||
constructor(data) {
|
constructor(data) {
|
||||||
|
@ -167,6 +170,30 @@ function createFile(filename, data) {
|
||||||
fs.writeFileSync(path.resolve(__dirname) + '/../' + 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 = {
|
module.exports = {
|
||||||
parsePlaylist,
|
parsePlaylist,
|
||||||
sortByTitle,
|
sortByTitle,
|
||||||
|
@ -174,5 +201,8 @@ module.exports = {
|
||||||
createFile,
|
createFile,
|
||||||
readFile,
|
readFile,
|
||||||
loadEPG,
|
loadEPG,
|
||||||
createChannel
|
createChannel,
|
||||||
|
getBasename,
|
||||||
|
addToCache,
|
||||||
|
checkCache
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue