Feloxy
Registered Member
- Dec 3, 2021
- 73
- 79
Hey, this will be my first real post here.
A few weeks ago I was working on an AI generated content website but had troubles with images. I didn't want to spend money on generating images with AI since those tend to be expensive (at least for a student still getting into IM).
I went on github to find a script that can download images for me based on a keyword but most scripts there have either become useless over the years or just don't work at all. But that was until I found this one that I briefly modified to do exactly what I wanted.
How It Works:
-To use the script you need to install python
-you can then edit this section of the code: KEYWORDS = ['beef', 'steak', 'meat', 'fried meat', 'fried steak'], and add your keywords. (Advanced users can pair this with AI for quick article generation)
-you can make a few other adjustments but I won't go over them here, I can reply your comments if you need assistance with adjustments.
-When you run the script it will ask if you want to download new images, type 'y', just the yyyy, dont include the quotes.
-After that it will ask how many pictures. One problem here is that it might download duplicte images so make sure to delete those.
Once you've done that the download will start.
To run the script you will need a few modules that don't come with python. On windows, and if you already have pip installed, you can run these:
pip install pathlib
pip install requests
Thats all I could think of for now. For further assistance I will be in the comments.
not a native speaker, sorry for my English
A few weeks ago I was working on an AI generated content website but had troubles with images. I didn't want to spend money on generating images with AI since those tend to be expensive (at least for a student still getting into IM).
I went on github to find a script that can download images for me based on a keyword but most scripts there have either become useless over the years or just don't work at all. But that was until I found this one that I briefly modified to do exactly what I wanted.
How It Works:
-To use the script you need to install python
-you can then edit this section of the code: KEYWORDS = ['beef', 'steak', 'meat', 'fried meat', 'fried steak'], and add your keywords. (Advanced users can pair this with AI for quick article generation)
-you can make a few other adjustments but I won't go over them here, I can reply your comments if you need assistance with adjustments.
-When you run the script it will ask if you want to download new images, type 'y', just the yyyy, dont include the quotes.
-After that it will ask how many pictures. One problem here is that it might download duplicte images so make sure to delete those.
Once you've done that the download will start.
To run the script you will need a few modules that don't come with python. On windows, and if you already have pip installed, you can run these:
pip install pathlib
pip install requests
Thats all I could think of for now. For further assistance I will be in the comments.
Python:
from pathlib import Path
from string import ascii_letters, digits
from random import choice
from os import system, name
from time import sleep
from requests import get
script_version = '2.5'
script_title = 'unsplash Downloader; FeloxyVrane (version {})'.format(script_version)
def start_script():
system('title ' + script_title if name == 'nt' else 'PS1="\[\e]0;' + script_title + '\a\]"; echo $PS1')
system('cls' if name == 'nt' else 'clear')
print (f'''
..: {script_title} :..
[-] Follow for more scripts; I will post them on blackhatworld when I get the chance.
[-]Use responsibly
[-] Version: {script_version}, a modified version of ALIILAPRO's (Programmer and developer from IRAN) script.
''')
def genString(stringLength):
letters = ascii_letters + digits
return ''.join(choice(letters) for i in range(stringLength))
def req(url):
try:
r = get(url)
except:
r = get(url)
return r
def download(number_of_images):
try:
start_script()
DOWNLOAD_FOLDER = './wp'
RES_URL = '1920x1080'
KEYWORDS = ['beef', 'steak', 'meat', 'fried meat', 'fried steak']
BASE_URL = 'https://source.unsplash.com'
Path(DOWNLOAD_FOLDER).mkdir(parents=True, exist_ok=True)
for i in range(number_of_images):
FILE_NAME = 'unsplash-{}.jpg'.format(genString(7))
FILE_PATH = '{}/{}'.format(DOWNLOAD_FOLDER,FILE_NAME)
URL = '{}/{}/?{}'.format(BASE_URL, RES_URL, choice(KEYWORDS))
print(f"[+] Start downloading image {i+1}...")
img_data = req(URL).content
with open(FILE_PATH, 'wb') as handler:
handler.write(img_data)
print(f"[+] Wallpaper [{FILE_NAME}] successfully downloaded.")
sleep(5)
except Exception as error:
print(error)
sleep(5)
def run():
while True:
start_script()
user_input = input("[?] Do you want to download new images? (y/n):")
if user_input == "y":
num_of_images = int(input("[?] Enter the number of images to download:"))
download(num_of_images)
elif user_input == "n":
break
else:
print("[!] Error: {} is not a valid parameter.".format(user_input))
sleep(3)
run()
not a native speaker, sorry for my English