-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwallhaven
More file actions
executable file
·67 lines (55 loc) · 1.74 KB
/
wallhaven
File metadata and controls
executable file
·67 lines (55 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
# Configuration
API_KEY="pgImy4me0OJwPtR9nssFcOjcEV1GrOU4"
DOWNLOAD_DIR="/home/akanksh/Pictures/wall"
SEARCH_QUERY="$1"
MAX_PAGES=3
# Function to fetch wallpaper URLs from a specific page
fetch_wallpaper_urls() {
local page="$1"
local api_url="https://wallhaven.cc/api/v1/search?q=$SEARCH_QUERY&purity=100&ratios=landscape,16x9,16x10&sorting=views&categories=110&page=$page&apikey=$API_KEY"
echo "Fetching wallpaper URLs from page $page..."
curl -s "$api_url" | jq -r ".data[] .path"
}
# Function to download a wallpaper
download_wallpaper() {
local url="$1"
echo "Downloading: $url"
aria2c --continue=true -d "$DOWNLOAD_DIR" "$url"
}
# Function to validate dependencies
validate_dependencies() {
local dependencies=("curl" "jq" "aria2c")
for dep in "${dependencies[@]}"; do
if ! command -v "$dep" &> /dev/null; then
echo "Error: $dep is not installed. Please install it and try again."
exit 1
fi
done
}
# Main function
main() {
# Validate dependencies
validate_dependencies
# Check if search query is provided
if [[ -z "$SEARCH_QUERY" ]]; then
echo "Error: Please provide a search query as an argument."
exit 1
fi
# Create download directory if it doesn't exist
mkdir -p "$DOWNLOAD_DIR"
# Loop through pages and download wallpapers
for ((page = 1; page <= MAX_PAGES; page++)); do
urls=$(fetch_wallpaper_urls "$page")
if [[ -z "$urls" ]]; then
echo "No wallpapers found on page $page."
continue
fi
for url in $urls; do
download_wallpaper "$url"
done
done
echo "Download complete. Wallpapers saved to: $DOWNLOAD_DIR"
}
# Run the script
main