From e86ec7223bbde093b05fb875879a6fbc6ec4db15 Mon Sep 17 00:00:00 2001 From: bafoed Date: Sat, 17 Dec 2016 09:56:34 +0300 Subject: [PATCH 1/2] Fixed bug with extension guessing. --- wallhaven-dl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wallhaven-dl.py b/wallhaven-dl.py index 3ea21d5..10d9a47 100644 --- a/wallhaven-dl.py +++ b/wallhaven-dl.py @@ -124,7 +124,7 @@ def main(): for chunk in tqdm.tqdm(imgreq.iter_content(1024), total=(int(imgreq.headers['content-length']) / 1024), unit='KB'): time.sleep(0.01) imageFile.write(chunk) - break + break if __name__ == '__main__': main() From 8e77b9e74f9a01998e1c6c7da5ed6ab30786e135 Mon Sep 17 00:00:00 2001 From: bafoed Date: Sat, 17 Dec 2016 09:57:58 +0300 Subject: [PATCH 2/2] Added ability to download images from search. --- wallhaven-dl.py | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/wallhaven-dl.py b/wallhaven-dl.py index 10d9a47..c93a4bc 100644 --- a/wallhaven-dl.py +++ b/wallhaven-dl.py @@ -15,6 +15,7 @@ import re import requests import tqdm import time +import urllib os.makedirs('Wallhaven', exist_ok=True) @@ -25,7 +26,7 @@ def login(): req = requests.post('https://alpha.wallhaven.cc/auth/login', data={'username':username, 'password':password}) return req.cookies -def choice(): +def category(): print('''**************************************************************** Category Codes @@ -89,18 +90,31 @@ def latest(): latesturl = 'https://alpha.wallhaven.cc/latest?page=' return (latesturl, dict()) +def search(): + query = input('Enter search query: ') + searchurl = 'https://alpha.wallhaven.cc/search?q=' + \ + urllib.parse.quote_plus(query) + '&page=' + return (searchurl, dict()) def main(): - Choice = input('''Do you want to choose categories or want to download latest wallpapers: - Enter "yes" for choosing categories - Enter "no" for Downloading latest wallpapers + Choice = input('''Choose how you want to download the image: - Enter choice: ''') + Enter "category" for downloading wallpapers from specified categories + Enter "latest" for downloading latest wallpapers + Enter "search" for downloading wallpapers from search - if Choice.lower() == 'yes': - BASEURL, cookies = choice() - else: + Enter choice: ''').lower() + while Choice not in ['category', 'latest', 'search']: + if Choice != None: + print('You entered an incorrect value.') + choice = input('Enter choice: ') + + if Choice == 'category': + BASEURL, cookies = category() + elif Choice == 'latest': BASEURL, cookies = latest() + elif Choice == 'search': + BASEURL, cookies = search() pgid = int(input('How Many pages you want to Download: ')) print('Number of Wallpapers to Download: ' + str(24 * pgid))