Skip to content

Instantly share code, notes, and snippets.

@xunil154
Created February 24, 2022 17:30
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xunil154/f7fa584b6525574f9a485410d0ae065f to your computer and use it in GitHub Desktop.
Save xunil154/f7fa584b6525574f9a485410d0ae065f to your computer and use it in GitHub Desktop.
Thingiverse direct download (AD Block Bypass)
#!/usr/bin/env python3
"""
====== DESCRIPTION ========
Early Feburary 2022 Thingiverse requires ad-blockers to be disabled to
download their files.
This is very very annoying so I wrote this script to pull them directly
Side note: I am blocking ads a network level, so even "Disabling" my local
ad-blocker still causes their checks to fail.
====== END DESCRIPTION ========
====== LICENSE ========
The MIT License (MIT)
Copyright © 2022 <copyright holders>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the “Software”),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
====== END LICENSE ========
"""
import requests
import sys
import time
if len(sys.argv) != 2:
print(f'Usage: {0} <thingid>')
print('Example, if the URL is: https://www.thingiverse.com/thing:5222753')
print('The thingid is 5222753')
print('All downloadable files will be downloaded and prefixed with the thing ID')
sys.exit(1)
ID=sys.argv[1]
AUTH="56edfc79ecf25922b98202dd79a291aa"
print(f'Pulling thingid detalis: {ID}')
resp = requests.get(f'https://api.thingiverse.com/things/{ID}', headers={"Authorization": f"Bearer {AUTH}"})
thing = resp.json()
if not thing or type(thing) != dict:
print(f'Error: Result was unexpected')
print(thing)
sys.exit(1)
creator = thing.get("creator",{"name":"UNKNOWN","first_name":"UNKNOWN","last_name":"UNKNOWN"})
print(f'\tName:\t{thing.get("name","UNKNOWN")}')
print(f'\tCreator:\t{creator["name"]} - {creator["first_name"]} {creator["last_name"]}')
print(f'\tCreated:\t{thing.get("added","UNKNWON")}')
print(f'\tModified:\t{thing.get("modified","UNKNWON")}')
print(f'\tNSFW?:\t{thing.get("is_nsfw","No")}')
print("")
print("If incorrect, press Ctrl+C - Downloading in 5 seconds")
time.sleep(5)
print(f"Downloading files for: {thing.get('name','UNKNOWN')}")
files_urls = thing["files_url"]
resp = requests.get(files_urls, headers={"Authorization": f"Bearer {AUTH}"})
files=resp.json()
for file in files:
print(file['name'])
print(file['direct_url'])
name = file.get('name').replace("..","_").replace("/","_").replace(" ","_")
direct_url = file.get('direct_url')
if not direct_url:
continue
resp = requests.get(file['direct_url'], headers={"Authorization": f"Bearer {AUTH}"})
if not resp:
print(f"Failed to download {file['direct_url']}")
continue
print(f"Saving to '{ID}_{name}'")
with open(f'{ID}_{name}', 'wb') as f:
f.write(resp.content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment