-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDownload_Thingiverse.ps1
More file actions
47 lines (43 loc) · 1.28 KB
/
Download_Thingiverse.ps1
File metadata and controls
47 lines (43 loc) · 1.28 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
######################################################################
#
# Written as a proof of concept should anyone need to scrub files
# from a website. Set parameters for URL, MaxPage, and Crop number to
# correctly apply this to other sites.
#
#####################################################################
# Set vars
$URL = "https://www.thingiverse.com/thing:"
$Extension = "/zip"
$CropVar = 7
$Page = 1
$Filename = ""
$MaxPage = 9999999
$Zeros = "000000"
# Test Filepath
If(!(Test-Path "C:\ThingiverseDownload\")){
New-Item -ItemType Directory -Path "C:\" -Name "ThingiverseDownload"
}
While ($Page -lt $MaxPage){
# Build URL
$ZerosPage = $Zeros + $Page
$CropTo = $ZerosPage.Length - $CropVar
$URLEnd = $ZerosPage.Substring($CropTo,$CropVar)
$ThingPage = $URL + $URLEnd
$Full = $URL + $URLEnd + $Extension
$Full
# Get Filename
Try {$GetMetadata = Invoke-WebRequest $ThingPage}
Catch {$exists = $false}
finally {
If($exists){
$GetMetadata.Content -match "<title>(?<title>.*)</title>" | out-null
$Filename = $matches['title']
$Filename
# Get File
$OutFile = "C:\ThingiverseDownload\" + $Filename + ".zip"
Invoke-WebRequest $Full -OutFile $OutFile
}}
$Filename = ""
$exists = $true
$Page ++
}