Saturday, 29 September 2012

Downloading Photobucket albums with Matlab and wget

Here's a script to take the pain out of downloading an album of photos from photobucket.

It uses matlab to search a particular url for photo links (actually it looks for the thumbnail links and modifies the string to give you the full res photo link), then uses a system command call to wget to download the photos All in 8 lines of code! 

Ok to start you need the full url for your album. The '?start=all' bit at the end is important because this will show you all the thumbnails on a single page. Then simply use regexp to find the instances of thumbnail urls. Then loop through each link, strip the unimportant bits out, remove the 'th_' from the string which indicates the thumbnail version of the photo you want, and call wget to download the photo. Easy-peasy!

s = urlread('http://s1270.photobucket.com/albums/SERVERNAME/YOURUSERNAME/YOURALBUMNAME/?start=all');
indices = regexp(s,'pbthumburl=');
for k=1:length(indices)
tmp=strtrim(s(indices(k):indices(k)+100));
tmp=tmp(regexp(tmp,'"','once')+1:end);
tmp=tmp(1:regexp(tmp,'"','once')-1);
system(['wget ',tmp(1:regexp(tmp,'th_')-1),tmp(regexp(tmp,'th_')+3:end)]);
end
view raw photobucket.m hosted with ❤ by GitHub

No comments: