I'm trying to automate the process of uploading videos/images on instagram. For now i automated the image uploading and i'm trying to do the same thing for the videos. I'm doing this with electron and Nodejs.
for click the upload button and select an image I execute this code
const fs = require('fs'),
{remote} = require('electron'),
clipboardy = require('clipboardy'),
BrowserWindow = remote.BrowserWindow;
const LOAD_IMAGE = '.UP43G',
NEW_POST = '.glyphsSpriteNew_post__outline__24__grey_9.u-__7';
function get_files(path){
return fs.readdirSync(path, { withFileTypes: true })
.filter(dirent => dirent.isFile())
.map(dirent => __dirname + '/../../' + path + '/' + dirent.name);
}
function randomRange(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
function createWindow (session_id, hidden) {
win = new BrowserWindow({
width: 500,
height: 500
});
win.loadURL('https://www.instagram.com');
return win;
}
////select the files to upload////
var files = UPLOAD_POST_FOLDER_CUSTOM
var file_to_upload = files[randomRange(0, files.length - 1)];
///////////////////////////////////////
function async upload_image(){
// click the upload button on the page
await electron_window.webContents.executeJavaScript(`
async function click_upload_button(){
let new_post_button = document.querySelector('${NEW_POST}');
await sleep(1000);
new_post_button.click()
}
click_upload_button();
`);
// write the path of the file and press enter in the file selector
await sleep(500);
let previous_clipboard = clipboardy.readSync();
clipboardy.writeSync(file_to_upload);
await fake_input.keyTap('l', 'control');
await fake_input.keyTap('v', 'control');
await fake_input.keyTap('enter');
clipboardy.writeSync(previous_clipboard);
await sleep(2000);
}
actually this code works fine for images .jpg files. The problem that i'm facing is that during the uploading, when it opens the file selector for choose something to post it doesn't recognize the videos. I tried all the possible video extensions.
I also tried to write the file path in the file selector instead select it manually and I saw that if u write a non .jpg/.mp4 file it show a warning only images are allowed, instead, if you write the path to a .jpg file it uploads the image and if you write a file to .mp4 it closes the file manager and do nothing, like that it ignores that you are trying to upload something.
To reproduce
- go to instagram
- do the login
- click
F12for open the dev tools - click
CTRL + SHIFT + Mfor toggle the device emulation - select any device or resize the page for toggle the mobile view of the site
- reload the site
- try to upload something by clicking the bottom
+button.
(The video is 6mb (< 15mb that is the maximum) and 40seconds (<60s that is the maximum)
from Instagram upload video from pc
No comments:
Post a Comment