-
Notifications
You must be signed in to change notification settings - Fork 5
/
Direct-Link-21022023.py
67 lines (59 loc) · 2.59 KB
/
Direct-Link-21022023.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
import re
def main():
links = []
input_source = input("Enter 'f' to read from a file or 't' to type the link (or press enter to quit): ")
while input_source not in ["f", "F", "t", "T", ""]:
print("Invalid input. Please try again.")
input_source = input("Enter 'f' to read from a file or 't' to type the link (or press enter to quit): ")
if input_source in ["f","F"]:
try:
with open("input.txt", "r") as f:
links = f.readlines()
links = [x.strip() for x in links]
except:
# Go to typing link mode
input_source = "t"
print("Could not find input.txt. Please enter the link instead.")
if input_source in ["t", "T"]:
while True:
link = input("Enter the link (or press enter to quit): ")
if link == "":
break
links.append(link)
else:
return
new_links = []
for link in links:
new_link_o = new_links_ob = new_link_d = new_link_g = None
if "onedrive.live.com" in link:
if re.search(r"https://.*width=", link):
new_link_o = re.sub(r"embed", "download", re.search(r"https://.*width=", link).group())
new_link_o = new_link_o.rstrip("\" width=")
elif "my.sharepoint.com" in link:
if re.search(r"https://.*\?", link):
new_links_ob = re.search(r"https://.*\?", link).group()
new_links_ob = new_links_ob + "download=1"
elif "www.dropbox.com" in link:
new_link_d = link.replace("www.dropbox.com", "dl.dropboxusercontent.com")
elif "drive.google.com" in link:
google_drive_link = re.search(r"https://drive.google.com/file/d/(.*)/view", link)
if google_drive_link:
new_link_g = "https://drive.google.com/uc?export=download&id=" + google_drive_link.group(1)
if new_link_o or new_links_ob or new_link_d or new_link_g:
new_links.append(new_link_o or new_links_ob or new_link_d or new_link_g)
else:
print(f"{link} is not a link from OneDrive, OneDrive for Business, Dropbox, or Google Drive.")
if new_links:
print("\n".join(new_links))
input("Press enter to write to output.txt and quit.")
try:
with open("output.txt", "w") as f:
for l in new_links:
f.write(l + "\n")
except:
print("An error occurred while opening the file. Exiting.")
exit()
else:
print("No links found.")
if __name__ == "__main__":
main()