Idris Kadri
Front & Back End Developer & Animator

Bulk Instagram Video Downloader

Github

Languages & Tools: Java, Selenium

Downloads all videos from a chosen instagram account. Also exports a CSV with information on hash tags and descriptions.


Sample Code



	

void getLinks() throws Exception{

instaVidLinks = new ArrayList<>();
createFile2();

List elements;
elements = driver.findElements(By.tagName("a"));
Thread.sleep(1000);

for (int i = 0; i < elements.size(); i++) {
String instaLink = elements.get(i).getAttribute("href");
if (instaLink.contains("https://www.instagram.com/p/")) {
instaVidLinks.add(instaLink);
writer2.append(""" + instaLink.replace("/?taken-by=megatokebyyets","") + ""n");
System.out.println("link " + i + " : " + instaVidLinks.get(instaVidLinks.size()-1));
}
}

saveFile2();

System.out.println("nn");

for (int i = 0; i < instaVidLinks.size(); i++) {
createFile();
writer.append(""" + instaVidLinks.get(i).replace("/?taken-by=megatokebyyets","") + "",");
System.out.println((i+1) + "n" + instaVidLinks.get(i));
getDescription(instaVidLinks.get(i));
downloadVideo(instaVidLinks.get(i));

System.out.println();
saveFile();
}

}

void getDescription(String pageName) throws Exception{
driver.get(pageName);

Thread.sleep(delay);

String[] descriptionText = driver.findElement(By.xpath("//*[@id="react-root"]/section/main/div/div/article/div[2]/div[1]/ul/li")).getText().split(" ");
String description = "";


for (int i = 0; i < descriptionText.length; i++) {
if (descriptionText[i].contains("@")) {
description = description + descriptionText[i] + "|";
System.out.println(description.replace("|",""));
}
}

if(description.endsWith("|")){
description = description.substring(0,description.length()-1);
}
writer.append(""" + description + "",");
}

Back