forked from rje4242/deviantart-scraper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwallpaper.ps1
71 lines (57 loc) · 2.54 KB
/
wallpaper.ps1
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
68
69
70
71
# Get the current logged-in user's profile path
$userProfile = [System.Environment]::GetFolderPath('UserProfile')
#############
# IMPORTANT
# Replace "\Documents\deviantart-scraper" with the path to deviantart-scraper.
#############
$deviantArtScraperFolder = "Documents\deviantart-scraper"
#############
# Define the folder containing the wallpapers.
$wallpaperFolder = "$userProfile\$deviantArtScraperFolder\images"
# Delete existing wallpaper files
Remove-Item -Path "$wallpaperFolder\wallpaper.jpg" -ErrorAction SilentlyContinue
Remove-Item -Path "$wallpaperFolder\wallpaper.png" -ErrorAction SilentlyContinue
Remove-Item -Path "$wallpaperFolder\wallpaper.jpeg" -ErrorAction SilentlyContinue
Remove-Item -Path "$wallpaperFolder\wallpaper.bmp" -ErrorAction SilentlyContinue
# Get the current month
$month = (Get-Date).Month
# Define the URL based on the current month
$url = switch ($month) {
9 { "https://www.deviantart.com/topic/creepy" }
10 { "https://www.deviantart.com/topic/horror" }
11 { "https://www.deviantart.com/topic/surreal" }
12 { "https://www.deviantart.com/topic/christmas" }
1 { "https://www.deviantart.com/topic/winter" }
2 { "https://www.deviantart.com/topic/cyberpunk" }
3 { "https://www.deviantart.com/topic/fantasy" }
4 { "https://www.deviantart.com/topic/science-fiction" }
5 { "https://www.deviantart.com/topic/photo-manipulation" }
default { "https://www.deviantart.com/topic/random" }
}
# Download image
python "$userProfile\$deviantArtScraperFolder\devianart.py" -f wallpaper -c 1 -r -u $url
# Get all image files in the folder
$wallpapers = Get-ChildItem -Path $wallpaperFolder -Recurse | Where-Object { $_.Extension -match "jpg|jpeg|png|bmp" }
# Check if any wallpapers were found
if ($null -eq $wallpapers -or $wallpapers.Count -eq 0) {
Write-Host "No wallpapers found in the specified folder: $wallpaperFolder"
exit
}
# Select a random wallpaper
$randomWallpaper = Get-Random -InputObject $wallpapers
# Output the selected file for debugging
Write-Host "Selected file: "$randomWallpaper.FullName
# Set the wallpaper using SystemParametersInfo
$code = @"
using System;
using System.Runtime.InteropServices;
public class Wallpaper {
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);
public static void SetWallpaper(string path) {
SystemParametersInfo(0x0014, 0, path, 0x01 | 0x02);
}
}
"@
Add-Type -TypeDefinition $code
[Wallpaper]::SetWallpaper($randomWallpaper.FullName)