This is just a script I made that will download every image in a public photobucket gallery.
just enter a directory and a photobucket gallery link
what im working on: http://pastebin.com/m672e6491
im gonna parse PB feed.rss's for all media:content url attributes, and for normal pages parse all a href attributes that end with a .jpg
just enter a directory and a photobucket gallery link
Code:
import urllib, re, os, xml.parsers.expat
imgs = []
DLbarLen = 40
def mkdir():
global DLlocation
DLlocation = raw_input('Enter download folder:\n')
if DLlocation:
root, tail = os.path.splitdrive(DLlocation)
os.chdir(root+os.sep)
try:
os.makedirs(DLlocation)
os.chdir(DLlocation)
DLlocation = os.getcwd()
except:
try:
os.path.exists(DLlocation)
os.chdir(DLlocation)
DLlocation = os.getcwd()
except:
print "Entered bad pathname."
mkdir()
else:
print "Did not enter pathname."
mkdir()
def getimgs():
def start_element(name, attrs):
if name == 'media:content':
imgs.append(attrs['url'])
site = raw_input('Enter photobucket gallery:\n')
site = re.split('[a-zA-Z0-9_.?=-]*$',site)[0] + 'feed.rss'
print '\n'
parse = xml.parsers.expat.ParserCreate()
parse.StartElementHandler = start_element
gallery = urllib.urlopen(site)
source = gallery.read()
parse.Parse(source, 1)
total = len(imgs)
imgName = re.compile('[a-zA-Z0-9_-]+\.(jpeg|gif|png|jpg)$')
for url in imgs:
pos = imgs.index(url)+1
img = imgName.search(url)
file = img.group()
barnum = pos*DLbarLen/total
blanknum = DLbarLen-barnum
bars = '='*barnum
blanks = ' '*blanknum
if pos == total:
print '\033[ACompleted.'+' '*55
else:
print '\033[ADownloading image '+str(pos)+' of '+str(total)
print "["+bars+blanks+"]"+"\033[A"
DLpic(url, file)
print "\nFinished downloading all "+str(total)+" images in gallery!\033[A\n"
def DLpic(url,filename):
sock = urllib.urlopen(url)
img = sock.read()
location = open(DLlocation+os.sep+filename, "wb")
location.write(img)
location.close()
mkdir()
getimgs()
im gonna parse PB feed.rss's for all media:content url attributes, and for normal pages parse all a href attributes that end with a .jpg