Advertisement
Guest User

Untitled

a guest
Nov 2nd, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.58 KB | None | 0 0
  1. import requests
  2. import json
  3. import threading
  4. from requests.packages.urllib3.exceptions import InsecureRequestWarning
  5. requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
  6. import os
  7.  
  8. num_threads = 10
  9. semaphore = threading.BoundedSemaphore(value=num_threads)
  10. print_lock = threading.Lock()
  11.  
  12.    
  13. def download(link):
  14.     try:
  15.         if os.path.isfile(link[1]):
  16.             pass
  17.         else:
  18.             if "webm" in link[1]:
  19.                 pass
  20.             elif "gif" in link[1]:
  21.                 pass
  22.             elif "mp4" in link[1]:
  23.                 pass
  24.             else:
  25.                 r = requests.get(link[0])
  26.                 with open(link[1], 'wb') as fd:
  27.                     for chunk in r.iter_content(chunk_size=128):
  28.                         fd.write(chunk)
  29.     except Exception as e:
  30.         with print_lock:
  31.             print ("[ERROR] [{0}] - {1}".format(link[0], e))
  32.     finally:
  33.         semaphore.release()
  34.    
  35. if __name__ == "__main__":
  36.     links = []
  37.     for page in range(1, 401):
  38.         print(page)
  39.         r = requests.get("https://capi-v2.sankakucomplex.com/posts?page={0}&limit=100&tags=threshold:3+rating:e+otoko_no_ko+order:quality+-flash".format(page))
  40.         if r.text != "[]":
  41.             for i in r.json():
  42.                 name = i['md5'] + "." + i["file_type"].split("/")[1]
  43.                 links.append([i['file_url'], name])
  44.         else:
  45.             print(page, "end")
  46.             break
  47.  
  48.     for link in links:
  49.         semaphore.acquire()
  50.         t = threading.Thread(target=download, args=(link,))
  51.         t.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement