Skip to content

Instantly share code, notes, and snippets.

@sebastialonso
Last active July 27, 2016 18:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebastialonso/38871f61e8f3961fdcc5ddd535612691 to your computer and use it in GitHub Desktop.
Save sebastialonso/38871f61e8f3961fdcc5ddd535612691 to your computer and use it in GitHub Desktop.
YGYL automatic downloader (py2)
import requests, json
CATALOG_URL = 'http://a.4cdn.org/gif/catalog.json'
THREAD_URL = 'http://a.4cdn.org/gif/thread/'
CDN_URL = 'http://i.4cdn.org/gif/'
CRITERIA = 'YGYL'
files_saved = 0
def parse_thread(number):
global files_saved
url = get_thread_url(number)
thread = get_dict_from_url(url)
posts = thread['posts']
for post in posts:
if post.get('filename') != None:
filename = str(post['filename']) + post['ext']
with open(filename, "wb") as handle:
webm = get_resource_from_post(post)
print "{filename} OK: {ok}".format(ok=webm.ok, filename=filename)
files_saved += 1
handle.write(webm.content)
def get_dict_from_url(url):
req = requests.get(url)
return json.JSONDecoder().decode(req.text)
def get_thread_url(number):
return THREAD_URL + str(number) + ".json"
def get_resource_from_post(post):
url = CDN_URL + str(post['tim']) + post['ext']
return requests.get(url)
board = get_dict_from_url(CATALOG_URL)
print "You Groove You Lose Downloader"
for page in board:
threads = page['threads']
print "Scanning page {page}".format(page=page['page'])
for thread in threads:
if thread.get('sub') != None and (CRITERIA in thread['sub'] or CRITERIA.swapcase() in thread['sub']):
print "Found {crit} thread".format(crit=CRITERIA)
parse_thread(thread['no'])
print "{num} files saved!".format(num=files_saved)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment