Skip to content

Instantly share code, notes, and snippets.

@bradgrimm
Created May 27, 2021 03:46
Download Textures from Ambiend CG
import httplib2
import numpy as np
from tqdm.auto import tqdm
from bs4 import BeautifulSoup, SoupStrainer
http = httplib2.Http()
categories = []
status, response = http.request('https://ambientcg.com/categories')
for link in BeautifulSoup(response, parse_only=SoupStrainer('a')):
if link.has_attr('href') and link['href'].startswith('./list?category'):
categories.append(link['href'])
textures = set()
for category in tqdm(categories):
status, response = http.request(f'https://ambientcg.com/{category}')
for link in BeautifulSoup(response, parse_only=SoupStrainer('a')):
if link.has_attr('href') and './view?id' in link['href'] and 'Substance' not in link['href']:
textures.add(link['href'])
resolution = '4K'
downloads = set()
for texture in tqdm(textures):
status, response = http.request(f'https://ambientcg.com/{texture}')
for link in BeautifulSoup(response, parse_only=SoupStrainer('a')):
if link.has_attr('href'):
url = link['href']
if url.startswith('https://ambientcg.com/get?file') and f'_{resolution}-JPG' in url:
downloads.add(url)
downloads = list(downloads)
np.random.shuffle(downloads)
for url in tqdm(downloads):
out_name = url.split('/')[-1].split('=')[-1]
out_path = f'~/data/ambientcg/{out_name}'
!wget -O $out_path $url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment