Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import json
- import threading
- from requests.packages.urllib3.exceptions import InsecureRequestWarning
- requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
- import os
- num_threads = 10
- semaphore = threading.BoundedSemaphore(value=num_threads)
- print_lock = threading.Lock()
- def download(link):
- try:
- if os.path.isfile(link[1]):
- pass
- else:
- if "webm" in link[1]:
- pass
- elif "gif" in link[1]:
- pass
- elif "mp4" in link[1]:
- pass
- else:
- r = requests.get(link[0])
- with open(link[1], 'wb') as fd:
- for chunk in r.iter_content(chunk_size=128):
- fd.write(chunk)
- except Exception as e:
- with print_lock:
- print ("[ERROR] [{0}] - {1}".format(link[0], e))
- finally:
- semaphore.release()
- if __name__ == "__main__":
- links = []
- for page in range(1, 401):
- print(page)
- 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))
- if r.text != "[]":
- for i in r.json():
- name = i['md5'] + "." + i["file_type"].split("/")[1]
- links.append([i['file_url'], name])
- else:
- print(page, "end")
- break
- for link in links:
- semaphore.acquire()
- t = threading.Thread(target=download, args=(link,))
- t.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement