forked from ankitsejwal/Lyndor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.py
More file actions
240 lines (198 loc) · 8.06 KB
/
install.py
File metadata and controls
240 lines (198 loc) · 8.06 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
''' Install Lyndor software and dependencies '''
import os
import sys
import shutil
import zipfile
import json
real_path = os.path.realpath(__file__)
LYNDOR_PATH = real_path[:real_path.find('install.py')]
def check_os():
'''Check operating system'''
if sys.platform.lower() == 'darwin':
return 'macos'
elif sys.platform.lower() == 'win32':
return 'windows'
elif sys.platform.lower() == 'linux2' or sys.platform.lower() == 'linux':
return 'linux'
else:
print('operating system not supported: ' + sys.platform.lower())
sys.exit('unknown operating system.')
def set_path():
'''Set path for saving lynda folder'''
if check_os() == 'macos':
os.chdir(os.path.expanduser('~/Movies'))
return os.getcwd()
elif check_os() == 'windows' or check_os() == 'linux':
if find_a_file('Videos'):
os.chdir(os.path.expanduser('~/Videos'))
else:
os.mkdir(os.path.expanduser('~/Videos'))
os.chdir(os.path.expanduser('~/Videos'))
return os.getcwd()
def folder_path(folder):
'''Set path for desktop folder'''
if check_os() == 'macos':
os.chdir(os.path.expanduser('~/' + folder))
return os.getcwd()
elif check_os() == 'windows':
os.chdir(os.path.expanduser('~/' + folder))
return os.getcwd()
elif check_os() == 'linux':
os.chdir(os.path.expanduser('~/' + folder))
return os.getcwd()
def find_a_file(folder):
''' find a file in a directory '''
directory = os.path.expanduser('~/')
for fil in os.listdir(directory):
if fil == folder:
return True
return False
def create_folder():
''' Create lynda folder '''
path = read_settings_json('preferences', 'location')
if not os.path.exists(path):
os.makedirs(path)
print('-> Lynda folder created at: ' +
read_settings_json('preferences', 'location') + '\n')
else:
print('>>> Lynda folder already exists\n')
def create_aliases():
'''Create aliases file'''
os.chdir(LYNDOR_PATH)
if check_os() == 'windows':
run_path = 'doskey lynda= python "' + os.getcwd() + '/run.py"'
alias = open('aliases.bat', 'w')
alias.write(run_path)
alias.close()
print('-> aliases.bat file created.\n')
def lynda_folder_files():
''' create Run-Lyndor.bat in windows '''
os.chdir(LYNDOR_PATH)
bulk_download = open('Bulk Download.txt', 'w')
bulk_download.close()
shutil.move('Bulk Download.txt', read_settings_json(
'preferences', 'location') + '/Bulk Download.txt')
print('-> Bulk Download.txt file created successfully.\n')
if check_os() == 'windows':
run_path = 'python "' + os.getcwd() + '/run.py"'
lynda = open('Run-Lyndor.bat', 'a')
lynda.writelines('@ECHO OFF\n')
lynda.writelines('REM Batch file to execute run.py\n')
lynda.writelines('SET PATH=%PATH%;C:\Python27;C:\Python27\Scripts\n')
lynda.writelines(run_path + '\n')
lynda.writelines('pause')
lynda.close()
try:
os.rename('Run-Lyndor.bat', read_settings_json('preferences',
'location') + '/Run-Lyndor.bat')
except:
pass
finally:
print('-> Run-Lyndor.bat file created.\n')
def create_settings_json():
''' Create settings_json file '''
os.chdir(LYNDOR_PATH)
settings_dict = {
"credentials": {
"username": "", # use cookie for organizational login-
"password": "", # instead of username & password
"use_cookie_for_download": True, # if false, username & password will be used
},
"preferences": {
"location": set_path() + '/Lynda',
"download_subtitles": True,
"download_exercise_file": False, # feature unavailable for organizational login
"web_browser_for_exfile": 'chrome', # select chrome or firefox as a web browser
"ext-downloader-aria2-installed": False, # set True after installing aria2
"download_time": ""
},
"requirements": {
"dependencies": ['youtube-dl', 'requests', 'beautifulsoup4', 'colorama', 'selenium']
}
}
out_file = open(LYNDOR_PATH + '/settings.json', 'w')
json.dump(settings_dict, out_file, indent=4)
out_file.close()
print('\n>>> Courses will be saved at -> ' +
read_settings_json('preferences', 'location') + '\n')
print('-> settings.json file created in Lyndor folder.\
(Have a look at this file, you can edit settings here.)\n')
def read_settings_json(section, key):
''' Read settings.json '''
os.chdir(LYNDOR_PATH)
in_file = open('settings.json', 'r')
data = json.load(in_file)
in_file.close()
return data[section][key]
def install_dependencies():
'''install required softwares'''
os.chdir(LYNDOR_PATH)
in_file = open('settings.json', 'r')
requirements = json.load(in_file)
in_file.close()
dependencies = requirements['requirements']['dependencies']
for module in dependencies:
os.system('pip install ' + module)
def download_webdriver():
''' Download web driver '''
import requests
os.chdir(LYNDOR_PATH) # change directory to LYNDOR
try:
# create directory webdriver to save platform specific webdrivers
os.mkdir('webdriver')
except:
pass
print('\n-> Downloading web driver for ' + check_os())
if check_os() == 'windows':
chrome_url = 'https://chromedriver.storage.googleapis.com/2.35/chromedriver_win32.zip'
firefox_url = 'https://github.com/mozilla/geckodriver/releases/download/v0.19.1/geckodriver-v0.19.1-win64.zip'
elif check_os() == 'macos':
chrome_url = 'https://chromedriver.storage.googleapis.com/2.35/chromedriver_mac64.zip'
firefox_url = 'https://github.com/mozilla/geckodriver/releases/download/v0.19.1/geckodriver-v0.19.1-macos.tar.gz'
elif check_os() == 'linux':
chrome_url = 'https://chromedriver.storage.googleapis.com/2.35/chromedriver_linux64.zip'
firefox_url = 'https://github.com/mozilla/geckodriver/releases/download/v0.19.1/geckodriver-v0.19.1-linux64.tar.gz'
chrome = requests.get(chrome_url)
firefox = requests.get(firefox_url)
with open('webdriver/chromedriver.zip', 'wb') as f:
f.write(chrome.content)
with open('webdriver/firefoxdriver.zip', 'wb') as f:
f.write(firefox.content)
print('\n>>> Web driver downloaded inside "/Lyndor/webdriver" folder, extract the zip file and\
set the webdriver directory path to "PATH" variable, see README.md file for more detail.\n')
print('\n>>> Installation complete, Don\'t forget to have a look at settings.json\n')
def download_aria2():
''' Download aria2c for windows '''
import requests
os.chdir(LYNDOR_PATH)
if check_os() == 'windows':
try:
os.mkdir('aria2c')
except:
pass
aria = requests.get(
'https://github.com/aria2/aria2/releases/download/release-1.33.1/aria2-1.33.1-win-64bit-build1.zip')
print('\n-> Downloading aria2c for windows')
with open('./aria2c/aria2c.zip', 'wb') as f:
f.write(aria.content)
print('\n>>> aria2c.zip has been downloaded inside "Lyndor/aria2c" folder')
print('>>> unzipping aria2c.zip')
unzip('aria2c', 'aria2c.zip')
print(
'>>> aria2c.zip has been unzipped, copy its path and save to PATH variable.\n')
def unzip(directory, zip_file):
''' unzip a file '''
with zipfile.ZipFile(directory + '/' + zip_file, 'r') as f:
f.extractall(path=directory)
if __name__ == '__main__':
try:
create_settings_json()
create_folder()
create_aliases()
lynda_folder_files()
install_dependencies()
download_aria2()
download_webdriver()
except KeyboardInterrupt:
print("Program execution cancelled through keyboard!")
sys.exit(0)