instagram-publisher
Version:
Publish Instagram Images, Image Slideshows, Video Reels & Stories via NodeJS
3 lines (2 loc) • 29.2 kB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("fs");function t(){t=function(){return e};var e={},r=Object.prototype,n=r.hasOwnProperty,a=Object.defineProperty||function(e,t,r){e[t]=r.value},i="function"==typeof Symbol?Symbol:{},o=i.iterator||"@@iterator",s=i.asyncIterator||"@@asyncIterator",u=i.toStringTag||"@@toStringTag";function c(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{c({},"")}catch(e){c=function(e,t,r){return e[t]=r}}function p(e,t,r,n){var i=Object.create((t&&t.prototype instanceof h?t:h).prototype),o=new P(n||[]);return a(i,"_invoke",{value:x(e,r,o)}),i}function d(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=p;var l={};function h(){}function f(){}function m(){}var g={};c(g,o,(function(){return this}));var v=Object.getPrototypeOf,_=v&&v(v(q([])));_&&_!==r&&n.call(_,o)&&(g=_);var b=m.prototype=h.prototype=Object.create(g);function y(e){["next","throw","return"].forEach((function(t){c(e,t,(function(e){return this._invoke(t,e)}))}))}function w(e,t){var r;a(this,"_invoke",{value:function(a,i){function o(){return new t((function(r,o){!function r(a,i,o,s){var u=d(e[a],e,i);if("throw"!==u.type){var c=u.arg,p=c.value;return p&&"object"==typeof p&&n.call(p,"__await")?t.resolve(p.__await).then((function(e){r("next",e,o,s)}),(function(e){r("throw",e,o,s)})):t.resolve(p).then((function(e){c.value=e,o(c)}),(function(e){return r("throw",e,o,s)}))}s(u.arg)}(a,i,r,o)}))}return r=r?r.then(o,o):o()}})}function x(e,t,r){var n="suspendedStart";return function(a,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===a)throw i;return{value:void 0,done:!0}}for(r.method=a,r.arg=i;;){var o=r.delegate;if(o){var s=k(o,r);if(s){if(s===l)continue;return s}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=d(e,t,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===l)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}function k(e,t){var r=t.method,n=e.iterator[r];if(void 0===n)return t.delegate=null,"throw"===r&&e.iterator.return&&(t.method="return",t.arg=void 0,k(e,t),"throw"===t.method)||"return"!==r&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+r+"' method")),l;var a=d(n,e.iterator,t.arg);if("throw"===a.type)return t.method="throw",t.arg=a.arg,t.delegate=null,l;var i=a.arg;return i?i.done?(t[e.resultName]=i.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,l):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,l)}function S(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function O(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function P(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(S,this),this.reset(!0)}function q(e){if(e){var t=e[o];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,a=function t(){for(;++r<e.length;)if(n.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=void 0,t.done=!0,t};return a.next=a}}return{next:I}}function I(){return{value:void 0,done:!0}}return f.prototype=m,a(b,"constructor",{value:m,configurable:!0}),a(m,"constructor",{value:f,configurable:!0}),f.displayName=c(m,u,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===f||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,m):(e.__proto__=m,c(e,u,"GeneratorFunction")),e.prototype=Object.create(b),e},e.awrap=function(e){return{__await:e}},y(w.prototype),c(w.prototype,s,(function(){return this})),e.AsyncIterator=w,e.async=function(t,r,n,a,i){void 0===i&&(i=Promise);var o=new w(p(t,r,n,a),i);return e.isGeneratorFunction(r)?o:o.next().then((function(e){return e.done?e.value:o.next()}))},y(b),c(b,u,"Generator"),c(b,o,(function(){return this})),c(b,"toString",(function(){return"[object Generator]"})),e.keys=function(e){var t=Object(e),r=[];for(var n in t)r.push(n);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},e.values=q,P.prototype={constructor:P,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(O),!e)for(var t in this)"t"===t.charAt(0)&&n.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function r(r,n){return o.type="throw",o.arg=e,t.next=r,n&&(t.method="next",t.arg=void 0),!!n}for(var a=this.tryEntries.length-1;a>=0;--a){var i=this.tryEntries[a],o=i.completion;if("root"===i.tryLoc)return r("end");if(i.tryLoc<=this.prev){var s=n.call(i,"catchLoc"),u=n.call(i,"finallyLoc");if(s&&u){if(this.prev<i.catchLoc)return r(i.catchLoc,!0);if(this.prev<i.finallyLoc)return r(i.finallyLoc)}else if(s){if(this.prev<i.catchLoc)return r(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return r(i.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var a=this.tryEntries[r];if(a.tryLoc<=this.prev&&n.call(a,"finallyLoc")&&this.prev<a.finallyLoc){var i=a;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var o=i?i.completion:{};return o.type=e,o.arg=t,i?(this.method="next",this.next=i.finallyLoc,l):this.complete(o)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),l},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),O(r),l}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var a=n.arg;O(r)}return a}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:q(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),l}},e}function r(e,t,r,n,a,i,o){try{var s=e[i](o),u=s.value}catch(e){return void r(e)}s.done?t(u):Promise.resolve(u).then(n,a)}function n(e){return function(){var t=this,n=arguments;return new Promise((function(a,i){var o=e.apply(t,n);function s(e){r(o,a,i,s,u,"next",e)}function u(e){r(o,a,i,s,u,"throw",e)}s(void 0)}))}}function a(){return(a=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}var i=["1:1","16:9","9:16"],o=["mp4"],s="https://i.instagram.com",u="[InstagramPublisher] - Invalid credentials",c="[InstagramPublisher] - No coookies found after login",p="[InstagramPublisher] - Only '1:1', '16:9', '9:16' video aspect ratios are supported",d="[InstagramPublisher] - Location not found";function l(){if(e.existsSync("cookies.json")){var t=JSON.parse(e.readFileSync("cookies.json","utf8")),r=new Date(t.find((function(e){return"sessionid"===e.key})).expires);return new Date<r}return!1}function h(e){return f.apply(this,arguments)}function f(){return(f=n(t().mark((function e(r){return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,new Promise((function(e){return setTimeout(e,r)}));case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var m=require("request-promise-native"),g=function(){function t(){}return t.setHeaders=function(){t.request=m;var r={baseUrl:s,uri:"",json:!0,headers:{"User-Agent":this.useragent,"Accept-Language":"en-US","X-Instagram-AJAX":1,"X-Requested-With":"XMLHttpRequest",Referer:s,origin:s}};if(l()&&void 0!==r.headers){var n=JSON.parse(e.readFileSync("cookies.json","utf-8")),a=n.filter((function(e){return"csrftoken"===e.key}))[0].value;this.csrftoken=a.toString(),r.headers["X-CSRFToken"]=a,this.cookies=n.map((function(e){return e.key+"="+e.value})).join(";"),r.headers.Cookie=this.cookies}t.request=m.defaults(r)},t}();g.request=m,g.cookies="",g.useragent="Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1",g.csrftoken="";var v=require("request-promise-native");function _(e){return b.apply(this,arguments)}function b(){return(b=n(t().mark((function e(r){var n,a;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n={"x-asbd-id":"198387","x-ig-app-id":"936619743392459","User-Agent":g.useragent,Cookie:g.cookies,"X-CSRFToken":g.csrftoken,origin:s,Referer:s},e.t0=JSON,e.next=4,v({url:s+"/api/v1/location_search/?search_query="+r,method:"GET",headers:n});case 4:return e.t1=e.sent,a=e.t0.parse.call(e.t0,e.t1),e.abrupt("return",a);case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var y=require("image-size");function w(e){return x.apply(this,arguments)}function x(){return(x=n(t().mark((function r(n){var a,i,o,u,c,p;return t().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return a=Date.now(),i={"access-control-request-method":"POST","access-control-request-headers":"content-type,offset,x-asbd-id,x-entity-length,x-entity-name,x-entity-type,x-ig-app-id,x-instagram-ajax,x-instagram-rupload-params"},t.next=4,g.request({uri:"/rupload_igphoto/fb_uploader_"+a,method:"OPTIONS",headers:i});case 4:return o=e.readFileSync(n),u=y(o),c={"x-instagram-rupload-params":JSON.stringify({media_type:1,upload_id:a,upload_media_height:u.height,upload_media_width:u.width}),"x-entity-name":"fb_uploader_"+a,offset:0,origin:s,"x-entity-length":o.byteLength,"Content-Length":o.byteLength,"Content-Type":"image/jpeg","x-entity-type":"image/jpeg"},t.t0=JSON,t.next=10,g.request({uri:"/rupload_igphoto/fb_uploader_"+a,headers:c,method:"POST",json:!1,body:o});case 10:return t.t1=t.sent,p=t.t0.parse.call(t.t0,t.t1),t.abrupt("return",p);case 13:case"end":return t.stop()}}),r)})))).apply(this,arguments)}var k=require("image-size");function S(e){if(e.length>2200)throw new Error("[InstagramPublisher] - Caption should not exceed 2200 characters")}function O(e,t){void 0===t&&(t=!1);try{k(e)}catch(e){throw new Error(t?"[InstagramPublisher] - Thumbnail image not found":"[InstagramPublisher] - Not all images found")}}function P(e){if(e.height!==e.width)throw new Error("[InstagramPublisher] - Not all images have 1:1 aspect ratio")}function q(e,t){if(void 0===t&&(t=!1),"jpg"!==e.type)throw new Error(t?"[InstagramPublisher] - Thumbnail image is not .jpg":"[InstagramPublisher] - Only .jpg images are allowed")}function I(t){if(!e.existsSync(t))throw new Error("[InstagramPublisher] - Video not found")}function L(e){var t=e.split(".")[e.split(".").length-1];if(!o.find((function(e){return e===t})))throw new Error("[InstagramPublisher] - Only .mp4 video files are supported")}var T=require("image-size");function E(e){return N.apply(this,arguments)}function N(){return(N=n(t().mark((function e(r){var n,a,i,o,s,u,c,p,d,l,h;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:o=void 0===(i=r.caption)?"":i,s=r.location,u=r.verbose,R(a=void 0===(n=r.images)?[]:n),S(o),c=[],p=[],d=0;case 6:if(!(d<a.length)){e.next=21;break}return l=a[d],e.prev=8,e.next=11,w(l);case 11:c.push(e.sent),e.next=18;break;case 15:e.prev=15,e.t0=e.catch(8),p.push("[InstagramPublisher/createSlideshow] - Photo "+l+" not uploaded");case 18:d++,e.next=6;break;case 21:if(!(c.length>0)){e.next=27;break}return e.next=24,j({photosUploaded:c,caption:o,location:s});case 24:return h=e.sent,u&&console.info("[InstagramPublisher] - Image Slideshow Created: "+h.status),e.abrupt("return",{succeeded:"ok"===h.status,code:h.media.code});case 27:return e.abrupt("return",{succeeded:!1,code:""});case 28:case"end":return e.stop()}}),e,null,[[8,15]])})))).apply(this,arguments)}function j(e){return C.apply(this,arguments)}function C(){return(C=n(t().mark((function e(r){var n,a,i,o;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=r.location,a={caption:r.caption,children_metadata:[].concat(r.photosUploaded),client_sidecar_id:Date.now().toString(),disable_comments:"0",like_and_view_counts_disabled:!1,source_type:"library"},!n){e.next=14;break}return e.prev=3,e.next=6,_(n);case 6:a.location={lat:(i=e.sent).venues[0].lat,lng:i.venues[0].lng,facebook_places_id:i.venues[0].external_id},a.geotag_enabled="true",e.next=14;break;case 11:throw e.prev=11,e.t0=e.catch(3),new Error(d);case 14:return o={"x-asbd-id":"198387","x-ig-app-id":"936619743392459"},e.next=17,g.request({uri:"/api/v1/media/configure_sidecar/",method:"POST",json:a,headers:o});case 17:return e.abrupt("return",e.sent);case 19:case"end":return e.stop()}}),e,null,[[3,11]])})))).apply(this,arguments)}function R(e){if(e.length<2)throw new Error("[InstagramPublisher] - Minimum 2 images required");if(e.length>10)throw new Error("[InstagramPublisher] - Maximum 10 images allowed");e.map((function(e){return O(e)}));var t=e.map(T);t.map((function(e){return q(e)})),t.map(P)}var A=require("tough-cookie").Cookie;function F(e){return M.apply(this,arguments)}function M(){return(M=n(t().mark((function r(n){var a,i,o,s,p,d,l,h,f;return t().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return a=n.email,i=n.password,o=n.verbose,t.next=3,g.request("/",{resolveWithFullResponse:!0}).then((function(e){var t=new RegExp(/(csrf_token\\":\\")[\w]+/),r=e.body.match(t);s=r[0].substring(15)}));case 3:return g.request=g.request.defaults({headers:{"X-CSRFToken":s}}),p=function(e){return"#PWD_INSTAGRAM_BROWSER:0:"+Date.now()+":"+e},t.next=7,g.request.post("/accounts/login/ajax/",{resolveWithFullResponse:!0,form:{username:a,enc_password:p(i)}});case 7:if((d=t.sent).headers["set-cookie"]){t.next=10;break}throw new Error(c);case 10:if(l=d.headers["set-cookie"],(h=d.body).authenticated){t.next=14;break}throw new Error(u);case 14:return o&&console.info("[InstagramPublisher] - Authenticated: "+d.body.authenticated),l.push("ig_cb=1"),f=l.map(A.parse).map((function(e){return e.toJSON()})),e.writeFileSync("cookies.json",JSON.stringify(f)),t.abrupt("return",h.authenticated);case 19:case"end":return t.stop()}}),r)})))).apply(this,arguments)}function J(e){return G.apply(this,arguments)}function G(){return(G=n(t().mark((function r(n){var i,o,u,c,p,d,l,h,f,m,v;return t().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return i=n.video_path,o=n.video_height,u=n.video_width,c=n.video_duration,d=void 0!==(p=n.is_reel)&&p,l=Date.now(),h={"access-control-request-method":"GET","access-control-request-headers":"x-asbd-id,x-ig-app-id",origin:s},t.next=5,g.request({uri:d?"/rupload_igvideo/feed_"+l:"/rupload_igvideo/fb_uploader_"+l,method:"OPTIONS",headers:h});case 5:return f=e.readFileSync(i),m=d?{"x-instagram-rupload-params":JSON.stringify({"client-passthrough":"1",is_igtv_video:!1,is_sidecar:"0",is_unified_video:!1,media_type:2,for_album:!1,upload_id:l,upload_media_duration_ms:1e3*Number(Number(c).toFixed(3)),upload_media_height:o,upload_media_width:u,video_transform:null,video_format:"video/mp4",is_clips_video:!0,uses_original_audio:!0,audio_type:"original_sounds"}),"x-entity-name":"feed_"+l,offset:0,origin:s,"x-entity-length":f.byteLength,"Content-Length":f.byteLength}:{"x-instagram-rupload-params":JSON.stringify({"client-passthrough":"1",is_igtv_video:!0,is_sidecar:"0",is_unified_video:"1",media_type:2,for_album:!1,video_format:"",upload_id:l,upload_media_duration_ms:1e3*Number(Number(c).toFixed(3)),upload_media_height:o,upload_media_width:u,video_transform:null}),"x-entity-name":"fb_uploader_"+l,offset:0,origin:s,"x-entity-length":f.byteLength,"Content-Length":f.byteLength},t.t0=JSON,t.next=10,g.request({uri:d?"/rupload_igvideo/feed_"+l:"/rupload_igvideo/fb_uploader_"+l,headers:m,method:"POST",json:!1,body:f});case 10:return t.t1=t.sent,v=t.t0.parse.call(t.t0,t.t1),t.abrupt("return",a({},v,{upload_id:l.toString()}));case 13:case"end":return t.stop()}}),r)})))).apply(this,arguments)}var U=require("request-promise-native");function X(e){return H.apply(this,arguments)}function H(){return(H=n(t().mark((function r(n){var a,i,o,u,c,p,d,l,h;return t().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return a=n.image_path,i=n.video_upload_id,o=n.video_height,u=n.video_width,p=void 0!==(c=n.is_reel)&&c,d={"access-control-request-method":"POST","access-control-request-headers":"content-type,offset,x-asbd-id,x-entity-length,x-entity-name,x-entity-type,x-ig-app-id,x-instagram-ajax,x-instagram-rupload-params",origin:s},t.next=4,g.request({uri:p?"/rupload_igphoto/feed_"+i:"/rupload_igphoto/fb_uploader_"+i,method:"OPTIONS",headers:d});case 4:return l=e.readFileSync(a),h={method:"POST",url:p?s+"/rupload_igphoto/feed_"+i:s+"/rupload_igphoto/fb_uploader_"+i,headers:{"User-Agent":g.useragent,Cookie:g.cookies,origin:s,"Content-Type":"image/jpeg","Content-Length":l.byteLength,"x-instagram-rupload-params":'{"media_type":2,"upload_id":"'+i+'","upload_media_height":'+o+',"upload_media_width":'+u+"}","x-entity-length":l.byteLength,"x-entity-type":"image/jpeg","x-entity-name":p?"feed_"+i:"fb_uploader_"+i,offset:0},body:l},t.t0=JSON,t.next=9,U(h);case 9:return t.t1=t.sent,t.abrupt("return",t.t0.parse.call(t.t0,t.t1));case 11:case"end":return t.stop()}}),r)})))).apply(this,arguments)}var z=require("ffprobe"),W=require("ffprobe-static"),D=require("request-promise-native"),K=require("image-size");function V(e){return B.apply(this,arguments)}function B(){return(B=n(t().mark((function e(r){var n,a,o,s,u,c,d,l,f,m,g,v,_,b,y;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=r.video_path,a=r.thumbnail_path,s=r.is_reel,u=r.location,c=r.verbose,S(o=r.caption),O(a,!0),q(K(a),!0),I(n),L(n),e.next=8,z(n,{path:W.path});case 8:if(d=e.sent.streams.filter((function(e){return"video"===e.codec_type}))[0],l=d.duration,f=d.width,m=d.height,null==(g=d.display_aspect_ratio)||i.find((function(e){return e===g}))){e.next=13;break}throw new Error(p);case 13:return e.prev=13,e.next=16,J({video_duration:l,video_height:m,video_width:f,video_path:n,is_reel:s});case 16:return v=e.sent,e.next=19,X({video_height:m,video_width:f,image_path:a,video_upload_id:v.upload_id,is_reel:s});case 19:return c&&console.info("[InstagramPublisher] - Processing video.."),e.next=22,h(15e3);case 22:_=0,b=!1,y={status:"failed",media:{code:"",upload_id:"",status:"",pk:""}};case 25:if(!(_<5&&!1===b)){e.next=42;break}if(!s){e.next=32;break}return e.next=29,Z({caption:o,upload_id:v.upload_id,location:u});case 29:e.t0=e.sent,e.next=35;break;case 32:return e.next=34,Y({caption:o,upload_id:v.upload_id,location:u});case 34:e.t0=e.sent;case 35:return b="ok"===(y=e.t0).status,_++,e.next=40,h(15e3);case 40:e.next=25;break;case 42:return c&&console.info(s?"[InstagramPublisher] - Reel created: "+b:"[InstagramPublisher] - Video post created: "+b),e.abrupt("return",{succeeded:b,code:y.media.code});case 46:throw e.prev=46,e.t1=e.catch(13),new Error("[InstagramPublisher] - Failed to create video - "+e.t1);case 49:case"end":return e.stop()}}),e,null,[[13,46]])})))).apply(this,arguments)}function Y(e){return Q.apply(this,arguments)}function Q(){return(Q=n(t().mark((function e(r){var n,i,o,u;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(i={source_type:"library",caption:r.caption,upload_id:r.upload_id,disable_comments:"0",like_and_view_counts_disabled:"0",igtv_share_preview_to_feed:"1",is_unified_video:"1",video_subtitles_enabled:"0"},!(n=r.location)){e.next=14;break}return e.prev=3,e.next=6,_(n);case 6:o=e.sent,i.location=JSON.stringify({lat:o.venues[0].lat,lng:o.venues[0].lng,facebook_places_id:o.venues[0].external_id}),i.geotag_enabled=!0,e.next=14;break;case 11:throw e.prev=11,e.t0=e.catch(3),new Error(d);case 14:return u={method:"POST",url:"https://www.instagram.com/igtv/configure_to_igtv/",headers:{"User-Agent":g.useragent,Cookie:g.cookies,"X-CSRFToken":g.csrftoken,origin:s,"Content-Type":"application/x-www-form-urlencoded",Referer:s,"x-requested-with":"XMLHttpRequest"},form:a({},i)},e.t1=JSON,e.next=18,D(u);case 18:return e.t2=e.sent,e.abrupt("return",e.t1.parse.call(e.t1,e.t2));case 20:case"end":return e.stop()}}),e,null,[[3,11]])})))).apply(this,arguments)}function Z(e){return $.apply(this,arguments)}function $(){return($=n(t().mark((function e(r){var n,i,o,u,c,p,l;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=r.caption,i=r.upload_id,o=r.location,u={method:"OPTIONS",url:"https://i.instagram.com/api/v1/media/configure_to_clips/",headers:{authority:"i.instagram.com",accept:"*/*","accept-language":"en-US,en-GB;q=0.9,en;q=0.8","access-control-request-headers":"x-asbd-id,x-csrftoken,x-ig-app-id,x-ig-www-claim,x-instagram-ajax","access-control-request-method":"POST",origin:"https://www.instagram.com",referer:"https://www.instagram.com/","sec-fetch-dest":"document","sec-fetch-mode":"cors","sec-fetch-site":"same-site","User-Agent":g.useragent,"x-frame-options":"SAMEORIGIN"}},e.next=4,D(u);case 4:if(c={upload_id:i,caption:n,retry_timeout:12,clips_uses_original_audio:1,uses_original_audio:1,original_audio:1,audio:1,clips_audio:1,clips_with_audio:1,with_audio:1,enable_audio:1,clips_enable_audio:1,clips_audio_enable:1,audio_enable:1,audio_type:"original_sounds"},!o){e.next=17;break}return e.prev=6,e.next=9,_(o);case 9:p=e.sent,c.location=JSON.stringify({lat:p.venues[0].lat,lng:p.venues[0].lng,facebook_places_id:p.venues[0].external_id}),c.geotag_enabled=!0,e.next=17;break;case 14:throw e.prev=14,e.t0=e.catch(6),new Error(d);case 17:return l={method:"POST",url:"https://i.instagram.com/api/v1/media/configure_to_clips/",headers:{"User-Agent":"Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1 Instagram 231.0.0.18.113",Cookie:g.cookies,"X-CSRFToken":g.csrftoken,origin:s,"Content-Type":"application/x-www-form-urlencoded",Referer:s,"x-ig-app-id":"1217981644879628","x-asbd-id":"198387","x-frame-options":"SAMEORIGIN"},form:a({},c)},e.t1=JSON,e.next=21,D(l);case 21:return e.t2=e.sent,e.abrupt("return",e.t1.parse.call(e.t1,e.t2));case 23:case"end":return e.stop()}}),e,null,[[6,14]])})))).apply(this,arguments)}var ee=require("image-size"),te=require("request-promise-native");function re(e){return ne.apply(this,arguments)}function ne(){return(ne=n(t().mark((function e(r){var n,i,o,u,c,p,l,h,f;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=r.image_path,o=r.verbose,u=r.location,S(i=r.caption),O(n),q(ee(n)),c={"access-control-request-method":"POST","access-control-request-headers":"x-asbd-id,x-csrftoken,x-ig-app-id,x-ig-www-claim,x-instagram-ajax"},e.next=8,g.request({uri:"/api/v1/media/configure",method:"OPTIONS",headers:c});case 8:return p={"x-asbd-id":"198387","x-ig-app-id":"936619743392459","Content-Type":"application/x-www-form-urlencoded","User-Agent":g.useragent,Cookie:g.cookies,"X-CSRFToken":g.csrftoken,origin:s,Referer:s},e.next=11,w(n);case 11:if(l={source_type:"library",caption:i,upload_id:e.sent.upload_id,disable_comments:"0",like_and_view_counts_disabled:"0",igtv_share_preview_to_feed:"1",is_unified_video:"1",video_subtitles_enabled:"0"},!u){e.next=25;break}return e.prev=14,e.next=17,_(u);case 17:h=e.sent,l.location=JSON.stringify({lat:h.venues[0].lat,lng:h.venues[0].lng,facebook_places_id:h.venues[0].external_id}),l.geotag_enabled=!0,e.next=25;break;case 22:throw e.prev=22,e.t0=e.catch(14),new Error(d);case 25:return e.t1=JSON,e.next=28,te({url:s+"/api/v1/media/configure/",method:"POST",headers:p,form:a({},l)});case 28:return e.t2=e.sent,f=e.t1.parse.call(e.t1,e.t2),o&&console.info("[InstagramPublisher] - Image Post Created: "+f.status),e.abrupt("return",{succeeded:"ok"===f.status,code:f.media.code});case 32:case"end":return e.stop()}}),e,null,[[14,22]])})))).apply(this,arguments)}var ae=require("request-promise-native");function ie(e){return oe.apply(this,arguments)}function oe(){return(oe=n(t().mark((function e(r){var n;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n={method:"POST",url:"https://www.instagram.com/api/v1/web/create/configure_to_story/",headers:{"User-Agent":"Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1 Instagram 231.0.0.18.113",Cookie:g.cookies,"X-CSRFToken":g.csrftoken,origin:s,"Content-Type":"application/x-www-form-urlencoded",Referer:s,"x-ig-app-id":"1217981644879628","x-asbd-id":"198387","x-frame-options":"SAMEORIGIN"},form:{upload_id:r.upload_id}},e.t0=JSON,e.next=5,ae(n);case 5:return e.t1=e.sent,e.abrupt("return",e.t0.parse.call(e.t0,e.t1));case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var se=require("image-size");function ue(e){return ce.apply(this,arguments)}function ce(){return(ce=n(t().mark((function e(r){var n,a,i,o,s;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=r.verbose,O(n=r.image_path),q(se(n)),i={"access-control-request-method":"POST","access-control-request-headers":"x-asbd-id,x-csrftoken,x-ig-app-id,x-ig-www-claim,x-instagram-ajax"},e.next=7,g.request({uri:"/api/v1/media/configure",method:"OPTIONS",headers:i});case 7:return e.next=9,w(n);case 9:return o=e.sent,e.next=12,ie({upload_id:o.upload_id});case 12:return s=e.sent,a&&console.info("[InstagramPublisher] - Image Story Created: "+s.status),e.abrupt("return",{succeeded:"ok"===s.status,code:s.media.pk});case 15:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var pe=function(){function e(e){var t=e.email,r=e.password,n=e.verbose,a=void 0!==n&&n;this._email="",this._password="",this._verbose=!1,this._email=t,this._password=r,this._verbose=a,g.setHeaders(),l()&&this._verbose&&console.info("[InstagramPublisher] - Authenticated: true (cached)")}var r=e.prototype;return r.createSingleImage=function(){var e=n(t().mark((function e(r){var n,a,i,o;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=r.image_path,i=void 0===(a=r.caption)?"":a,o=r.location,l()){e.next=5;break}return e.next=4,F({email:this._email,password:this._password,verbose:this._verbose});case 4:g.setHeaders();case 5:return e.next=7,re({image_path:n,caption:i,location:o,verbose:this._verbose});case 7:return e.abrupt("return",e.sent);case 8:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),r.createImageSlideshow=function(){var e=n(t().mark((function e(r){var n,a,i,o,s;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(a=void 0===(n=r.images)?[]:n,o=void 0===(i=r.caption)?"":i,s=r.location,l()){e.next=5;break}return e.next=4,F({email:this._email,password:this._password,verbose:this._verbose});case 4:g.setHeaders();case 5:return e.next=7,E({images:a,caption:o,location:s,verbose:this._verbose});case 7:return e.abrupt("return",e.sent);case 8:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),r.createSingleVideo=function(){var e=n(t().mark((function e(r){var n,a,i,o;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=r.video_path,a=r.thumbnail_path,i=r.caption,o=r.location,l()){e.next=5;break}return e.next=4,F({email:this._email,password:this._password,verbose:this._verbose});case 4:g.setHeaders();case 5:return e.next=7,V({video_path:n,thumbnail_path:a,caption:i,is_reel:!1,location:o,verbose:this._verbose});case 7:return e.abrupt("return",e.sent);case 8:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),r.createReel=function(){var e=n(t().mark((function e(r){var n,a,i,o;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=r.video_path,a=r.thumbnail_path,i=r.caption,o=r.location,l()){e.next=5;break}return e.next=4,F({email:this._email,password:this._password,verbose:this._verbose});case 4:g.setHeaders();case 5:return e.next=7,V({video_path:n,thumbnail_path:a,caption:i,is_reel:!0,location:o,verbose:this._verbose});case 7:return e.abrupt("return",e.sent);case 8:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),r.createImageStory=function(){var e=n(t().mark((function e(r){var n;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=r.image_path,l()){e.next=5;break}return e.next=4,F({email:this._email,password:this._password,verbose:this._verbose});case 4:g.setHeaders();case 5:return e.next=7,ue({image_path:n,verbose:this._verbose});case 7:return e.abrupt("return",e.sent);case 8:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),e}();module.exports=pe,exports.default=pe;
//# sourceMappingURL=instagram-publisher.cjs.production.min.js.map