Idris Kadri
Front & Back End Developer & Animator

Bulk Youtube Video Downloader

Github

Languages & Tools: Java, Selenium

Downloads all videos from a chosen youtube account or search term. Also exports a CSV with information on titles, channel names and descriptions.


Sample Code



	

void start(){
file = new File("lib/chromedriver.exe");
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());


//change download path
String downloadFilepath = "Z:\Coding\My Projects\MegatokeVideos\files\videos";
HashMap chromePrefs = new HashMap();
chromePrefs.put("download.default_directory", downloadFilepath);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", chromePrefs);
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
cap.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(cap);

}

void getVideoInfo(String link) throws Exception{
videoLink = link;
driver.get(videoLink);
videoName = driver.findElement(By.xpath("//*[@id="eow-title"]")).getText();
channelName = driver.findElement(By.xpath("//*[@id="watch7-user-header"]/div/a")).getText();
channelLink = driver.findElement(By.xpath("//*[@id="watch7-user-header"]/a")).getAttribute("href");
thumbnailImage = "http://img.youtube.com/vi/" + videoLink.replace("https://www.youtube.com/watch?v=","") + "/0.jpg";

writer.append("n"" + videoLink + ""," + """ + videoName + ""," + """ + channelName + ""," + """ + channelLink + ""," + """ + thumbnailImage + """);

System.out.println(channelName + "n" + videoName + "n" + videoLink + "n" + channelLink + "n" + thumbnailImage);
Thread.sleep(delay);
}

Back