forked from Biswa96/WinLight
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWinLight.py
More file actions
137 lines (122 loc) · 6.09 KB
/
WinLight.py
File metadata and controls
137 lines (122 loc) · 6.09 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/python
# Import modules
import requests
import re
import os
import hashlib
import pathlib
import colorama
import random
# Set environment variables
ImageUrl = "https://img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData"
JsonUrls = [
"https://arc.msn.com/v3/Delivery/Placement?&fmt=json&cdm=1&ctry=NL&pid=209567",
"https://arc.msn.com/v3/Delivery/Placement?&fmt=json&cdm=1&ctry=NL&pid=279978",
"https://arc.msn.com/v3/Delivery/Placement?&fmt=json&cdm=1&ctry=NL&pid=338380",
"https://arc.msn.com/v3/Delivery/Placement?&fmt=json&cdm=1&ctry=NL&pid=338387",
"https://arc.msn.com/v3/Delivery/Placement?&fmt=json&cdm=1&ctry=NL&pid=338387",
"https://arc.msn.com/v3/Delivery/Placement?&fmt=json&cdm=1&ctry=ES&pid=209567",
"https://arc.msn.com/v3/Delivery/Placement?&fmt=json&cdm=1&ctry=ES&pid=279978",
"https://arc.msn.com/v3/Delivery/Placement?&fmt=json&cdm=1&ctry=ES&pid=338380",
"https://arc.msn.com/v3/Delivery/Placement?&fmt=json&cdm=1&ctry=ES&pid=338387",
"https://arc.msn.com/v3/Delivery/Placement?&fmt=json&cdm=1&ctry=ES&pid=338387",
"https://arc.msn.com/v3/Delivery/Placement?&fmt=json&cdm=1&ctry=BE&pid=209567",
"https://arc.msn.com/v3/Delivery/Placement?&fmt=json&cdm=1&ctry=BE&pid=279978",
"https://arc.msn.com/v3/Delivery/Placement?&fmt=json&cdm=1&ctry=BE&pid=338380",
"https://arc.msn.com/v3/Delivery/Placement?&fmt=json&cdm=1&ctry=BE&pid=338387",
"https://arc.msn.com/v3/Delivery/Placement?&fmt=json&cdm=1&ctry=BE&pid=338387",
"https://arc.msn.com/v3/Delivery/Placement?&fmt=json&cdm=1&ctry=UK&pid=209567",
"https://arc.msn.com/v3/Delivery/Placement?&fmt=json&cdm=1&ctry=UK&pid=279978",
"https://arc.msn.com/v3/Delivery/Placement?&fmt=json&cdm=1&ctry=UK&pid=338380",
"https://arc.msn.com/v3/Delivery/Placement?&fmt=json&cdm=1&ctry=UK&pid=338387",
"https://arc.msn.com/v3/Delivery/Placement?&fmt=json&cdm=1&ctry=UK&pid=338387",
"https://arc.msn.com/v3/Delivery/Placement?&fmt=json&cdm=1&ctry=IT&pid=209567",
"https://arc.msn.com/v3/Delivery/Placement?&fmt=json&cdm=1&ctry=IT&pid=279978",
"https://arc.msn.com/v3/Delivery/Placement?&fmt=json&cdm=1&ctry=IT&pid=338380",
"https://arc.msn.com/v3/Delivery/Placement?&fmt=json&cdm=1&ctry=IT&pid=338387",
"https://arc.msn.com/v3/Delivery/Placement?&fmt=json&cdm=1&ctry=IT&pid=338387",
"https://arc.msn.com/v3/Delivery/Placement?&fmt=json&cdm=1&ctry=FR&pid=209567",
"https://arc.msn.com/v3/Delivery/Placement?&fmt=json&cdm=1&ctry=FR&pid=279978",
"https://arc.msn.com/v3/Delivery/Placement?&fmt=json&cdm=1&ctry=FR&pid=338380",
"https://arc.msn.com/v3/Delivery/Placement?&fmt=json&cdm=1&ctry=FR&pid=338387",
"https://arc.msn.com/v3/Delivery/Placement?&fmt=json&cdm=1&ctry=FR&pid=338387",
"https://arc.msn.com/v3/Delivery/Placement?&fmt=json&cdm=1&ctry=NL&pid=310093",
"https://arc.msn.com/v3/Delivery/Placement?&fmt=json&cdm=1&ctry=ES&pid=310093",
"https://arc.msn.com/v3/Delivery/Placement?&fmt=json&cdm=1&ctry=BE&pid=310093",
"https://arc.msn.com/v3/Delivery/Placement?&fmt=json&cdm=1&ctry=UK&pid=310093",
"https://arc.msn.com/v3/Delivery/Placement?&fmt=json&cdm=1&ctry=IT&pid=310093",
"https://arc.msn.com/v3/Delivery/Placement?&fmt=json&cdm=1&ctry=FR&pid=310093",
]
random.shuffle(JsonUrls)
SearchPattern = "(?<=imageFileData/).*?(?=\?ver)"
HttpHeader = {
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'en-US,en;q=0.9',
'Cache-Control': 'no-cache',
'User-Agent': 'WindowsShellClient/9.0.40929.0 (Windows)'
}
# Some colors
ColorRed = colorama.Fore.RED
ColorGreen = colorama.Fore.GREEN
ColorBlue = colorama.Fore.BLUE
ColorCyan = colorama.Fore.CYAN
ColorYellow = colorama.Fore.YELLOW
ColorBlack = colorama.Fore.BLACK
ColorWhite = colorama.Fore.WHITE
StyleBright = colorama.Style.BRIGHT
StyleDim = colorama.Style.DIM
StyleNormal = colorama.Style.NORMAL
ResetColor = colorama.Style.RESET_ALL
# Try all Urls
for JsonUrl in JsonUrls:
print(
f'{ColorWhite}Parsing {StyleDim}{JsonUrl}{StyleNormal} to find images...{ResetColor}'
)
# Download JSON file
Response = requests.get(JsonUrl, headers=HttpHeader)
content_raw = Response.text
# Remove back slashes
content_raw = content_raw.replace("\\", "")
# Remove opening quotes
content_raw = content_raw.replace("\"{", "{")
# Remove closing quotes
content_raw = content_raw.replace("}\"", "}")
# Get the hashes from links and download
hash = re.findall(SearchPattern, content_raw, re.DOTALL)
for i in hash:
j = ImageUrl + "/" + i
FileName = i + ".jpg"
print(f'{ColorCyan}Downloading {StyleDim}{j}{ResetColor}')
Response = requests.get(j, headers=HttpHeader)
ResponseSize = len(Response.content)
#
if Response.status_code != 200:
print(
f'{ColorRed} HTTP status code {StyleBright}{Response.status_code}{StyleDim} for {StyleDim}{j}{ResetColor}'
)
continue
# Ignore files less that 2 KB which are blank
if ResponseSize < 2048:
print(
f'{ColorRed}Ignoring {i}: {StyleBright}file too small ({ResponseSize} bytes){ResetColor}'
)
continue
# Check if the file already exist
if os.path.isfile(FileName):
OldHash = hashlib.md5(
pathlib.Path(FileName).read_bytes()).hexdigest()
NewHash = hashlib.md5(Response.content).hexdigest()
# Do we have the same content on disk?
if OldHash != NewHash:
NewFileName = i + '-' + NewHash + '.jpg'
print(
f'{ColorCyan}File already exist with different content, renaming {StyleBright}{FileName}{StyleNormal} to {StyleBright}{NewFileName}{ResetColor}'
)
FileName = NewFileName
print(
f'{ColorYellow}Ignoring {i}: {StyleBright}already downloaded (identical content on disk){ResetColor}'
)
continue
with open(FileName, 'wb') as file:
file.write(Response.content)
print(f'{ColorGreen}Saved as {StyleBright}{FileName}{ResetColor}')