Skip to content

Commit 055048c

Browse files
author
Vishesh Dembla
committed
Added a New Script To Download Spotlight Wallpapers from Windows into a new folder
1 parent 6311956 commit 055048c

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

spotlight.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
""" Script To Copy Spotlight(Lockscreen) Images from Windows """
2+
import os
3+
import shutil
4+
import errno
5+
import hashlib
6+
from PIL import Image
7+
8+
def md5(fname):
9+
""" Function to return the MD5 Digest of a file """
10+
11+
hash_md5 = hashlib.md5()
12+
with open(fname, "rb") as file_var:
13+
for chunk in iter(lambda: file_var.read(4096), b""):
14+
hash_md5.update(chunk)
15+
return hash_md5.hexdigest()
16+
17+
def make_folder(folder_name):
18+
"""Function to make the required folers"""
19+
try:
20+
os.makedirs(folder_name)
21+
except OSError as exc:
22+
if exc.errno == errno.EEXIST and os.path.isdir(folder_name):
23+
pass
24+
else:
25+
print "Error! Could not create a folder"
26+
raise
27+
28+
def get_spotlight_wallpapers(target_folder):
29+
"""Fetches wallpapers from source folder inside AppData to the
30+
newly created folders in C:\\Users\\['user.name']\\Pictures"""
31+
#PATHS REQUIRED TO FETCH AND STORE WALLPAPERS
32+
#Creating necessary folders
33+
34+
source_folder = os.environ['HOME']+"\\AppData\\Local\\Packages\\"
35+
source_folder += "Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy"
36+
source_folder += "\\LocalState\\Assets"
37+
spotlight_path_mobile = target_folder+"\\Mobile"
38+
spotlight_path_desktop = target_folder+"\\Desktop"
39+
make_folder(spotlight_path_mobile)
40+
make_folder(spotlight_path_desktop)
41+
42+
43+
#Fetching files from the source dir
44+
for filename in os.listdir(source_folder):
45+
filename = source_folder+"\\"+filename
46+
#if size of file is less than 100 KB, ignore the file
47+
if os.stat(filename).st_size > 100000:
48+
#Check resolution and classify based upon the resolution of the images
49+
50+
#name the file equal to the MD5 of the file, so that no duplicate files are to be copied
51+
img_file = Image.open(filename)
52+
if img_file.size[0] >= 1080:
53+
if img_file.size[0] > img_file.size[1]:
54+
temp_path = spotlight_path_desktop+"\\"+md5(filename)
55+
else:
56+
temp_path = spotlight_path_mobile+"\\"+md5(filename)
57+
#If file doesn't exist, copy the file to the new folders
58+
if not os.path.exists(temp_path+".png"):
59+
shutil.copy(filename, temp_path+".png")
60+
61+
if __name__ == '__main__':
62+
PATH = raw_input("Enter directory path:")
63+
get_spotlight_wallpapers(PATH)
64+
print "Lockscreen images have been copied to \""+PATH+"\""
65+

0 commit comments

Comments
 (0)