-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathFunctions.py
216 lines (184 loc) · 8.52 KB
/
Functions.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
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
'''
Author : Zdravko Georgiev (r00tmebaby)
Github : https://github.com/r00tmebaby
License : MIT
Copyright (c) 2019 Zdravko Georgiev (r00tmebaby)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the
Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
'''
##############################################
# Lynda Downloading Script
# by r00tme 26/01/2019
# version: 1.0 Downloading with Pre-Specified List
###############################################
# Options:
# Creating Category Folder Automatically
# Creating Course Sub-folder Automatically
# Creating Course Difficulty Folder Prefix Automatically
# Creating .php File with a Course Description Automatically - Useful for web development
# Dumping video duration and date added
# Creating a log.txt file to save the course path, so the .zip archives can be moved later
#############################################
from selenium import webdriver
from pathlib import Path
from tqdm import tqdm
from colorama import init, Fore, Back, Style
import urllib.request, urllib.request, ssl, urllib3, Config, os
class Main:
# Method Driver Return Driver Object
# @param browser_type Integer -> Switch between Different Browsers 1-4
# @param driver_path String -> Path to the driver
##################################################
def driver(self, browser_type=1, driver_path='C:/chromedriver.exe'):
if browser_type == 1:
driver = webdriver.Chrome(driver_path, chrome_options=self.build_chrome_options())
elif browser_type == 2:
driver = webdriver.Firefox(driver_path)
elif browser_type == 3:
driver = webdriver.Safari(driver_path)
elif browser_type == 4:
driver = webdriver.Opera(driver_path)
else:
driver = webdriver.Chrome(driver_path)
return driver
def build_chrome_options (self, profile_dir = Config.profile_dr):
chrome_options = webdriver.ChromeOptions()
chrome_options.accept_untrusted_certs = True
chrome_options.assume_untrusted_cert_issuer = True
# chrome configuration
# More: https://github.com/SeleniumHQ/docker-selenium/issues/89
# And: https://github.com/SeleniumHQ/docker-selenium/issues/87
chrome_options.add_argument("--disable-extensions")
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument(
'--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36')
chrome_options.add_argument("--disable-impl-side-painting")
chrome_options.add_argument("--user-data-dir=" + os.path.abspath(profile_dir))
chrome_options.add_argument("--disable-setuid-sandbox")
chrome_options.add_argument("--disable-seccomp-filter-sandbox")
chrome_options.add_argument("--disable-breakpad")
chrome_options.add_argument("--disable-client-side-phishing-detection")
chrome_options.add_argument("--disable-cast")
chrome_options.add_argument("--disable-cast-streaming-hw-encoding")
chrome_options.add_argument("--disable-cloud-import")
chrome_options.add_argument("--disable-popup-blocking")
chrome_options.add_argument("--ignore-certificate-errors")
chrome_options.add_argument("--disable-session-crashed-bubble")
chrome_options.add_argument("--disable-ipv6")
chrome_options.add_argument("--allow-http-screen-capture")
return chrome_options
##################################################
# Static Method Download Download File
###################################################
@staticmethod
def download(url, names):
urllib3.disable_warnings()
try:
_create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
pass
else:
ssl._create_default_https_context = _create_unverified_https_context
if urllib.request.urlretrieve(url, names):
return True
else:
return False
##################################################
# Progress bar Class tqdm
###################################################
class progress_bar(tqdm):
def update_to(self, b=1, bsize=1, tsize=None):
if tsize is not None:
self.total = tsize
self.update(b * bsize - self.n)
def show_progress_bar(self, url, filename, output_path):
with self.progress_bar(unit='B',smoothing=0.3, unit_scale=True,
miniters=1, desc=filename) as t:
urllib.request.urlretrieve(url, filename=output_path, reporthook=t.update_to)
##################################################
# Background and Font Colours
# Reference => *Nasir Khan (r0ot h3x49) - **https://github.com/r0oth3x49** ##*
###################################################
class bcolors:
if os.name == "posix":
init(autoreset=True)
# colors foreground text:
fc = "\033[0;96m"
fg = "\033[0;92m"
fw = "\033[0;97m"
fr = "\033[0;91m"
fb = "\033[0;94m"
fy = "\033[0;33m"
fm = "\033[0;35m"
# colors background text:
bc = "\033[46m"
bg = "\033[42m"
bw = "\033[47m"
br = "\033[41m"
bb = "\033[44m"
by = "\033[43m"
bm = "\033[45m"
# colors style text:
sd = Style.DIM
sn = Style.NORMAL
sb = Style.BRIGHT
else:
init(autoreset=True)
# colors foreground text:
fc = Fore.CYAN
fg = Fore.GREEN
fw = Fore.WHITE
fr = Fore.RED
fb = Fore.BLUE
fy = Fore.YELLOW
fm = Fore.MAGENTA
# colors background text:
bc = Back.CYAN
bg = Back.GREEN
bw = Back.WHITE
br = Back.RED
bb = Back.BLUE
by = Fore.YELLOW
bm = Fore.MAGENTA
# colors style text:
sd = Style.DIM
sn = Style.NORMAL
sb = Style.BRIGHT
##################################################
# Method Waits wait time
# @param wait Integer
###################################################
def waits(self, wait):
self.driver().implicitly_wait(wait)
##################################################
# Method Maximizing Window
# @param m_window Boolean -> True by Default
###################################################
def max_window(self, m_window=True):
if m_window:
self.driver().maximize_window()
##################################################
# Method Looking for file existence before downloading
# @param m_window Boolean -> True by Default
###################################################
def file_exist(self, path):
if Path(path).is_file():
return True
else:
return False
##################################################
# Method checking whether the directory exists or not
# @param Directory Path String
###################################################
def dir_exist(self, path):
if Path(path).is_dir():
return True
else:
return False