redgifs-downloader
Version:
This is a simple utiliy which allows you to download all videos from any user or search term on RedGIFs.
3 lines (2 loc) • 38.3 kB
JavaScript
!function(e,t,r,n,o,s,i,a,u,c,f,l,d){"use strict";function p(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var h=p(t),m=p(r),g=p(n),v=p(o),y=p(s),b=p(i),w=p(a),_=p(u),E=p(c),x=p(f),R=p(l),k=p(d),O=function(e,t){return function(){for(var r=new Array(arguments.length),n=0;n<r.length;n++)r[n]=arguments[n];return e.apply(t,r)}},S=Object.prototype.toString;function j(e){return"[object Array]"===S.call(e)}function T(e){return void 0===e}function A(e){return null!==e&&"object"==typeof e}function C(e){if("[object Object]"!==S.call(e))return!1;var t=Object.getPrototypeOf(e);return null===t||t===Object.prototype}function B(e){return"[object Function]"===S.call(e)}function U(e,t){if(null!=e)if("object"!=typeof e&&(e=[e]),j(e))for(var r=0,n=e.length;r<n;r++)t.call(null,e[r],r,e);else for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.call(null,e[o],o,e)}var L={isArray:j,isArrayBuffer:function(e){return"[object ArrayBuffer]"===S.call(e)},isBuffer:function(e){return null!==e&&!T(e)&&null!==e.constructor&&!T(e.constructor)&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)},isFormData:function(e){return"undefined"!=typeof FormData&&e instanceof FormData},isArrayBufferView:function(e){return"undefined"!=typeof ArrayBuffer&&ArrayBuffer.isView?ArrayBuffer.isView(e):e&&e.buffer&&e.buffer instanceof ArrayBuffer},isString:function(e){return"string"==typeof e},isNumber:function(e){return"number"==typeof e},isObject:A,isPlainObject:C,isUndefined:T,isDate:function(e){return"[object Date]"===S.call(e)},isFile:function(e){return"[object File]"===S.call(e)},isBlob:function(e){return"[object Blob]"===S.call(e)},isFunction:B,isStream:function(e){return A(e)&&B(e.pipe)},isURLSearchParams:function(e){return"undefined"!=typeof URLSearchParams&&e instanceof URLSearchParams},isStandardBrowserEnv:function(){return("undefined"==typeof navigator||"ReactNative"!==navigator.product&&"NativeScript"!==navigator.product&&"NS"!==navigator.product)&&("undefined"!=typeof window&&"undefined"!=typeof document)},forEach:U,merge:function e(){var t={};function r(r,n){C(t[n])&&C(r)?t[n]=e(t[n],r):C(r)?t[n]=e({},r):j(r)?t[n]=r.slice():t[n]=r}for(var n=0,o=arguments.length;n<o;n++)U(arguments[n],r);return t},extend:function(e,t,r){return U(t,(function(t,n){e[n]=r&&"function"==typeof t?O(t,r):t})),e},trim:function(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")},stripBOM:function(e){return 65279===e.charCodeAt(0)&&(e=e.slice(1)),e}};function N(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}var D=function(e,t,r){if(!t)return e;var n;if(r)n=r(t);else if(L.isURLSearchParams(t))n=t.toString();else{var o=[];L.forEach(t,(function(e,t){null!=e&&(L.isArray(e)?t+="[]":e=[e],L.forEach(e,(function(e){L.isDate(e)?e=e.toISOString():L.isObject(e)&&(e=JSON.stringify(e)),o.push(N(t)+"="+N(e))})))})),n=o.join("&")}if(n){var s=e.indexOf("#");-1!==s&&(e=e.slice(0,s)),e+=(-1===e.indexOf("?")?"?":"&")+n}return e};function q(){this.handlers=[]}q.prototype.use=function(e,t,r){return this.handlers.push({fulfilled:e,rejected:t,synchronous:!!r&&r.synchronous,runWhen:r?r.runWhen:null}),this.handlers.length-1},q.prototype.eject=function(e){this.handlers[e]&&(this.handlers[e]=null)},q.prototype.forEach=function(e){L.forEach(this.handlers,(function(t){null!==t&&e(t)}))};var P=q,M=function(e,t){L.forEach(e,(function(r,n){n!==t&&n.toUpperCase()===t.toUpperCase()&&(e[t]=r,delete e[n])}))},$=function(e,t,r,n,o){return e.config=t,r&&(e.code=r),e.request=n,e.response=o,e.isAxiosError=!0,e.toJSON=function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:this.config,code:this.code}},e},F=function(e,t,r,n,o){var s=new Error(e);return $(s,t,r,n,o)},z=function(e,t,r){var n=r.config.validateStatus;r.status&&n&&!n(r.status)?t(F("Request failed with status code "+r.status,r.config,null,r.request,r)):e(r)},I=L.isStandardBrowserEnv()?{write:function(e,t,r,n,o,s){var i=[];i.push(e+"="+encodeURIComponent(t)),L.isNumber(r)&&i.push("expires="+new Date(r).toGMTString()),L.isString(n)&&i.push("path="+n),L.isString(o)&&i.push("domain="+o),!0===s&&i.push("secure"),document.cookie=i.join("; ")},read:function(e){var t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove:function(e){this.write(e,"",Date.now()-864e5)}}:{write:function(){},read:function(){return null},remove:function(){}},H=function(e,t){return e&&!function(e){return/^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(e)}(t)?function(e,t){return t?e.replace(/\/+$/,"")+"/"+t.replace(/^\/+/,""):e}(e,t):t},J=["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"],G=L.isStandardBrowserEnv()?function(){var e,t=/(msie|trident)/i.test(navigator.userAgent),r=document.createElement("a");function n(e){var n=e;return t&&(r.setAttribute("href",n),n=r.href),r.setAttribute("href",n),{href:r.href,protocol:r.protocol?r.protocol.replace(/:$/,""):"",host:r.host,search:r.search?r.search.replace(/^\?/,""):"",hash:r.hash?r.hash.replace(/^#/,""):"",hostname:r.hostname,port:r.port,pathname:"/"===r.pathname.charAt(0)?r.pathname:"/"+r.pathname}}return e=n(window.location.href),function(t){var r=L.isString(t)?n(t):t;return r.protocol===e.protocol&&r.host===e.host}}():function(){return!0},W=function(e){return new Promise((function(t,r){var n=e.data,o=e.headers,s=e.responseType;L.isFormData(n)&&delete o["Content-Type"];var i=new XMLHttpRequest;if(e.auth){var a=e.auth.username||"",u=e.auth.password?unescape(encodeURIComponent(e.auth.password)):"";o.Authorization="Basic "+btoa(a+":"+u)}var c=H(e.baseURL,e.url);function f(){if(i){var n,o,a,u,c,f="getAllResponseHeaders"in i?(n=i.getAllResponseHeaders(),c={},n?(L.forEach(n.split("\n"),(function(e){if(u=e.indexOf(":"),o=L.trim(e.substr(0,u)).toLowerCase(),a=L.trim(e.substr(u+1)),o){if(c[o]&&J.indexOf(o)>=0)return;c[o]="set-cookie"===o?(c[o]?c[o]:[]).concat([a]):c[o]?c[o]+", "+a:a}})),c):c):null,l={data:s&&"text"!==s&&"json"!==s?i.response:i.responseText,status:i.status,statusText:i.statusText,headers:f,config:e,request:i};z(t,r,l),i=null}}if(i.open(e.method.toUpperCase(),D(c,e.params,e.paramsSerializer),!0),i.timeout=e.timeout,"onloadend"in i?i.onloadend=f:i.onreadystatechange=function(){i&&4===i.readyState&&(0!==i.status||i.responseURL&&0===i.responseURL.indexOf("file:"))&&setTimeout(f)},i.onabort=function(){i&&(r(F("Request aborted",e,"ECONNABORTED",i)),i=null)},i.onerror=function(){r(F("Network Error",e,null,i)),i=null},i.ontimeout=function(){var t="timeout of "+e.timeout+"ms exceeded";e.timeoutErrorMessage&&(t=e.timeoutErrorMessage),r(F(t,e,e.transitional&&e.transitional.clarifyTimeoutError?"ETIMEDOUT":"ECONNABORTED",i)),i=null},L.isStandardBrowserEnv()){var l=(e.withCredentials||G(c))&&e.xsrfCookieName?I.read(e.xsrfCookieName):void 0;l&&(o[e.xsrfHeaderName]=l)}"setRequestHeader"in i&&L.forEach(o,(function(e,t){void 0===n&&"content-type"===t.toLowerCase()?delete o[t]:i.setRequestHeader(t,e)})),L.isUndefined(e.withCredentials)||(i.withCredentials=!!e.withCredentials),s&&"json"!==s&&(i.responseType=e.responseType),"function"==typeof e.onDownloadProgress&&i.addEventListener("progress",e.onDownloadProgress),"function"==typeof e.onUploadProgress&&i.upload&&i.upload.addEventListener("progress",e.onUploadProgress),e.cancelToken&&e.cancelToken.promise.then((function(e){i&&(i.abort(),r(e),i=null)})),n||(n=null),i.send(n)}))};function X(e,t){return e(t={exports:{}},t.exports),t.exports}var V=1e3,Y=60*V,K=60*Y,Z=24*K,Q=365.25*Z,ee=function(e,t){t=t||{};var r=typeof e;if("string"===r&&e.length>0)return function(e){if((e=String(e)).length>100)return;var t=/^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(e);if(!t)return;var r=parseFloat(t[1]);switch((t[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return r*Q;case"days":case"day":case"d":return r*Z;case"hours":case"hour":case"hrs":case"hr":case"h":return r*K;case"minutes":case"minute":case"mins":case"min":case"m":return r*Y;case"seconds":case"second":case"secs":case"sec":case"s":return r*V;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return r;default:return}}(e);if("number"===r&&!1===isNaN(e))return t.long?function(e){return te(e,Z,"day")||te(e,K,"hour")||te(e,Y,"minute")||te(e,V,"second")||e+" ms"}(e):function(e){if(e>=Z)return Math.round(e/Z)+"d";if(e>=K)return Math.round(e/K)+"h";if(e>=Y)return Math.round(e/Y)+"m";if(e>=V)return Math.round(e/V)+"s";return e+"ms"}(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))};function te(e,t,r){if(!(e<t))return e<1.5*t?Math.floor(e/t)+" "+r:Math.ceil(e/t)+" "+r+"s"}var re=X((function(e,t){var r;function n(e){function n(){if(n.enabled){var e=n,o=+new Date,s=o-(r||o);e.diff=s,e.prev=r,e.curr=o,r=o;for(var i=new Array(arguments.length),a=0;a<i.length;a++)i[a]=arguments[a];i[0]=t.coerce(i[0]),"string"!=typeof i[0]&&i.unshift("%O");var u=0;i[0]=i[0].replace(/%([a-zA-Z%])/g,(function(r,n){if("%%"===r)return r;u++;var o=t.formatters[n];if("function"==typeof o){var s=i[u];r=o.call(e,s),i.splice(u,1),u--}return r})),t.formatArgs.call(e,i);var c=n.log||t.log||console.log.bind(console);c.apply(e,i)}}return n.namespace=e,n.enabled=t.enabled(e),n.useColors=t.useColors(),n.color=function(e){var r,n=0;for(r in e)n=(n<<5)-n+e.charCodeAt(r),n|=0;return t.colors[Math.abs(n)%t.colors.length]}(e),"function"==typeof t.init&&t.init(n),n}(t=e.exports=n.debug=n.default=n).coerce=function(e){return e instanceof Error?e.stack||e.message:e},t.disable=function(){t.enable("")},t.enable=function(e){t.save(e),t.names=[],t.skips=[];for(var r=("string"==typeof e?e:"").split(/[\s,]+/),n=r.length,o=0;o<n;o++)r[o]&&("-"===(e=r[o].replace(/\*/g,".*?"))[0]?t.skips.push(new RegExp("^"+e.substr(1)+"$")):t.names.push(new RegExp("^"+e+"$")))},t.enabled=function(e){var r,n;for(r=0,n=t.skips.length;r<n;r++)if(t.skips[r].test(e))return!1;for(r=0,n=t.names.length;r<n;r++)if(t.names[r].test(e))return!0;return!1},t.humanize=ee,t.names=[],t.skips=[],t.formatters={}}));re.coerce,re.disable,re.enable,re.enabled,re.humanize,re.names,re.skips,re.formatters;var ne=X((function(e,t){function r(){var e;try{e=t.storage.debug}catch(e){}return!e&&"undefined"!=typeof process&&"env"in process&&(e=process.env.DEBUG),e}(t=e.exports=re).log=function(){return"object"==typeof console&&console.log&&Function.prototype.apply.call(console.log,console,arguments)},t.formatArgs=function(e){var r=this.useColors;if(e[0]=(r?"%c":"")+this.namespace+(r?" %c":" ")+e[0]+(r?"%c ":" ")+"+"+t.humanize(this.diff),!r)return;var n="color: "+this.color;e.splice(1,0,n,"color: inherit");var o=0,s=0;e[0].replace(/%[a-zA-Z%]/g,(function(e){"%%"!==e&&(o++,"%c"===e&&(s=o))})),e.splice(s,0,n)},t.save=function(e){try{null==e?t.storage.removeItem("debug"):t.storage.debug=e}catch(e){}},t.load=r,t.useColors=function(){if("undefined"!=typeof window&&window.process&&"renderer"===window.process.type)return!0;return"undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},t.storage="undefined"!=typeof chrome&&void 0!==chrome.storage?chrome.storage.local:function(){try{return window.localStorage}catch(e){}}(),t.colors=["lightseagreen","forestgreen","goldenrod","dodgerblue","darkorchid","crimson"],t.formatters.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}},t.enable(r())}));ne.log,ne.formatArgs,ne.save,ne.load,ne.useColors,ne.storage,ne.colors;var oe=X((function(e,t){(t=e.exports=re).init=function(e){e.inspectOpts={};for(var r=Object.keys(t.inspectOpts),n=0;n<r.length;n++)e.inspectOpts[r[n]]=t.inspectOpts[r[n]]},t.log=function(){return n.write(w.default.format.apply(w.default,arguments)+"\n")},t.formatArgs=function(e){var r=this.namespace;if(this.useColors){var n=this.color,o=" [3"+n+";1m"+r+" [0m";e[0]=o+e[0].split("\n").join("\n"+o),e.push("[3"+n+"m+"+t.humanize(this.diff)+"[0m")}else e[0]=(new Date).toUTCString()+" "+r+" "+e[0]},t.save=function(e){null==e?delete process.env.DEBUG:process.env.DEBUG=e},t.load=o,t.useColors=function(){return"colors"in t.inspectOpts?Boolean(t.inspectOpts.colors):b.default.isatty(r)},t.colors=[6,2,3,4,5,1],t.inspectOpts=Object.keys(process.env).filter((function(e){return/^debug_/i.test(e)})).reduce((function(e,t){var r=t.substring(6).toLowerCase().replace(/_([a-z])/g,(function(e,t){return t.toUpperCase()})),n=process.env[t];return n=!!/^(yes|on|true|enabled)$/i.test(n)||!/^(no|off|false|disabled)$/i.test(n)&&("null"===n?null:Number(n)),e[r]=n,e}),{});var r=parseInt(process.env.DEBUG_FD,10)||2;1!==r&&2!==r&&w.default.deprecate((function(){}),"except for stderr(2) and stdout(1), any other usage of DEBUG_FD is deprecated. Override debug.log if you want to use a different log function (https://git.io/debug_fd)")();var n=1===r?process.stdout:2===r?process.stderr:function(e){var t;switch(process.binding("tty_wrap").guessHandleType(e)){case"TTY":(t=new b.default.WriteStream(e))._type="tty",t._handle&&t._handle.unref&&t._handle.unref();break;case"FILE":var r=_.default;(t=new r.SyncWriteStream(e,{autoClose:!1}))._type="fs";break;case"PIPE":case"TCP":var n=E.default;(t=new n.Socket({fd:e,readable:!1,writable:!0})).readable=!1,t.read=null,t._type="pipe",t._handle&&t._handle.unref&&t._handle.unref();break;default:throw new Error("Implement me. Unknown stream file type!")}return t.fd=e,t._isStdio=!0,t}(r);function o(){return process.env.DEBUG}t.formatters.o=function(e){return this.inspectOpts.colors=this.useColors,w.default.inspect(e,this.inspectOpts).split("\n").map((function(e){return e.trim()})).join(" ")},t.formatters.O=function(e){return this.inspectOpts.colors=this.useColors,w.default.inspect(e,this.inspectOpts)},t.enable(o())}));oe.init,oe.log,oe.formatArgs,oe.save,oe.load,oe.useColors,oe.colors,oe.inspectOpts,X((function(e){"undefined"!=typeof process&&"renderer"===process.type?e.exports=ne:e.exports=oe}));var se=g.default.URL,ie=v.default.Writable,ae=["abort","aborted","connect","error","socket","timeout"],ue=Object.create(null);ae.forEach((function(e){ue[e]=function(t,r,n){this._redirectable.emit(e,t,r,n)}}));var ce=ye("ERR_FR_REDIRECTION_FAILURE",""),fe=ye("ERR_FR_TOO_MANY_REDIRECTS","Maximum number of redirects exceeded"),le=ye("ERR_FR_MAX_BODY_LENGTH_EXCEEDED","Request body larger than maxBodyLength limit"),de=ye("ERR_STREAM_WRITE_AFTER_END","write after end");function pe(e,t){ie.call(this),this._sanitizeOptions(e),this._options=e,this._ended=!1,this._ending=!1,this._redirectCount=0,this._redirects=[],this._requestBodyLength=0,this._requestBodyBuffers=[],t&&this.on("response",t);var r=this;this._onNativeResponse=function(e){r._processResponse(e)},this._performRequest()}function he(e){var t={maxRedirects:21,maxBodyLength:10485760},r={};return Object.keys(e).forEach((function(n){var o=n+":",s=r[o]=e[n],i=t[n]=Object.create(s);Object.defineProperties(i,{request:{value:function(e,n,s){if("string"==typeof e){var i=e;try{e=ge(new se(i))}catch(t){e=g.default.parse(i)}}else se&&e instanceof se?e=ge(e):(s=n,n=e,e={protocol:o});return"function"==typeof n&&(s=n,n=null),(n=Object.assign({maxRedirects:t.maxRedirects,maxBodyLength:t.maxBodyLength},e,n)).nativeProtocols=r,y.default.equal(n.protocol,o,"protocol mismatch"),new pe(n,s)},configurable:!0,enumerable:!0,writable:!0},get:{value:function(e,t,r){var n=i.request(e,t,r);return n.end(),n},configurable:!0,enumerable:!0,writable:!0}})})),t}function me(){}function ge(e){var t={protocol:e.protocol,hostname:e.hostname.startsWith("[")?e.hostname.slice(1,-1):e.hostname,hash:e.hash,search:e.search,pathname:e.pathname,path:e.pathname+e.search,href:e.href};return""!==e.port&&(t.port=Number(e.port)),t}function ve(e,t){var r;for(var n in t)e.test(n)&&(r=t[n],delete t[n]);return r}function ye(e,t){function r(e){Error.captureStackTrace(this,this.constructor),this.message=e||t}return r.prototype=new Error,r.prototype.constructor=r,r.prototype.name="Error ["+e+"]",r.prototype.code=e,r}function be(e){for(var t=0;t<ae.length;t++)e.removeListener(ae[t],ue[ae[t]]);e.on("error",me),e.abort()}pe.prototype=Object.create(ie.prototype),pe.prototype.abort=function(){be(this._currentRequest),this.emit("abort")},pe.prototype.write=function(e,t,r){if(this._ending)throw new de;if(!("string"==typeof e||"object"==typeof e&&"length"in e))throw new TypeError("data should be a string, Buffer or Uint8Array");"function"==typeof t&&(r=t,t=null),0!==e.length?this._requestBodyLength+e.length<=this._options.maxBodyLength?(this._requestBodyLength+=e.length,this._requestBodyBuffers.push({data:e,encoding:t}),this._currentRequest.write(e,t,r)):(this.emit("error",new le),this.abort()):r&&r()},pe.prototype.end=function(e,t,r){if("function"==typeof e?(r=e,e=t=null):"function"==typeof t&&(r=t,t=null),e){var n=this,o=this._currentRequest;this.write(e,t,(function(){n._ended=!0,o.end(null,null,r)})),this._ending=!0}else this._ended=this._ending=!0,this._currentRequest.end(null,null,r)},pe.prototype.setHeader=function(e,t){this._options.headers[e]=t,this._currentRequest.setHeader(e,t)},pe.prototype.removeHeader=function(e){delete this._options.headers[e],this._currentRequest.removeHeader(e)},pe.prototype.setTimeout=function(e,t){var r=this;function n(t){t.setTimeout(e),t.removeListener("timeout",t.destroy),t.addListener("timeout",t.destroy)}function o(t){r._timeout&&clearTimeout(r._timeout),r._timeout=setTimeout((function(){r.emit("timeout"),s()}),e),n(t)}function s(){r._timeout&&(clearTimeout(r._timeout),r._timeout=null),t&&r.removeListener("timeout",t),r.socket||r._currentRequest.removeListener("socket",o)}return t&&this.on("timeout",t),this.socket?o(this.socket):this._currentRequest.once("socket",o),this.on("socket",n),this.once("response",s),this.once("error",s),this},["flushHeaders","getHeader","setNoDelay","setSocketKeepAlive"].forEach((function(e){pe.prototype[e]=function(t,r){return this._currentRequest[e](t,r)}})),["aborted","connection","socket"].forEach((function(e){Object.defineProperty(pe.prototype,e,{get:function(){return this._currentRequest[e]}})})),pe.prototype._sanitizeOptions=function(e){if(e.headers||(e.headers={}),e.host&&(e.hostname||(e.hostname=e.host),delete e.host),!e.pathname&&e.path){var t=e.path.indexOf("?");t<0?e.pathname=e.path:(e.pathname=e.path.substring(0,t),e.search=e.path.substring(t))}},pe.prototype._performRequest=function(){var e=this._options.protocol,t=this._options.nativeProtocols[e];if(t){if(this._options.agents){var r=e.substr(0,e.length-1);this._options.agent=this._options.agents[r]}var n=this._currentRequest=t.request(this._options,this._onNativeResponse);this._currentUrl=g.default.format(this._options),n._redirectable=this;for(var o=0;o<ae.length;o++)n.on(ae[o],ue[ae[o]]);if(this._isRedirect){var s=0,i=this,a=this._requestBodyBuffers;!function e(t){if(n===i._currentRequest)if(t)i.emit("error",t);else if(s<a.length){var r=a[s++];n.finished||n.write(r.data,r.encoding,e)}else i._ended&&n.end()}()}}else this.emit("error",new TypeError("Unsupported protocol "+e))},pe.prototype._processResponse=function(e){var t=e.statusCode;this._options.trackRedirects&&this._redirects.push({url:this._currentUrl,headers:e.headers,statusCode:t});var r=e.headers.location;if(r&&!1!==this._options.followRedirects&&t>=300&&t<400){if(be(this._currentRequest),e.destroy(),++this._redirectCount>this._options.maxRedirects)return void this.emit("error",new fe);((301===t||302===t)&&"POST"===this._options.method||303===t&&!/^(?:GET|HEAD)$/.test(this._options.method))&&(this._options.method="GET",this._requestBodyBuffers=[],ve(/^content-/i,this._options.headers));var n=ve(/^host$/i,this._options.headers)||g.default.parse(this._currentUrl).hostname,o=g.default.resolve(this._currentUrl,r);this._isRedirect=!0;var s=g.default.parse(o);if(Object.assign(this._options,s),s.hostname!==n&&ve(/^authorization$/i,this._options.headers),"function"==typeof this._options.beforeRedirect){var i={headers:e.headers};try{this._options.beforeRedirect.call(null,this._options,i)}catch(e){return void this.emit("error",e)}this._sanitizeOptions(this._options)}try{this._performRequest()}catch(e){var a=new ce("Redirected request failed: "+e.message);a.cause=e,this.emit("error",a)}}else e.responseUrl=this._currentUrl,e.redirects=this._redirects,this.emit("response",e),this._requestBodyBuffers=[]};var we=he({http:h.default,https:m.default}),_e=he;we.wrap=_e;var Ee,xe="axios",Re="0.21.4",ke="Promise based HTTP client for the browser and node.js",Oe="index.js",Se={test:"grunt test",start:"node ./sandbox/server.js",build:"NODE_ENV=production grunt build",preversion:"npm test",version:"npm run build && grunt version && git add -A dist && git add CHANGELOG.md bower.json package.json",postversion:"git push && git push --tags",examples:"node ./examples/server.js",coveralls:"cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",fix:"eslint --fix lib/**/*.js"},je={type:"git",url:"https://github.com/axios/axios.git"},Te=["xhr","http","ajax","promise","node"],Ae="Matt Zabriskie",Ce={url:"https://github.com/axios/axios/issues"},Be="https://axios-http.com",Ue={coveralls:"^3.0.0","es6-promise":"^4.2.4",grunt:"^1.3.0","grunt-banner":"^0.6.0","grunt-cli":"^1.2.0","grunt-contrib-clean":"^1.1.0","grunt-contrib-watch":"^1.0.0","grunt-eslint":"^23.0.0","grunt-karma":"^4.0.0","grunt-mocha-test":"^0.13.3","grunt-ts":"^6.0.0-beta.19","grunt-webpack":"^4.0.2","istanbul-instrumenter-loader":"^1.0.0","jasmine-core":"^2.4.1",karma:"^6.3.2","karma-chrome-launcher":"^3.1.0","karma-firefox-launcher":"^2.1.0","karma-jasmine":"^1.1.1","karma-jasmine-ajax":"^0.1.13","karma-safari-launcher":"^1.0.0","karma-sauce-launcher":"^4.3.6","karma-sinon":"^1.0.5","karma-sourcemap-loader":"^0.3.8","karma-webpack":"^4.0.2","load-grunt-tasks":"^3.5.2",minimist:"^1.2.0",mocha:"^8.2.1",sinon:"^4.5.0","terser-webpack-plugin":"^4.2.3",typescript:"^4.0.5","url-search-params":"^0.10.0",webpack:"^4.44.2","webpack-dev-server":"^3.11.0"},Le={"./lib/adapters/http.js":"./lib/adapters/xhr.js"},Ne="dist/axios.min.js",De="dist/axios.min.js",qe="./index.d.ts",Pe={"follow-redirects":"^1.14.0"},Me=[{path:"./dist/axios.min.js",threshold:"5kB"}],$e={name:xe,version:Re,description:ke,main:Oe,scripts:Se,repository:je,keywords:Te,author:Ae,license:"MIT",bugs:Ce,homepage:Be,devDependencies:Ue,browser:Le,jsdelivr:Ne,unpkg:De,typings:qe,dependencies:Pe,bundlesize:Me},Fe=(Ee=Object.freeze({__proto__:null,name:xe,version:Re,description:ke,main:Oe,scripts:Se,repository:je,keywords:Te,author:Ae,license:"MIT",bugs:Ce,homepage:Be,devDependencies:Ue,browser:Le,jsdelivr:Ne,unpkg:De,typings:qe,dependencies:Pe,bundlesize:Me,default:$e}))&&Ee.default||Ee,ze=we.http,Ie=we.https,He=/https:?/;function Je(e,t,r){if(e.hostname=t.host,e.host=t.host,e.port=t.port,e.path=r,t.auth){var n=Buffer.from(t.auth.username+":"+t.auth.password,"utf8").toString("base64");e.headers["Proxy-Authorization"]="Basic "+n}e.beforeRedirect=function(e){e.headers.host=e.host,Je(e,t,e.href)}}var Ge=function(e){return new Promise((function(t,r){var n=function(e){t(e)},o=function(e){r(e)},s=e.data,i=e.headers;if("User-Agent"in i||"user-agent"in i?i["User-Agent"]||i["user-agent"]||(delete i["User-Agent"],delete i["user-agent"]):i["User-Agent"]="axios/"+Fe.version,s&&!L.isStream(s)){if(Buffer.isBuffer(s));else if(L.isArrayBuffer(s))s=Buffer.from(new Uint8Array(s));else{if(!L.isString(s))return o(F("Data after transformation must be a string, an ArrayBuffer, a Buffer, or a Stream",e));s=Buffer.from(s,"utf-8")}i["Content-Length"]=s.length}var a=void 0;e.auth&&(a=(e.auth.username||"")+":"+(e.auth.password||""));var u=H(e.baseURL,e.url),c=g.default.parse(u),f=c.protocol||"http:";if(!a&&c.auth){var l=c.auth.split(":");a=(l[0]||"")+":"+(l[1]||"")}a&&delete i.Authorization;var d=He.test(f),p=d?e.httpsAgent:e.httpAgent,v={path:D(c.path,e.params,e.paramsSerializer).replace(/^\?/,""),method:e.method.toUpperCase(),headers:i,agent:p,agents:{http:e.httpAgent,https:e.httpsAgent},auth:a};e.socketPath?v.socketPath=e.socketPath:(v.hostname=c.hostname,v.port=c.port);var y,b=e.proxy;if(!b&&!1!==b){var w=f.slice(0,-1)+"_proxy",_=process.env[w]||process.env[w.toUpperCase()];if(_){var E=g.default.parse(_),R=process.env.no_proxy||process.env.NO_PROXY,k=!0;if(R){var O=R.split(",").map((function(e){return e.trim()}));k=!O.some((function(e){return!!e&&("*"===e||("."===e[0]&&c.hostname.substr(c.hostname.length-e.length)===e||c.hostname===e))}))}if(k&&(b={host:E.hostname,port:E.port,protocol:E.protocol},E.auth)){var S=E.auth.split(":");b.auth={username:S[0],password:S[1]}}}}b&&(v.headers.host=c.hostname+(c.port?":"+c.port:""),Je(v,b,f+"//"+c.hostname+(c.port?":"+c.port:"")+v.path));var j=d&&(!b||He.test(b.protocol));e.transport?y=e.transport:0===e.maxRedirects?y=j?m.default:h.default:(e.maxRedirects&&(v.maxRedirects=e.maxRedirects),y=j?Ie:ze),e.maxBodyLength>-1&&(v.maxBodyLength=e.maxBodyLength);var T=y.request(v,(function(t){if(!T.aborted){var r=t,s=t.req||T;if(204!==t.statusCode&&"HEAD"!==s.method&&!1!==e.decompress)switch(t.headers["content-encoding"]){case"gzip":case"compress":case"deflate":r=r.pipe(x.default.createUnzip()),delete t.headers["content-encoding"]}var i={status:t.statusCode,statusText:t.statusMessage,headers:t.headers,config:e,request:s};if("stream"===e.responseType)i.data=r,z(n,o,i);else{var a=[],u=0;r.on("data",(function(t){a.push(t),u+=t.length,e.maxContentLength>-1&&u>e.maxContentLength&&(r.destroy(),o(F("maxContentLength size of "+e.maxContentLength+" exceeded",e,null,s)))})),r.on("error",(function(t){T.aborted||o($(t,e,null,s))})),r.on("end",(function(){var t=Buffer.concat(a);"arraybuffer"!==e.responseType&&(t=t.toString(e.responseEncoding),e.responseEncoding&&"utf8"!==e.responseEncoding||(t=L.stripBOM(t))),i.data=t,z(n,o,i)}))}}}));if(T.on("error",(function(t){T.aborted&&"ERR_FR_TOO_MANY_REDIRECTS"!==t.code||o($(t,e,null,T))})),e.timeout){var A=parseInt(e.timeout,10);if(isNaN(A))return void o(F("error trying to parse `config.timeout` to int",e,"ERR_PARSE_TIMEOUT",T));T.setTimeout(A,(function(){T.abort(),o(F("timeout of "+A+"ms exceeded",e,e.transitional&&e.transitional.clarifyTimeoutError?"ETIMEDOUT":"ECONNABORTED",T))}))}e.cancelToken&&e.cancelToken.promise.then((function(e){T.aborted||(T.abort(),o(e))})),L.isStream(s)?s.on("error",(function(t){o($(t,e,null,T))})).pipe(T):T.end(s)}))},We={"Content-Type":"application/x-www-form-urlencoded"};function Xe(e,t){!L.isUndefined(e)&&L.isUndefined(e["Content-Type"])&&(e["Content-Type"]=t)}var Ve,Ye={transitional:{silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},adapter:("undefined"!=typeof XMLHttpRequest?Ve=W:"undefined"!=typeof process&&"[object process]"===Object.prototype.toString.call(process)&&(Ve=Ge),Ve),transformRequest:[function(e,t){return M(t,"Accept"),M(t,"Content-Type"),L.isFormData(e)||L.isArrayBuffer(e)||L.isBuffer(e)||L.isStream(e)||L.isFile(e)||L.isBlob(e)?e:L.isArrayBufferView(e)?e.buffer:L.isURLSearchParams(e)?(Xe(t,"application/x-www-form-urlencoded;charset=utf-8"),e.toString()):L.isObject(e)||t&&"application/json"===t["Content-Type"]?(Xe(t,"application/json"),function(e,t,r){if(L.isString(e))try{return(t||JSON.parse)(e),L.trim(e)}catch(e){if("SyntaxError"!==e.name)throw e}return(r||JSON.stringify)(e)}(e)):e}],transformResponse:[function(e){var t=this.transitional,r=t&&t.silentJSONParsing,n=t&&t.forcedJSONParsing,o=!r&&"json"===this.responseType;if(o||n&&L.isString(e)&&e.length)try{return JSON.parse(e)}catch(e){if(o){if("SyntaxError"===e.name)throw $(e,this,"E_JSON_PARSE");throw e}}return e}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,validateStatus:function(e){return e>=200&&e<300}};Ye.headers={common:{Accept:"application/json, text/plain, */*"}},L.forEach(["delete","get","head"],(function(e){Ye.headers[e]={}})),L.forEach(["post","put","patch"],(function(e){Ye.headers[e]=L.merge(We)}));var Ke=Ye,Ze=function(e,t,r){var n=this||Ke;return L.forEach(r,(function(r){e=r.call(n,e,t)})),e},Qe=function(e){return!(!e||!e.__CANCEL__)};function et(e){e.cancelToken&&e.cancelToken.throwIfRequested()}var tt=function(e){return et(e),e.headers=e.headers||{},e.data=Ze.call(e,e.data,e.headers,e.transformRequest),e.headers=L.merge(e.headers.common||{},e.headers[e.method]||{},e.headers),L.forEach(["delete","get","head","post","put","patch","common"],(function(t){delete e.headers[t]})),(e.adapter||Ke.adapter)(e).then((function(t){return et(e),t.data=Ze.call(e,t.data,t.headers,e.transformResponse),t}),(function(t){return Qe(t)||(et(e),t&&t.response&&(t.response.data=Ze.call(e,t.response.data,t.response.headers,e.transformResponse))),Promise.reject(t)}))},rt=function(e,t){t=t||{};var r={},n=["url","method","data"],o=["headers","auth","proxy","params"],s=["baseURL","transformRequest","transformResponse","paramsSerializer","timeout","timeoutMessage","withCredentials","adapter","responseType","xsrfCookieName","xsrfHeaderName","onUploadProgress","onDownloadProgress","decompress","maxContentLength","maxBodyLength","maxRedirects","transport","httpAgent","httpsAgent","cancelToken","socketPath","responseEncoding"],i=["validateStatus"];function a(e,t){return L.isPlainObject(e)&&L.isPlainObject(t)?L.merge(e,t):L.isPlainObject(t)?L.merge({},t):L.isArray(t)?t.slice():t}function u(n){L.isUndefined(t[n])?L.isUndefined(e[n])||(r[n]=a(void 0,e[n])):r[n]=a(e[n],t[n])}L.forEach(n,(function(e){L.isUndefined(t[e])||(r[e]=a(void 0,t[e]))})),L.forEach(o,u),L.forEach(s,(function(n){L.isUndefined(t[n])?L.isUndefined(e[n])||(r[n]=a(void 0,e[n])):r[n]=a(void 0,t[n])})),L.forEach(i,(function(n){n in t?r[n]=a(e[n],t[n]):n in e&&(r[n]=a(void 0,e[n]))}));var c=n.concat(o).concat(s).concat(i),f=Object.keys(e).concat(Object.keys(t)).filter((function(e){return-1===c.indexOf(e)}));return L.forEach(f,u),r},nt={};["object","boolean","number","function","string","symbol"].forEach((function(e,t){nt[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}}));var ot={},st=Fe.version.split(".");function it(e,t){for(var r=t?t.split("."):st,n=e.split("."),o=0;o<3;o++){if(r[o]>n[o])return!0;if(r[o]<n[o])return!1}return!1}nt.transitional=function(e,t,r){var n=t&&it(t);function o(e,t){return"[Axios v"+Fe.version+"] Transitional option '"+e+"'"+t+(r?". "+r:"")}return function(r,s,i){if(!1===e)throw new Error(o(s," has been removed in "+t));return n&&!ot[s]&&(ot[s]=!0,console.warn(o(s," has been deprecated since v"+t+" and will be removed in the near future"))),!e||e(r,s,i)}};var at={isOlderVersion:it,assertOptions:function(e,t,r){if("object"!=typeof e)throw new TypeError("options must be an object");for(var n=Object.keys(e),o=n.length;o-- >0;){var s=n[o],i=t[s];if(i){var a=e[s],u=void 0===a||i(a,s,e);if(!0!==u)throw new TypeError("option "+s+" must be "+u)}else if(!0!==r)throw Error("Unknown option "+s)}},validators:nt},ut=at.validators;function ct(e){this.defaults=e,this.interceptors={request:new P,response:new P}}ct.prototype.request=function(e){"string"==typeof e?(e=arguments[1]||{}).url=arguments[0]:e=e||{},(e=rt(this.defaults,e)).method?e.method=e.method.toLowerCase():this.defaults.method?e.method=this.defaults.method.toLowerCase():e.method="get";var t=e.transitional;void 0!==t&&at.assertOptions(t,{silentJSONParsing:ut.transitional(ut.boolean,"1.0.0"),forcedJSONParsing:ut.transitional(ut.boolean,"1.0.0"),clarifyTimeoutError:ut.transitional(ut.boolean,"1.0.0")},!1);var r=[],n=!0;this.interceptors.request.forEach((function(t){"function"==typeof t.runWhen&&!1===t.runWhen(e)||(n=n&&t.synchronous,r.unshift(t.fulfilled,t.rejected))}));var o,s=[];if(this.interceptors.response.forEach((function(e){s.push(e.fulfilled,e.rejected)})),!n){var i=[tt,void 0];for(Array.prototype.unshift.apply(i,r),i=i.concat(s),o=Promise.resolve(e);i.length;)o=o.then(i.shift(),i.shift());return o}for(var a=e;r.length;){var u=r.shift(),c=r.shift();try{a=u(a)}catch(e){c(e);break}}try{o=tt(a)}catch(e){return Promise.reject(e)}for(;s.length;)o=o.then(s.shift(),s.shift());return o},ct.prototype.getUri=function(e){return e=rt(this.defaults,e),D(e.url,e.params,e.paramsSerializer).replace(/^\?/,"")},L.forEach(["delete","get","head","options"],(function(e){ct.prototype[e]=function(t,r){return this.request(rt(r||{},{method:e,url:t,data:(r||{}).data}))}})),L.forEach(["post","put","patch"],(function(e){ct.prototype[e]=function(t,r,n){return this.request(rt(n||{},{method:e,url:t,data:r}))}}));var ft=ct;function lt(e){this.message=e}lt.prototype.toString=function(){return"Cancel"+(this.message?": "+this.message:"")},lt.prototype.__CANCEL__=!0;var dt=lt;function pt(e){if("function"!=typeof e)throw new TypeError("executor must be a function.");var t;this.promise=new Promise((function(e){t=e}));var r=this;e((function(e){r.reason||(r.reason=new dt(e),t(r.reason))}))}pt.prototype.throwIfRequested=function(){if(this.reason)throw this.reason},pt.source=function(){var e;return{token:new pt((function(t){e=t})),cancel:e}};var ht=pt;function mt(e){var t=new ft(e),r=O(ft.prototype.request,t);return L.extend(r,ft.prototype,t),L.extend(r,t),r}var gt=mt(Ke);gt.Axios=ft,gt.create=function(e){return mt(rt(gt.defaults,e))},gt.Cancel=dt,gt.CancelToken=ht,gt.isCancel=Qe,gt.all=function(e){return Promise.all(e)},gt.spread=function(e){return function(t){return e.apply(null,t)}},gt.isAxiosError=function(e){return"object"==typeof e&&!0===e.isAxiosError};var vt=gt,yt=gt;vt.default=yt;var bt=vt;const wt=bt.create({baseURL:"https://api.redgifs.com/v2/",timeout:1e4});let _t=500;async function Et(e,t,r,n,o){try{const s=n.numberToDownload||250;if(e.length>=s)return;if(o>_t)return;let i;t?(0===e.length&&(i=(await wt.get(Ot(r,100))).data),o&&(i=(await wt.get(`${Ot(r,100)}?page=${o}`)).data)):(0===e.length&&(i=(await wt.get(St(r,100))).data),o&&(i=(await wt.get(`${St(r,100)}&page=${o}`)).data)),await Rt(i,e,t,r,n,Et)}catch(e){console.log(e)}}async function xt(e,t,r={},n){let o=[];try{await Et(o,e,t,r,n)}catch(e){}return kt(o,r)}const Rt=async(e,t,r,n,o,s)=>{let{gifs:i,page:a}=e;_t=e.pages,i=kt(i,o),i.forEach((e=>{t.length<o.numberToDownload&&t.push(e)})),await s(t,r,n,o,++a)},kt=(e,t)=>{const{numberToDownload:r,useMobile:n}=t,o=[],s=[],i=[],a=(e,r)=>{const n=t[`min${e[0].toUpperCase()}${e.slice(1)}`],o=t[`max${e[0].toUpperCase()}${e.slice(1)}`];void 0!==n&&r.push({option:e,type:"min",value:n}),void 0!==o&&r.push({option:e,type:"max",value:o})};return["likes","dislikes","views","duration"].forEach((e=>{a(e,o)})),["height","width"].forEach((e=>{a(e,s)})),["nsfw","hasAudio"].forEach((e=>{void 0!==t[e]&&i.push({option:e,value:t[e]})})),e=e.filter((e=>{let t=!0;return o.forEach((r=>{"min"===r.type?t=t&&e[r.option]>=r.value:"max"===r.type&&(t=t&&e[r.option]<=r.value)})),s.forEach((r=>{"min"===r.type?t=t&&e[r.option]>=r.value:"max"===r.type&&(t=t&&e[r.option]<=r.value)})),i.forEach((r=>{t=t&&r.value===e[r.option]})),t})),r&&(e=e.slice(0,r)),e},Ot=(e,t)=>"users/$user/search".replace("$user",e).replace("$count",t),St=(e,t)=>"gifs/search?search_text=$search&count=$count&order=trending".replace("$search",e).replace("$count",t);var jt={getLinksMain:Et,getUserLinks:async function(e,t,r){return await xt(!0,e,t,r)},getSearchLinks:async function(e,t,r){return await xt(!1,e,t,r)},filter:kt};const{getLinksMain:Tt,filter:At}=jt;var Ct={create:function(e){return new Bt(e)},instance:function(e){return new Bt(e)}};class Bt{constructor(e){if(!e)throw new Error("dirname constructor parameter must not be empty");this.dirname=e,this.isDownloading=!1,this.eventEmitter=new k.default}addEventListener(e,t){return this.eventEmitter.on(e,t)}downloadUser(e,t){Ut(this,!0,e,t)}downloadQuery(e,t){Ut(this,!1,e,t)}}async function Ut(e,t,r,n={}){const{dirname:o,eventEmitter:s}=e;n.useMobile=!!n.useMobile,n.skipExisting=!!n.skipExisting;const{numberToDownload:i,useMobile:a,skipExisting:u}=n;s.emit("onInit",{userMode:t,query:r,...n,date:new Date});let c=[];try{await Tt(c,t,r,n);try{_.default.mkdirSync(R.default.join(o,`/${r||"trending"}${a?" mobile":""}`))}catch(e){}s.emit("onStart",{availableFiles:c.length,date:new Date,numberToDownload:i||"not specified",query:r,userMode:t}),s.emit("onGetLinks",{links:c,date:new Date,options:n}),async function n(a,c,f=0){try{if(f!==i&&f!==a.length){e.isDownloading=!0;const i=a[f];if(!i){const e=[];let t=0;return a.forEach((r=>{t!==f&&e.push(r)})),n(a,c,f)}const{id:l,views:d,likes:p,dislikes:h,userName:m}=i,g=c?i.urls.sd:i.urls.hd,v=R.default.join(o,`/${r||"trending"}${c?" mobile":""}/${t?l:`${m} - ${l}`}.mp4`),y={dislikes:h,likes:p,name:l,user:m,url:g,views:d,index:f,date:new Date};if(u&&_.default.existsSync(v))s.emit("onFileDownloadSkip",y),n(a,c,f+1);else{const e=_.default.createWriteStream(v);e.on("close",(()=>{s.emit("onFileDownloadFinish",y),n(a,c,f+1)})),s.emit("onFileDownloadStart",y),bt.get(g,{responseType:"stream"}).then((async t=>{t.data.pipe(e)})).catch((e=>{n(a,c,f+1)}))}}else e.isDownloading=!1,s.emit("onFinish",{availableFiles:a.length,date:new Date,numberToDownload:i||"not specified",query:r,userMode:t})}catch(t){n(a,c,f+1),s.emit("onError",{downloader:e,error:t})}}(c,a)}catch(e){console.log("Something went wrong",e)}e.isDownloading=!1}var Lt=Ct,Nt=Ct.create,Dt=Ct.instance,qt=jt.getUserLinks,Pt=jt.getSearchLinks;Lt.create=Nt,Lt.instance=Dt,Lt.getUserLinks=qt,Lt.getSearchLinks=Pt,e.create=Nt,e.default=Lt,e.getSearchLinks=Pt,e.getUserLinks=qt,e.instance=Dt,Object.defineProperty(e,"__esModule",{value:!0})}({},http,https,url,stream,assert,tty,util,fs,net,zlib,path,events$1);
//# sourceMappingURL=lib.min.js.map