-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex-compiled.js.map
1 lines (1 loc) · 12.9 KB
/
index-compiled.js.map
1
{"version":3,"sources":["index.js"],"names":[],"mappings":";;;;AAIA;;AAEA,IAAI,KAAK,QAAQ,IAAR,CAAL;;AAEJ,IAAI,OAAO,QAAQ,MAAR,CAAP;AACJ,IAAI,WAAW,QAAQ,KAAR,EAAe,KAAf;;AAEf,IAAI,MAAM,QAAQ,OAAR,CAAN;;AAEJ,MAAM,IAAN,CAAU;;;;;;;;;;AAUN,gBAAY,OAAZ,EAAoB;AAChB,YAAI,MAAM,OAAN,CAAc,OAAd,CAAJ,EAA2B;AACvB,sBAAU,EAAC,SAAS,OAAT,EAAX,CADuB;SAA3B;;AAIA,YAAI,CAAC,QAAQ,SAAR,EAAkB;AACnB,oBAAQ,SAAR,GAAoB,IAAE,EAAF,GAAK,EAAL,GAAQ,EAAR,GAAW,IAAX,CADD;SAAvB;;AAIA,YAAI,CAAC,QAAQ,OAAR,EAAgB;AACjB,oBAAQ,OAAR,GAAkB,EAAlB,CADiB;SAArB;;AAIA,aAAK,OAAL,GAAe,OAAf,CAbgB;KAApB;;;;;;;;;;;;;;;;AAVM,iBAwCN,CAAc,OAAd,EAAuB,QAAvB,EAAgC;AAC5B,YAAI,SAAS,OAAC,CAAQ,KAAR,IAAiB,QAAQ,KAAR,CAAc,KAAd,GAAuB,KAAK,cAAL,GAAsB,KAAK,OAAL,CADhD;;AAG5B,eAAO,IAAP,CAAY,IAAZ,EACK,IADL,CACU,WAAU;;;AAGZ,qBAAS,SAAT,CAAmB,cAAnB,EAAmC,iBAAnC,EAHY;AAIZ,qBAAS,SAAT,CAAmB,qBAAnB,EAA0C,kCAA1C,EAJY;AAKZ,qBAAS,OAAT,GAAmB,OAAnB,CALY;AAMZ,qBAAS,KAAT,CAAe,OAAf,EANY;AAOZ,qBAAS,GAAT,GAPY;SAAV,CADV,CAUK,KAVL,CAUW,SAAS;AACZ,qBAAS,MAAT,C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Q7C,oBAAI,EAAJ,CAAO,MAAP,EAAe,UAAU,KAAV,EAAiB;AAC5B,4BAAQ,KAAR,CAD4B;iBAAjB,CAAf,CAR6C;AAW7C,oBAAI,EAAJ,CAAO,KAAP,EAAc,YAAY;AACtB,4BAAQ,IAAR,EADsB;iBAAZ,CAAd,CAX6C;aAAf,CAA9B,CADiB;;AAiBrB,gBAAI,EAAJ,CAAO,OAAP,EAAgB,UAAU,CAAV,EAAa;AACzB,uBAAO,CAAP,EADyB;aAAb,CAAhB,CAjBqB;AAoBrB,gBAAI,GAAJ,GApBqB;SAAzB,CADJ,CADkB;KAAtB;;AA2BA,WAAO,UAAP,CAAkB,GAAlB,EAAsB;AAClB,YAAI,IAAI,UAAJ,CAAe,SAAf,KAA2B,IAAI,UAAJ,CAAe,SAAf,CAA3B,EAAqD;AACrD,mBAAO,KAAK,UAAL,CAAgB,GAAhB,CAAP,CADqD;SAAzD;;AAIA,eAAO,KAAK,SAAL,CAAe,GAAf,CAAP,CALkB;KAAtB;CA1OJ;;AAmPA,KAAK,eAAL,GAAuB,QAAvB;AACA,KAAK,oBAAL,GAA4B,QAA5B;AACA,KAAK,qBAAL,GAA6B,QAA7B;;AAEA,KAAK,OAAL,GAAe,QAAQ,WAAR,CAAf;;AAEA,OAAO,OAAP,GAAiB,IAAjB","file":"index-compiled.js","sourcesContent":["/**\n * Created by solvek on 08.02.16.\n */\n\n\"use strict\";\n\nvar fs = require('fs');\n\nvar http = require(\"http\");\nvar urlParse = require(\"url\").parse;\n\nvar m3u = require('m3ujs');\n\nclass Pled{\n /**\n * @param {Object|string[]} options Pled options object or array of sources\n * @param {string[]} options.sources Sources of m3u files. Each source is either a path\n * to local file of a url to an http file (starting from \"http://\" or \"https://\")\n * @param {FilterFunction[]} [options.filters] Sequence of filters\n * @param {string} [options.cachePath] Path to cache file\n * @param {int} [options.cacheTime=5*24*60*60*1000] Time for cache in milliseconds. By default 5 days\n * to not use the cache but regenerate content (however resulting content still can be saved to the cache)\n */\n constructor(options){\n if (Array.isArray(options)){\n options = {sources: options};\n }\n\n if (!options.cacheTime){\n options.cacheTime = 5*24*60*60*1000;\n }\n\n if (!options.filters){\n options.filters = [];\n }\n\n this.options = options;\n }\n\n /**\n * @name FilterFunction\n * @function\n * @param {Object} stream Stream object\n * @param {string} [source] Source\n * @param {Object[]} [collected] Already collected streams for result\n * @return Either modified Stream Object of undefined. Undefined means that the stream should not be outputted in result.\n */\n\n /**\n * It is possible to use Pled in pair with [Express.js]{@link http://expressjs.com/}. Handles HTTP request.\n * Query string can have \"force=true\" (or request.query.force true) query parameter. This allows to force reload data (ignoring cache)\n * See `samples` directory for an example.\n */\n handleRequest(request, response){\n let loader = (request.query && request.query.force) ? this.executeNoCache : this.execute;\n\n loader.call(this)\n .then(content =>{\n //console.log(`Received content: ${content}`);\n //response.status(200);\n response.setHeader('Content-type', 'audio/x-mpegurl');\n response.setHeader(\"Content-Disposition\", \"attachment;filename=playlist.m3u\");\n response.charset = 'UTF-8';\n response.write(content);\n response.end();\n })\n .catch(error => {\n response.status(500);\n response.send(\"Failed to generate the playlist.m3u. Error: \"+error.message);\n });\n }\n\n /**\n * Processes play list sources and generates resulting playlist as string\n * If up to date cache content is available then cache will be returned without reloading\n * @returns {Promise<string>} Promise with a string value - content of m3u\n */\n execute(){\n if (!this.options.cachePath){\n return this.executeNoCache();\n }\n\n let obj = this;\n\n return this.loadCache()\n .then(cache => {\n if (cache.status == Pled.CACHE_STATUS_OK){\n return cache.content;\n }\n\n return obj.executeNoCache();\n });\n }\n\n /**\n * Creates content from sources omitting cache\n * @returns {Promise<string>} Promise with a string value - content of m3u\n */\n executeNoCache(){\n let obj = this;\n return this._handleSourceTail(0, {tracks: []})\n .then(result => {\n let content = m3u.format(result);\n if (obj.options.cachePath){\n return obj.saveCache(content);\n }\n return content;\n });\n }\n\n /**\n * @typedef CacheStatus\n * @type Object\n * @property {Symbol} status Cache status: CACHE_STATUS_OK, CACHE_STATUS_MISSING, CACHE_STATUS_OUTDATED\n * @property {string} [content] Optional content. Specified only if cache status is CACHE_STATUS_OK\n */\n\n /**\n * Loads playlist from cache file.\n * @returns {Promise<CacheStatus>}\n */\n loadCache(){\n let options = this.options;\n\n if (!options.cachePath){\n return Promise.reject(new Error(\"Path to cache file not specified\"));\n }\n\n return new Promise(function (resolve) {\n fs.stat(options.cachePath, (err, stat) => {\n if (err){\n resolve({status : Pled.CACHE_STATUS_MISSING});\n return;\n }\n\n let now = new Date();\n let age = now - stat.mtime;\n\n //console.log(`Cache time: ${options.cacheTime}, now: ${now}, file time: ${stat.mtime}, age: ${age}`);\n\n if (age > options.cacheTime){\n resolve({status : Pled.CACHE_STATUS_OUTDATED});\n return;\n }\n\n resolve(Pled.loadLocal(options.cachePath)\n .then(content => {\n return {status: Pled.CACHE_STATUS_OK, content: content};\n }));\n });\n });\n }\n\n saveCache(content){\n let obj = this;\n return new Promise(\n function(resolve, reject){\n fs.writeFile(obj.options.cachePath, content, err => {\n if (err) {\n reject(err);\n }\n else {\n resolve(content);\n }\n });\n });\n }\n\n _handleSourceTail(sourceIdx, result){\n if (sourceIdx >= this.options.sources.length){\n return result;\n }\n\n let source = this.options.sources[sourceIdx];\n let obj = this;\n\n return this._handleSource(source, result)\n .then(function(){\n return obj._handleSourceTail(sourceIdx+1, result);\n });\n }\n\n _handleSource(source, result){\n let filters = this.options.filters;\n\n return Pled.loadSource(source)\n .then(content => {\n let parsed = m3u.parse(content);\n var filter;\n\n parsed.tracks.forEach(track => {\n for(var idx in filters){\n filter = filters[idx];\n\n track = filter(track, source, result);\n\n if (!track) break;\n }\n\n if (track){\n result.tracks.push(track);\n }\n });\n });\n }\n\n static loadLocal(path){\n return new Promise(\n function(resolve, reject) {\n fs.readFile(path, 'utf8', (err, data) => {\n if (err) {\n reject(err);\n }\n else {\n resolve(data);\n }\n });\n });\n }\n\n static loadRemote(url){\n return new Promise(\n function(resolve, reject){\n var req = http.get(urlParse(url), function (res) {\n if (res.statusCode !== 200) {\n reject(new Error(\"Http returned status: \"+req.statusCode));\n return;\n }\n\n var data = '';\n\n res.on('data', function (chunk) {\n data += chunk;\n });\n res.on('end', function () {\n resolve(data);\n });\n });\n\n req.on('error', function (e) {\n reject(e);\n });\n req.end();\n }\n );\n }\n\n static loadSource(url){\n if (url.startsWith('http://')||url.startsWith('http://')){\n return Pled.loadRemote(url);\n }\n\n return Pled.loadLocal(url);\n }\n}\n\nPled.CACHE_STATUS_OK = Symbol();\nPled.CACHE_STATUS_MISSING = Symbol();\nPled.CACHE_STATUS_OUTDATED = Symbol();\n\nPled.filters = require('./filters');\n\nmodule.exports = Pled;"]}