pupgram 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -3
- package/dist/actions/create-post/put-post-caption.action.js +2 -2
- package/dist/actions/delay.action.js +2 -2
- package/dist/configs/en.config.js +1 -1
- package/dist/configs/pt-br.config.js +1 -1
- package/dist/enums/index.d.ts +1 -0
- package/dist/enums/index.js +17 -0
- package/dist/enums/language.enum.d.ts +10 -0
- package/dist/enums/language.enum.js +14 -0
- package/dist/instagram.d.ts +14 -3
- package/dist/instagram.js +22 -10
- package/dist/utils/create-post-url.util.d.ts +1 -0
- package/dist/utils/create-post-url.util.js +6 -0
- package/dist/utils/create-reel-url.util.d.ts +1 -0
- package/dist/utils/create-reel-url.util.js +6 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/require-vanilla-puppeteer.d.ts +1 -0
- package/dist/utils/require-vanilla-puppeteer.js +15 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -47,7 +47,7 @@ async function main() {
|
|
|
47
47
|
caption: "Hello from Pupgram! 🚀",
|
|
48
48
|
})
|
|
49
49
|
|
|
50
|
-
console.log(`Post created! URL:
|
|
50
|
+
console.log(`Post created! URL: ${postData.url}`)
|
|
51
51
|
console.log(postData)
|
|
52
52
|
|
|
53
53
|
// 4. Close the instance
|
|
@@ -80,11 +80,11 @@ async function main() {
|
|
|
80
80
|
|
|
81
81
|
// 3. Create a Reel
|
|
82
82
|
const reelData = await instagram.createReel({
|
|
83
|
-
|
|
83
|
+
filePath: "./path/to/video.mp4",
|
|
84
84
|
caption: "My awesome Reel! 🎥",
|
|
85
85
|
})
|
|
86
86
|
|
|
87
|
-
console.log(`Reel created! URL:
|
|
87
|
+
console.log(`Reel created! URL: ${reelData.url}`)
|
|
88
88
|
|
|
89
89
|
// 4. Close the instance
|
|
90
90
|
await instagram.close()
|
|
@@ -123,6 +123,20 @@ Automate reel publishing with support for:
|
|
|
123
123
|
|
|
124
124
|
Pupgram is designed to be flexible. You can provide custom configurations for different locales or UI variations using the `config` option in `Instagram.create`.
|
|
125
125
|
|
|
126
|
+
#### 🌍 Forcing Language
|
|
127
|
+
|
|
128
|
+
You can force Instagram to load in a specific language using the `languageParam` option. This is useful to ensure the UI matches the selectors provided in your config.
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
import { Instagram, enConfig, Language } from "pupgram"
|
|
132
|
+
|
|
133
|
+
const instagram = await Instagram.create({
|
|
134
|
+
// ... other options
|
|
135
|
+
config: enConfig,
|
|
136
|
+
languageParam: Language.EN_US // Forces ?hl=en-us
|
|
137
|
+
})
|
|
138
|
+
```
|
|
139
|
+
|
|
126
140
|
#### 🐞 Debugging
|
|
127
141
|
|
|
128
142
|
When things go wrong, Pupgram helps you diagnose the issue. If `screenshotOnError` or `htmlContentOnError` are enabled (default: `true`), Pupgram creates an `errors` directory in your project root.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.putPostCaptionAction = void 0;
|
|
4
|
-
const delay_util_1 = require("../../utils/delay.util");
|
|
5
4
|
const error_1 = require("../../error");
|
|
5
|
+
const utils_1 = require("../../utils");
|
|
6
6
|
const putPostCaptionAction = (caption) => {
|
|
7
7
|
return async ({ page, config, logger, defaultTimeout }) => {
|
|
8
8
|
logger.info("Starting to put post caption");
|
|
@@ -17,7 +17,7 @@ const putPostCaptionAction = (caption) => {
|
|
|
17
17
|
await captionElement.focus();
|
|
18
18
|
await page.keyboard.type(caption);
|
|
19
19
|
await page.keyboard.press("Tab");
|
|
20
|
-
await (0,
|
|
20
|
+
await (0, utils_1.delay)(300);
|
|
21
21
|
logger.info("Post caption successfully entered");
|
|
22
22
|
};
|
|
23
23
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.delayAction = void 0;
|
|
4
|
-
const
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
5
|
const delayAction = (delayTime) => {
|
|
6
6
|
return async ({ logger }) => {
|
|
7
7
|
logger.info("Delaying");
|
|
8
|
-
await (0,
|
|
8
|
+
await (0, utils_1.delay)(delayTime);
|
|
9
9
|
logger.debug("Delaying");
|
|
10
10
|
};
|
|
11
11
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./language.enum";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./language.enum"), exports);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Language = void 0;
|
|
4
|
+
var Language;
|
|
5
|
+
(function (Language) {
|
|
6
|
+
Language["EN_US"] = "en-us";
|
|
7
|
+
Language["EN_UK"] = "en-uk";
|
|
8
|
+
Language["EN"] = "en";
|
|
9
|
+
Language["PT_BR"] = "pt-br";
|
|
10
|
+
Language["PT"] = "pt";
|
|
11
|
+
Language["PT_PT"] = "pt-pt";
|
|
12
|
+
Language["ES"] = "es";
|
|
13
|
+
Language["ES_MX"] = "es-mx";
|
|
14
|
+
})(Language || (exports.Language = Language = {}));
|
package/dist/instagram.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Browser } from "puppeteer";
|
|
2
2
|
import { PostData } from "./interfaces/post-data.interface";
|
|
3
3
|
import { Config } from "./interfaces";
|
|
4
|
+
import { Language } from "./enums";
|
|
4
5
|
export declare const defaultTimeout = 10000;
|
|
5
6
|
export type CreateInstagramOptions = {
|
|
6
7
|
puppeteer: {
|
|
@@ -14,6 +15,7 @@ export type CreateInstagramOptions = {
|
|
|
14
15
|
htmlContentOnError?: boolean;
|
|
15
16
|
config: Config;
|
|
16
17
|
defaultTimeout?: number;
|
|
18
|
+
languageParam?: Language;
|
|
17
19
|
};
|
|
18
20
|
export type InstagramOptions = {
|
|
19
21
|
browser: Browser;
|
|
@@ -22,6 +24,7 @@ export type InstagramOptions = {
|
|
|
22
24
|
htmlContentOnError: boolean;
|
|
23
25
|
config: Config;
|
|
24
26
|
defaultTimeout?: number;
|
|
27
|
+
languageParam?: Language;
|
|
25
28
|
};
|
|
26
29
|
export type LogInOptions = {
|
|
27
30
|
username: string;
|
|
@@ -31,6 +34,13 @@ export type CreatePostOptions = {
|
|
|
31
34
|
filePaths: string[];
|
|
32
35
|
caption: string;
|
|
33
36
|
};
|
|
37
|
+
export type CreateReelOptions = {
|
|
38
|
+
filePath: string;
|
|
39
|
+
caption: string;
|
|
40
|
+
};
|
|
41
|
+
export type CreatePostResult = PostData & {
|
|
42
|
+
url: string;
|
|
43
|
+
};
|
|
34
44
|
export declare class Instagram {
|
|
35
45
|
readonly baseUrl = "https://www.instagram.com";
|
|
36
46
|
private readonly browser;
|
|
@@ -40,7 +50,8 @@ export declare class Instagram {
|
|
|
40
50
|
private readonly htmlContentOnError;
|
|
41
51
|
readonly config: Config;
|
|
42
52
|
readonly defaultTimeout: number;
|
|
43
|
-
|
|
53
|
+
readonly languageParam?: Language;
|
|
54
|
+
constructor({ browser, logLevel, screenshotOnError, htmlContentOnError, config, defaultTimeout: optionsDefaultTimeout, languageParam, }: InstagramOptions);
|
|
44
55
|
static create(options: CreateInstagramOptions): Promise<Instagram>;
|
|
45
56
|
close(): Promise<void>;
|
|
46
57
|
private initalizePage;
|
|
@@ -48,6 +59,6 @@ export declare class Instagram {
|
|
|
48
59
|
needsLogin(): Promise<boolean>;
|
|
49
60
|
logIn({ username, password }: LogInOptions): Promise<void>;
|
|
50
61
|
ensureLoggedIn({ username, password }: LogInOptions): Promise<void>;
|
|
51
|
-
createPost({ caption, filePaths }: CreatePostOptions): Promise<
|
|
52
|
-
createReel({ caption,
|
|
62
|
+
createPost({ caption, filePaths }: CreatePostOptions): Promise<CreatePostResult>;
|
|
63
|
+
createReel({ caption, filePath }: CreateReelOptions): Promise<CreatePostResult>;
|
|
53
64
|
}
|
package/dist/instagram.js
CHANGED
|
@@ -5,31 +5,34 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Instagram = exports.defaultTimeout = void 0;
|
|
7
7
|
const puppeteer_extra_plugin_stealth_1 = __importDefault(require("puppeteer-extra-plugin-stealth"));
|
|
8
|
-
const puppeteer_extra_1 =
|
|
8
|
+
const puppeteer_extra_1 = require("puppeteer-extra");
|
|
9
9
|
const node_path_1 = __importDefault(require("node:path"));
|
|
10
10
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
11
11
|
const create_post_1 = require("./actions/create-post");
|
|
12
12
|
const login_1 = require("./actions/login");
|
|
13
13
|
const create_reel_1 = require("./actions/create-reel");
|
|
14
|
+
const utils_1 = require("./utils");
|
|
14
15
|
const needs_login_action_1 = require("./actions/needs-login.action");
|
|
15
16
|
const logger_helper_1 = require("./helpers/logger.helper");
|
|
16
17
|
const delay_action_1 = require("./actions/delay.action");
|
|
17
|
-
puppeteer_extra_1.default.use((0, puppeteer_extra_plugin_stealth_1.default)());
|
|
18
18
|
exports.defaultTimeout = 10000;
|
|
19
19
|
class Instagram {
|
|
20
|
-
constructor({ browser, logLevel, screenshotOnError, htmlContentOnError, config, defaultTimeout: optionsDefaultTimeout, }) {
|
|
20
|
+
constructor({ browser, logLevel, screenshotOnError, htmlContentOnError, config, defaultTimeout: optionsDefaultTimeout, languageParam, }) {
|
|
21
21
|
this.baseUrl = "https://www.instagram.com";
|
|
22
22
|
this.browser = browser;
|
|
23
23
|
this.logLevel = logLevel;
|
|
24
|
-
this.logger = (0, logger_helper_1.createLogger)(
|
|
24
|
+
this.logger = (0, logger_helper_1.createLogger)(Instagram.name, logLevel);
|
|
25
25
|
this.screenshotOnError = screenshotOnError;
|
|
26
26
|
this.htmlContentOnError = htmlContentOnError;
|
|
27
27
|
this.config = config;
|
|
28
28
|
this.defaultTimeout = optionsDefaultTimeout !== null && optionsDefaultTimeout !== void 0 ? optionsDefaultTimeout : exports.defaultTimeout;
|
|
29
|
+
this.languageParam = languageParam;
|
|
29
30
|
}
|
|
30
31
|
static async create(options) {
|
|
31
32
|
var _a, _b, _c, _d;
|
|
32
|
-
const
|
|
33
|
+
const puppeteer = new puppeteer_extra_1.PuppeteerExtra(...(0, utils_1.requireVanillaPuppeteer)());
|
|
34
|
+
puppeteer.use((0, puppeteer_extra_plugin_stealth_1.default)());
|
|
35
|
+
const browser = await puppeteer.launch({
|
|
33
36
|
headless: options.puppeteer.headless,
|
|
34
37
|
executablePath: options.puppeteer.executablePath,
|
|
35
38
|
userDataDir: options.puppeteer.userDataDir,
|
|
@@ -51,6 +54,7 @@ class Instagram {
|
|
|
51
54
|
htmlContentOnError: (_d = options.htmlContentOnError) !== null && _d !== void 0 ? _d : true,
|
|
52
55
|
config: options.config,
|
|
53
56
|
defaultTimeout: options.defaultTimeout,
|
|
57
|
+
languageParam: options.languageParam,
|
|
54
58
|
});
|
|
55
59
|
}
|
|
56
60
|
async close() {
|
|
@@ -65,7 +69,9 @@ class Instagram {
|
|
|
65
69
|
width: 1920,
|
|
66
70
|
height: 919,
|
|
67
71
|
});
|
|
68
|
-
await page.goto(this.baseUrl
|
|
72
|
+
await page.goto(`${this.baseUrl}${this.languageParam ? `?hl=${this.languageParam}` : ""}`, {
|
|
73
|
+
waitUntil: "domcontentloaded",
|
|
74
|
+
});
|
|
69
75
|
this.logger.debug("Page initalized");
|
|
70
76
|
return page;
|
|
71
77
|
}
|
|
@@ -154,15 +160,18 @@ class Instagram {
|
|
|
154
160
|
create_post_1.waitForPostConfigureAction,
|
|
155
161
|
]);
|
|
156
162
|
this.logger.debug("Post created");
|
|
157
|
-
return
|
|
163
|
+
return {
|
|
164
|
+
...result,
|
|
165
|
+
url: (0, utils_1.createPostUrl)(result.code),
|
|
166
|
+
};
|
|
158
167
|
}
|
|
159
|
-
async createReel({ caption,
|
|
168
|
+
async createReel({ caption, filePath }) {
|
|
160
169
|
this.logger.info("Creating reel");
|
|
161
170
|
const result = await this.executeWithDiagnostics([
|
|
162
171
|
(0, delay_action_1.delayAction)(1500),
|
|
163
172
|
create_post_1.clickOnCreateButtonAction,
|
|
164
173
|
create_post_1.clickOnPostButtonAction,
|
|
165
|
-
(0, create_post_1.selectFilesAction)(
|
|
174
|
+
(0, create_post_1.selectFilesAction)([filePath]),
|
|
166
175
|
create_reel_1.tryCloseReelInfoAction,
|
|
167
176
|
create_reel_1.selectRatioAction,
|
|
168
177
|
create_post_1.clickOnNextButtonAction,
|
|
@@ -172,7 +181,10 @@ class Instagram {
|
|
|
172
181
|
create_reel_1.waitForReelConfigureAction,
|
|
173
182
|
]);
|
|
174
183
|
this.logger.debug("Reel created");
|
|
175
|
-
return
|
|
184
|
+
return {
|
|
185
|
+
...result,
|
|
186
|
+
url: (0, utils_1.createReelUrl)(result.code),
|
|
187
|
+
};
|
|
176
188
|
}
|
|
177
189
|
}
|
|
178
190
|
exports.Instagram = Instagram;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function createPostUrl(code: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function createReelUrl(code: string): string;
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
|
@@ -15,3 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./evaluated-click.util"), exports);
|
|
18
|
+
__exportStar(require("./create-post-url.util"), exports);
|
|
19
|
+
__exportStar(require("./create-reel-url.util"), exports);
|
|
20
|
+
__exportStar(require("./delay.util"), exports);
|
|
21
|
+
__exportStar(require("./require-vanilla-puppeteer"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function requireVanillaPuppeteer(): any[];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.requireVanillaPuppeteer = requireVanillaPuppeteer;
|
|
4
|
+
function requireVanillaPuppeteer() {
|
|
5
|
+
try {
|
|
6
|
+
return [require("puppeteer"), undefined];
|
|
7
|
+
}
|
|
8
|
+
catch { }
|
|
9
|
+
try {
|
|
10
|
+
return [require("puppeteer-core"), undefined];
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
return [undefined, error];
|
|
14
|
+
}
|
|
15
|
+
}
|