mirror of
https://github.com/saurabhan/Wallhaven-dl.git
synced 2026-01-03 08:28:01 +00:00
Updated with Categories and Purity options
This commit is contained in:
133
wallhaven-dl.py
133
wallhaven-dl.py
@@ -1,42 +1,121 @@
|
|||||||
########################################################
|
########################################################
|
||||||
# Script to Download Wallpapers from #
|
# Program to Download Wallpapers from #
|
||||||
# alpha.wallhaven.cc #
|
# alpha.wallhaven.cc #
|
||||||
# #
|
# #
|
||||||
# Author - Saurabh Bhan #
|
# Author - Saurabh Bhan #
|
||||||
# #
|
# #
|
||||||
# dated- 26 June 2016 #
|
# dated- 26 June 2016 #
|
||||||
|
# Update - 29 June 2016 #
|
||||||
########################################################
|
########################################################
|
||||||
|
|
||||||
#!usr/bin/env python3
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import bs4
|
import bs4
|
||||||
import re
|
import re
|
||||||
import requests
|
import requests
|
||||||
import time
|
|
||||||
import tqdm
|
import tqdm
|
||||||
|
import time
|
||||||
|
|
||||||
os.makedirs('Wallhaven', exist_ok=True)
|
os.makedirs('Wallhaven', exist_ok=True)
|
||||||
pgid = int(input('How Many pages you want to Download: '))
|
|
||||||
print('Number of Wallpapers to Download: ' + str(24 * pgid))
|
|
||||||
for i in range(1, pgid + 1):
|
def choice():
|
||||||
url = 'https://alpha.wallhaven.cc/latest?page=' + str(i)
|
print('''****************************************************************
|
||||||
urlreq = requests.get(url)
|
Category Codes
|
||||||
soup = bs4.BeautifulSoup(urlreq.text, 'lxml')
|
|
||||||
soupid = soup.findAll('a', {'class': 'preview'})
|
all - Every wallpaper.
|
||||||
res = re.compile(r'\d+')
|
general - For 'general' wallpapers only.
|
||||||
imgid = res.findall(str(soupid))
|
anime - For 'Anime' Wallpapers only.
|
||||||
imgext = ['jpg', 'png', 'bmp']
|
people - For 'people' wallapapers only.
|
||||||
for i in range(len(imgid)):
|
ga - For 'General' and 'Anime' wallapapers only.
|
||||||
url = 'http://wallpapers.wallhaven.cc/wallpapers/full/wallhaven-%s.' % imgid[
|
gp - For 'General' and 'People' wallpapers only.
|
||||||
i]
|
****************************************************************
|
||||||
for ext in imgext:
|
''')
|
||||||
iurl = url + ext
|
ccode = input('Enter Category: ')
|
||||||
imgreq = requests.get(iurl)
|
ALL = '111'
|
||||||
if imgreq.status_code == 200:
|
ANIME = '010'
|
||||||
print('Downloading: ' + iurl)
|
GENERAL = '100'
|
||||||
with open(os.path.join('Wallhaven', os.path.basename(iurl)), 'ab') as imageFile:
|
PEOPLE = '001'
|
||||||
for chunk in tqdm.tqdm(imgreq.iter_content(1024), total=(int(imgreq.headers['content-length']) / 1024), unit='KB'):
|
GENERAL_ANIME = '110'
|
||||||
time.sleep(0.01)
|
GENERAL_PEOPLE = '101'
|
||||||
imageFile.write(chunk)
|
if ccode.lower() == "all":
|
||||||
break
|
ctag = ALL
|
||||||
|
elif ccode.lower() == "anime":
|
||||||
|
ctag = ANIME
|
||||||
|
elif ccode.lower() == "general":
|
||||||
|
ctag = GENERAL
|
||||||
|
elif ccode.lower() == "people":
|
||||||
|
ctag = PEOPLE
|
||||||
|
elif ccode.lower() == "ga":
|
||||||
|
ctag = GENERAL_ANIME
|
||||||
|
elif ccode.lower() == "gp":
|
||||||
|
ctag = GENERAL_PEOPLE
|
||||||
|
|
||||||
|
print('''
|
||||||
|
****************************************************************
|
||||||
|
Purity Codes
|
||||||
|
|
||||||
|
sfw - For 'Safe For Work'
|
||||||
|
nsfw - For 'Not Safe For Work'
|
||||||
|
both - For both 'SFW' and 'NSFW'
|
||||||
|
****************************************************************
|
||||||
|
''')
|
||||||
|
pcode = input('Enter Purity: ')
|
||||||
|
SFW = '100'
|
||||||
|
NSFW = '010'
|
||||||
|
BOTH = '110'
|
||||||
|
if pcode.lower() == 'sfw':
|
||||||
|
ptag = SFW
|
||||||
|
elif pcode.lower() == "nsfw":
|
||||||
|
ptag = NSFW
|
||||||
|
elif pcode.lower() == "both":
|
||||||
|
ptag = BOTH
|
||||||
|
|
||||||
|
CATURL = 'https://alpha.wallhaven.cc/search?categories=' + \
|
||||||
|
ctag + '&purity=' + ptag + '&page='
|
||||||
|
return CATURL
|
||||||
|
|
||||||
|
|
||||||
|
def latest():
|
||||||
|
print('Downloading latest')
|
||||||
|
latesturl = 'https://alpha.wallhaven.cc/latest?page='
|
||||||
|
return latesturl
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
Enter choice: ''')
|
||||||
|
|
||||||
|
if Choice.lower() == 'yes':
|
||||||
|
BASEURL = choice()
|
||||||
|
else:
|
||||||
|
BASEURL = latest()
|
||||||
|
|
||||||
|
pgid = int(input('How Many pages you want to Download: '))
|
||||||
|
print('Number of Wallpapers to Download: ' + str(24 * pgid))
|
||||||
|
for i in range(1, pgid + 1):
|
||||||
|
url = BASEURL + str(i)
|
||||||
|
urlreq = requests.get(url)
|
||||||
|
soup = bs4.BeautifulSoup(urlreq.text, 'lxml')
|
||||||
|
soupid = soup.findAll('a', {'class': 'preview'})
|
||||||
|
res = re.compile(r'\d+')
|
||||||
|
imgid = res.findall(str(soupid))
|
||||||
|
imgext = ['jpg', 'png', 'bmp']
|
||||||
|
for i in range(len(imgid)):
|
||||||
|
url = 'http://wallpapers.wallhaven.cc/wallpapers/full/wallhaven-%s.' % imgid[
|
||||||
|
i]
|
||||||
|
for ext in imgext:
|
||||||
|
iurl = url + ext
|
||||||
|
imgreq = requests.get(iurl)
|
||||||
|
if imgreq.status_code == 200:
|
||||||
|
print('Downloading: ' + iurl)
|
||||||
|
with open(os.path.join('Wallhaven', os.path.basename(iurl)), 'ab') as imageFile:
|
||||||
|
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
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user