# Plugin for gallery_get.
import re

# Each definition can be one of the following:
# - a string
# - a regex string
# - a function that takes source as a parameter and returns an array or a string.  (You may assume that re and urllib are already imported.)
# If you comment out a parameter, it will use the default defined in __init__.py

# identifier (default = name of this plugin after "plugin_") : If there's a match, we'll attempt to download images using this plugin.

# title: parses the gallery page for a title.  This will be the folder name of the output gallery.
title = r'<title>(.*?) - xHamster.com</title>'

# redirect: if the links in the gallery page go to an html instead of an image, use this to parse the gallery page.

# direct_links: if redirect is non-empty, this parses each redirect page for a single image.  Otherwise, this parses the gallery page for all images.
def direct_links(source):
    links = re.findall(r'"imageURL":"(\S+?)"',source)
    return map(lambda x: x.replace("\/", "/"), links)

# same_filename (default=False): if True, uses filename specified on remote link.  Otherwise, creates own filename with incremental index. 
same_filename = True
@@ -730,16 +730,532 @@
 ry page.
+%0Adef redirect(source):%0A    redirects = re.findall(r'property=%22og:url%22 content=%22(%5CS+?)%22', source)%0A    indexed_source = source%0A    while True:%0A        next_url = re.findall(r'rel=%22next%22 href=%22(%5CS+?)%22', indexed_source)%0A        if next_url:%0A          indexed_page = next_url%5B0%5D%0A          redirects.append(indexed_page)%0A          print(%22Crawling %22 + indexed_page)%0A          try:%0A            indexed_source = urlopen_text(indexed_page)%0A          except:%0A            break%0A        else:%0A          break%0A    return redirects
 %0A%0A# dire

update xHamster plugin to support multiple-page galleries