Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import urlencode from 'urlencode';
urlencode('苏千'); // default is utf8
urlencode('苏千', 'gbk'); // '%CB%D5%C7%A7'
// decode gbk
urlencode.decode('%CB%D5%C7%A7', 'gbk'); // '苏千'
// parse gbk querystring
urlencode.parse('nick=%CB%D5%C7%A7', {charset: 'gbk'}); // {nick: '苏千'}
// stringify obj with gbk encoding
const str = 'x[y][0][v][w]=' + urlencode('雾空', 'gbk'); // x[y][0][v][w]=%CE%ED%BF%D5
const obj = {x: {y : [{v : {w : '雾空'}}]}};
urlencode.stringify(obj, {charset: 'gbk'});
HttpProtocolBase.prototype._prepareRequest = function(config) {
config.requestPrepared = true;
var path;
var query = urlencode.stringify(config.query, {
charset: config.encoding
});
if (query) {
// didn't handle # situation since backend should not get a hash tag
if (config.path.indexOf('?') === -1) {
path = config.path + '?' + query;
} else {
path = config.path + '&' + query;
}
} else {
path = config.path;
}
if (config.disableGzip) {
if (config.headers && config.headers['accept-encoding']) {
// parse url & its protocol
var urlObject = urlHelper.parse(url);
var protocol = urlObject.protocol;
// charset
var charset = opts.charset || "utf8";
// data
var bodyEncode = null;
var data = opts.data || "";
if(data instanceof Buffer) {
// if it's raw data
bodyEncode = "binary";
} else if(typeof data === "object") {
// if it's object then stringify it
data = urlencode.stringify(data, { charset: charset });
}
// header
var header = this._combineHeader(opts.header || {});
if(!header["content-length"]) {
header["content-length"] = (Buffer.isBuffer(data) ? data.length : Buffer.byteLength(data));
}
if(!header["content-type"] && method.toLowerCase() !== "get") {
header["content-type"] = "application/x-www-form-urlencoded";
}
// the returned object
var emitter = new EventEmitter();
var p = ((protocol === "http:") ? http : ((protocol === "https:") ? https : null));
if(!p) {
_tryExtractHls(script) {
const parts = script.match(/fhls = "([^"]+)"/)
if(parts && parts.length > 1) {
const manifestUrl = this._extractManifest(parts[1])
return [{
manifestUrl,
downloadUrl: '/videoStreamConcat?' + urlencode.stringify({ manifestUrl})
}]
}
}
details.files.forEach((file) => {
const extractor = {
type: 'streamguard',
params: {
referer: resultsId
}
}
file.extractor = extractor
file.downloadUrl = '/videoStreamConcat?' + urlencode.stringify({
manifestUrl: file.manifestUrl,
extractor
})
})
transform: ($el) => {
const script = $el.toArray()[0].children[0].data
const matches = script.match(/var filmSource = "([^]+)" \|\|/)
if(!matches) return []
const manifestUrl = matches[1]
const extractor = { type: 'direct' }
return [{
id: 0,
extractor,
downloadUrl: '/videoStreamConcat?' + urlencode.stringify({
manifestUrl,
extractor
}),
manifestUrl
}]
}
}
function getExtractorUrl(url, extractor) {
const { type, params } = extractor
if (!extractor) return url
return `http://${HOSTNAME}:${WEB_PORT}/extractVideo?` + urlencode.stringify({
type,
url,
...params
})
}