@@ -0,0 +1,1847 @@
+from threading import Thread, Lock%0Afrom queue import Queue%0Aimport os, requests, re%0A%0Aclass fileControl:%0A    fileDir = '/Volumes/Seagate Backup Plus Drive/Down/Hee/'%0A    fileName = fileDir + '%7B%7D.jpg'%0A%0A    def __init__(self):%0A        fileNames = os.listdir(fileControl.fileDir)%0A        if fileNames%5B0%5D == '.DS_Store': self.baseNum = len(fileNames) - 1%0A        else: self.baseNum = len(fileNames)%0A%0Aclass DLThread(Thread):%0A    lock = Lock()%0A    control = fileControl()%0A%0A    def __init__(self, queue):%0A        Thread.__init__(self, daemon=True)%0A        self.queue = queue%0A%0A    def _process(self, url):%0A        print('Begin downloading:%5Cn%7B%7D%5Cn%5Cn'.format(url))%0A        source = requests.get(url).text%0A        imgPattern = re.compile('http:%5C/%5C/.*?mo.*?%5C.jpg')%0A        imgs = imgPattern.findall(source)%0A        base = self.control.baseNum%0A        DLThread.lock.acquire()%0A        self.control.baseNum += len(imgs)%0A        DLThread.lock.release()%0A        for index, imgURL in enumerate(imgs):%0A            with open(self.control.fileName.format(base + index), 'wb') as img:%0A                img.write(requests.get(imgURL).content)%0A        return len(imgs)%0A%0A    def run(self):%0A        url = self.queue.get()%0A        last = None%0A        while url != last:%0A            last = url%0A            count = self._process(url)%0A            print('%7B%7D images downloaded. %7B%7D URLs in the queue'.format(count, self.queue.qsize()))%0A            url = self.queue.get()%0A%0Aqueue = Queue()%0Athreads = %5BDLThread(queue) for _ in range(5)%5D%0Afor thread in threads: thread.start()%0A%0Alast = os.popen('pbpaste', 'r').read()%0AurlPattern = re.compile('http:%5C/%5C/.*?')%0Awhile True:%0A    try:%0A        text = os.popen('pbpaste', 'r').read()%0A        if not text or text == last or not urlPattern.match(text): continue%0A        last = text%0A        queue.put(text)%0A    except KeyboardInterrupt:%0A        break%0A

Add image downloader