All pastes #166280 Raw Edit

Untitled

public text v1 · immutable
·published 2006-09-10 18:59 UTC
rendered paste body

import os, sys, re, urllib, string

reg = re.compile(r"&#[0-9]{1,3};")
def fix(s):
    codes = reg.findall(s)
    for i in codes:
        s = s.replace(i,'%c'%(int(i.replace('&#','').replace(';','')))).replace('<em>','').replace('</em>','') #.replace('<br>','')
    return(s)

class IMDb:
    def __init__(self, url, Info=False, Details=False, Gallery=False):
        if Info == True:
            fromInfo         = urllib.urlopen(url).read()
            self.fromInfo    = fix(fromInfo).replace(' / ','').replace('</a> <i>',' ').replace('</i>','</a>')
        if Details == True:    
            self.fromDetails = urllib.urlopen(url + 'plotsummary').read()
        if Gallery == True:
            self.fromGallery = urllib.urlopen(url + 'photogallery').read()

def Galleries(fromGallery, page='0'):
    in_gallery = re.compile('"(photogallery.*?|/gallery/.*?)"><img src="(.*?jpg)"')
    in_pgLeft  = re.compile('There are.*?>(.*?) more</a>')
    Gallery = []
    Thumbs  = []
    for a in in_gallery.findall(fromGallery):
        Gallery.append(a[0])                                      # Gallery names
        thumbs  = urllib.urlopen(url + a[0][:-1] + page).read()   # open all gallery pages
        gallery = in_gallery.findall(thumbs)                      # find thumbs for 1st Gallery page of each Gallery
        for a in gallery:
            Thumbs.append(a[1].replace('th-',''))                 # changes Thumb images to full-size Images
        pgleft  = in_pgLeft.findall(thumbs)                       # parse how many thumbs are left
        for a in pgleft:
            pgLeft = int(a) / 12                                  # how many pages are in each gallery
        return Gallery, Thumbs


num = '0'
url = 'http://www.imdb.com/title/tt0315824/'

imdb = IMDb(url, Gallery=True)

gal, thumb = Galleries(imdb.fromGallery, page=num)
print gal