-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
160 lines (134 loc) · 4.45 KB
/
main.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import os
import threading
import argparse
from cryptography.fernet import Fernet
from sys import exit
from packaging import version
from tkinter import messagebox
import sys
import gui
import loginGUI
import requests
import webbrowser
from tkinter import Tk
import pyperclip
import win10toast
from mega import Mega
from mega import errors
if getattr(sys, 'frozen', False):
VERSION = open("VERSION", "r").read().splitlines()
versionFile = requests.get(
r"https://raw.githubusercontent.com/CUPZYY/EasyMegaUpload/main/VERSION").text.splitlines()
var = version.parse(VERSION[0]) < version.parse(versionFile[0])
if var:
root = Tk()
root.withdraw()
root.protocol("WM_DELETE_WINDOW", exit)
versionFile = requests.get(
r"https://raw.githubusercontent.com/CUPZYY/EasyMegaUpload/main/VERSION").text.splitlines()
updatePrompt = messagebox.askquestion("Update Available!",
f"There is a newer version of the program available (v{versionFile[0]}). Would you like to download it now?")
if updatePrompt[0] == "y":
webbrowser.open(versionFile[1])
exit()
else:
exit()
mega = Mega()
toaster = win10toast.ToastNotifier()
gui = gui.guiClass()
uploading = False
appdata = os.getenv('APPDATA')
appdataFolder = f"{appdata}\\EasyMegaUpload"
# if len(sys.argv) > 1:
# filepath = sys.argv[1]
# print(filepath)
# else:
# filepath = sys.argv[0]
if not os.path.exists(appdataFolder):
os.mkdir(appdataFolder)
parser = argparse.ArgumentParser(description="Uploads files to mega, easily")
parser.add_argument("-p", "--path", type=str, metavar="", help="The filepath to the file you want to upload",
required=True)
args = parser.parse_args()
filepath = args.path
try:
loginread = open(fr"{appdataFolder}\login", "r").read().splitlines()
except FileNotFoundError:
loginGUI.loginGUI()
exit()
if os.stat(fr"{appdataFolder}\login").st_size == 0:
loginGUI.loginGUI()
exit()
def init():
try:
loginread[1]
except IndexError:
loginGUI.loginGUI()
exit()
try:
open(fr"{appdataFolder}\key", "r").read().splitlines()
except FileNotFoundError:
loginGUI.loginGUI()
exit()
if os.stat(fr"{appdataFolder}\key").st_size == 0:
loginGUI.loginGUI()
exit()
else:
key = open(fr"{appdataFolder}\key", "rb", ).read()
global f
f = Fernet(bytes(key))
init()
def passToaster():
toaster.show_toast("EasyMegaUpload",
f"The email/password was incorrect.\nPlease try again",
icon_path="toaster.ico",
duration=0,
threaded=True)
def passToaster():
toaster.show_toast("EasyMegaUpload",
f"The email/password was incorrect.\nPlease try again",
icon_path="toaster.ico",
duration=0,
threaded=True)
def successToaster():
toaster.show_toast(title="EasyMegaUpload",
msg=f"Successfully uploaded {os.path.basename(filepath)}\nThe link was copied to your clipboard",
icon_path="toaster.ico",
duration=0,
threaded=True)
def unsuccessToaster():
toaster.show_toast("EasyMegaUpload",
f"Unsuccessfully uploaded {os.path.basename(filepath)}",
icon_path="toaster.ico",
duration=0,
threaded=True)
def upload():
try:
emailencoded = loginread[0].encode()
passencoded = loginread[1].encode()
emailDecrypted = f.decrypt(emailencoded)
passDecrypted = f.decrypt(passencoded)
emaildecoded = emailDecrypted.decode()
passdecoded = passDecrypted.decode()
m = mega.login(email=str(emaildecoded), password=str(passdecoded))
except errors.RequestError:
passToaster()
return
folderName = "EasyUpload"
findfolder = m.find(folderName)
if findfolder is None:
m.create_folder(folderName)
try:
file = m.upload(filepath, findfolder[0])
fileurl = m.get_upload_link(file)
except:
unsuccessToaster()
return
pyperclip.copy(fileurl)
successToaster()
return
uplfoadThread = threading.Thread(target=gui.gui)
uplfoadThread.setDaemon(True)
uplfoadThread.start()
upload()
exit()