Bulk blog image downlaoder (unsplash) +script, no API key needed.

Status
Not open for further replies.

Feloxy

Registered Member
Joined
Dec 3, 2021
Messages
73
Reaction score
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.
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
 
Thank you for the share mate. Currently looking for some thing like this>
Get kw from csv > serch for image> add as featured image

Maybe chat gpt can modify the script. I ll give a try. If success I ll share here.

I also like to share some ideas on automated AI content as Im currently doing some thing same. Let me know if I can DM you.
 
Thank you for the share mate. Currently looking for some thing like this>
Get kw from csv > serch for image> add as featured image

Maybe chat gpt can modify the script. I ll give a try. If success I ll share here.

I also like to share some ideas on automated AI content as Im currently doing some thing same. Let me know if I can DM you.
Yeah, you can send me a dm
 
the script is working, i got it to work with a csv (with GPT...)
the problem is: there are different ID's for the very same picture (size and resolution) which means if you see 1000 pictures on the website it could be that there are 4 duplicates on the website for every single one. (EDIT: making it 4000 downloads)
if you limit the downloaded pictures you end up with e.g. 250 pictures, 1 "original" and 3 duplicates.
so it's the websites fault, i guess but don't have time or the knowledge to dive into it.
in anyway: thanks for sharing, great work!

import csv
with open('keywords.csv', 'r') as input_file:
csv_reader = csv.reader(input_file)
keywords = []
for row in csv_reader:
keywords.append(row[0])
 
Last edited:
I could never understand why people apologise for their English.
I don't see English people apologising for their Spanish.
Anyway... thank you for sharing.

no soy un hablante nativo, lo siento por mi español
 
Status
Not open for further replies.
Back
Top