Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Photobucket gallery downloader
#1
This is just a script I made that will download every image in a public photobucket gallery.

[Image: 2lawzm.png]

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()
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
[Image: sig.php]
Reply


Messages In This Thread
Photobucket gallery downloader - by Nyx- - 12-10-2009, 02:51 PM
RE: Photobucket gallery downloader - by Fallen - 12-10-2009, 08:05 PM
RE: Photobucket gallery downloader - by Nyx- - 12-12-2009, 03:14 AM
RE: Photobucket gallery downloader - by Extasey - 12-12-2009, 03:41 AM
RE: Photobucket gallery downloader - by MarkW7 - 12-13-2009, 02:13 PM
RE: Photobucket gallery downloader - by Gaijin - 12-13-2009, 02:24 PM
RE: Photobucket gallery downloader - by Gos - 12-13-2009, 03:33 PM
RE: Photobucket gallery downloader - by Nyx- - 12-13-2009, 04:53 PM
RE: Photobucket gallery downloader - by Gaijin - 12-13-2009, 05:10 PM
RE: Photobucket gallery downloader - by Nyx- - 12-13-2009, 09:05 PM
RE: Photobucket gallery downloader - by Gaijin - 12-13-2009, 09:15 PM
RE: Photobucket gallery downloader - by Nyx- - 12-13-2009, 09:30 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)