-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdiscordCacheToImage.py
128 lines (107 loc) · 4.51 KB
/
discordCacheToImage.py
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
import getpass
import os
from shutil import copyfile
import sys
def main():
global discordDir
stringpiece1 = (r"C:\Users")
stringpiece2 = (r"AppData\Roaming\Discord")
value=f"{stringpiece1}\{getpass.getuser()}\{stringpiece2}"
if os.path.isdir(value):
print("Automatically found Discord directory.")
discordDir = value
else:
print("Discord directory could not be located. Please specify the location")
def getDir():
discordDir = input(r"Discord directory: ")
if os.path.isdir(discordDir):
print("Discord directory found!")
return discordDir
else:
print("This directory doesn't exist. Please try again.")
discordDir = getDir()
return discordDir
discordDir = getDir()
print("Now that the directory has been found. I'll do some quick checks to ensure everything is where it's supposed to be.")
input("Press any key to continue or ctrl+c to quit.")
newdir = f"{discordDir}\Cache"
if os.path.isdir(newdir):
num=0
for i in os.listdir(newdir):
if str(i)[:4] == "data":
pass
elif str(i) == "index":
pass
else:
num+=1
print(f"Found {i}")
print(f"Found a total of {num} images!")
input("Enter to continue")
print(f"\n\n\n\n\n\n")
print(f"The next thing to do is to decide on how many of these images you want to download.")
def allorcustom():
print("a) All the images b) Custom number")
a = input("a/b: ")
if a.lower() == "a":
return 0
elif a.lower() == "b":
return 1
else:
print("I don't understand this input.")
input("Press enter to try again")
val = allorcustom()
return val
val = allorcustom()
if val == 0:
images_count = num
else:
images_count = int(input("How many images would you like to download: "))
if images_count > num:
images_count = num
input("Press enter to continue")
print(f"\n\n\n\n\n\n\n")
print("Next, we need to specify a directory to dump all the images into")
print("Please create a folder and specify its location below")
def getDirSave():
SaveDir = input(r"Save-to directory: ")
if os.path.isdir(SaveDir):
print("Directory found!")
return SaveDir
else:
print("This directory doesn't exist. Please try again.")
SaveDir = getDirSave()
return SaveDir
SaveDir = getDirSave()
print(f"\n\n\n\n\n\n\n")
print("WARNING!")
print("If you have specified the incorrect directory please exit the program now!")
print("If you make any mistakes here, it'll be very hard to undo the damages")
print("By pressing enter you agree that any damages caused by incorrect directory assignment is completely your own fault.")
print(f"All {images_count} file(s) will be saved to: {SaveDir}")
input("Press enter to continue the process at your own discretion or ctrl+c to exit")
FileListArray=[]
FileList=os.listdir(newdir)
for i in FileList:
if str(i)[:4] == "data":
pass
elif str(i) == "index":
pass
else:
FileListArray.append(i)
for i in range(int(images_count)):
fileName = FileListArray[i]
fileloc = f"{newdir}\{fileName}"
newfile = f"{SaveDir}\{fileName}.png"
print(f"Copied to {newfile}")
try:
copyfile(fileloc, newfile)
except Exception as e:
print(f"{e}")
print(f"\nThis probably means that you didn't run as administrator so the script doesn't have permission to copy paste files.")
input("")
sys.exit()
else:
print("Error! A cache folder doesn't exist.")
input("Press enter to try again or ctrl+c to quit")
main()
main()