Browse Source

download_all() functionality

master
parent
commit
a7ad2c6310
1 changed files with 70 additions and 21 deletions
  1. 70
    21
      pluralsight.py

+ 70
- 21
pluralsight.py View File

@@ -25,32 +25,45 @@ HIDE_SELENIUM_INSTANCES = False
MAX_COURSE_DOWNLOAD_COUNT = 5

# Denotes Time.Sleep() duration in seconds
SLEEP_DURATION = 5
SELENIUM_SLEEP_DURATION = 5

# Minimum number of seconds to wait between consecutive video downloads
MIN_VIDEO_DOWNLOAD_DELAY = 10

# Minimum number of seconds to wait between consecutive video downloads
MAX_VIDEO_DOWNLOAD_DELAY = 20

# Check if current OS/platform is Windows
IS_WINDOWS = platform.startswith("win")

# Master Directory Path
WORKING_DIRECTORY = os.path.dirname(os.path.realpath(__file__))
# Master Directory Path (Default: Working Directory)
MASTER_DIRECTORY = os.path.dirname(os.path.realpath(__file__))

# Path of the text file where pluralsight account details will be stored
CREDENTIAL_FILE_PATH = os.path.join(WORKING_DIRECTORY, "credential.txt")
CREDENTIAL_FILE_PATH = os.path.join(MASTER_DIRECTORY, "credential.txt")

# Path of the archive text file to log all downloaded videos
ARCHIVE_FILE_PATH = os.path.join(MASTER_DIRECTORY, "archive.txt")

# Progress text file path (Progress file stores progress of download_all())
PROGRESS_FILE_PATH = os.path.join(MASTER_DIRECTORY, "progress.txt")

# Path of the directory where downloaded courses will be saved
SAVE_DIRECTORY_PATH = os.path.join(WORKING_DIRECTORY, "Courses")
SAVE_DIRECTORY_PATH = os.path.join(MASTER_DIRECTORY, "Courses")

# JSON File (.json) containing the JSON of the paths/courses dump of Pluralsight
# JSON_FILE_URL = os.path.join(WORKING_DIRECTORY, "pluralsight.json")
JSON_FILE_URL = "https://git.teknik.io/CanWePlsRapeTheShitOuttaPluralsight/RapePluralsight/raw/branch/master/pluralsight.json"
JSON_FILE_URL = os.path.join(MASTER_DIRECTORY, "pluralsight.json")

# Options for youtube-dl. For a complete list of options, check https://github.com/ytdl-org/youtube-dl/blob/3e4cedf9e8cd3157df2457df7274d0c842421945/youtube_dl/YoutubeDL.py#L137-L312
ydl_options = {
'writesubtitles': True,
'nooverwrites': True,
'sleep_interval': 10,
'max_sleep_interval': 20,
'sleep_interval': MIN_VIDEO_DOWNLOAD_DELAY,
'max_sleep_interval': MAX_VIDEO_DOWNLOAD_DELAY,
'download_archive': ARCHIVE_FILE_PATH
}


# endregion


@@ -159,7 +172,7 @@ class Pluralsight:
"""

self.driver.get("https://www.pluralsight.com/offer/2020/free-april-month")
time.sleep(SLEEP_DURATION)
time.sleep(SELENIUM_SLEEP_DURATION)

accept_cookie_button_element = self.driver.find_element_by_class_name("cookie_notification--opt_in")
accept_cookie_button_element.click()
@@ -183,7 +196,7 @@ class Pluralsight:
lastname_input_element.send_keys(lastName)
tos_checkbox_element.click()

time.sleep(SLEEP_DURATION)
time.sleep(SELENIUM_SLEEP_DURATION)

create_account_button_element = self.driver.find_element_by_xpath(
"//*[contains(text(), 'I agree, activate benefit')]")
@@ -194,7 +207,7 @@ class Pluralsight:
cancel_button_element = self.driver.find_element_by_class_name("cancelButton---CKAut")
cancel_button_element.click()

time.sleep(SLEEP_DURATION)
time.sleep(SELENIUM_SLEEP_DURATION)

def set_password(self, verification_link: str) -> None:
"""
@@ -205,7 +218,7 @@ class Pluralsight:
"""

self.driver.get(verification_link)
time.sleep(SLEEP_DURATION)
time.sleep(SELENIUM_SLEEP_DURATION)

password_input_element = self.driver.find_element_by_id("Password")
password_confirm_input_element = self.driver.find_element_by_id("PasswordConfirmation")
@@ -218,7 +231,7 @@ class Pluralsight:

save_button_element.click()

time.sleep(SLEEP_DURATION)
time.sleep(SELENIUM_SLEEP_DURATION)


class Progress:
@@ -264,7 +277,7 @@ def create_pluralsight_account(credential_file_path: str) -> Dict[str, str]:

ps.set_password(verification_link=verification_link)

time.sleep(SLEEP_DURATION)
time.sleep(SELENIUM_SLEEP_DURATION)

with open(credential_file_path, 'w+') as account_file:
account_file.write(f"{disposable_email.email_address}\n")
@@ -347,11 +360,6 @@ def get_directory_full_path(root_directory_path: str, pluralsight_path: Pluralsi
return directory_full_path


def download_all(all_pluralsight_courses: List[PluralsightPath]):
# Todo Download all
pass


def download_pluralsight_paths(pluralsight_paths=List[PluralsightPath]):
pass

@@ -399,10 +407,11 @@ def prompt_paths_and_courses_selection(all_pluralsight_paths_list: List[Pluralsi
if click.prompt("Exit", default=False, show_default=True, type=bool):
return UserSelection([], is_exit=True)


# endregion


def get_credential() -> Tuple[str,str]:
def get_credential() -> Tuple[str, str]:
if not os.path.exists(CREDENTIAL_FILE_PATH):
print("CREATING NEW PLURALSIGHT ACCOUNT")
create_pluralsight_account(CREDENTIAL_FILE_PATH)
@@ -415,6 +424,46 @@ def get_credential() -> Tuple[str,str]:
return credential


def save_progress(path_id: int, course_index: int):
with open(PROGRESS_FILE_PATH, 'w+') as progress_file:
progress_file.write(f"{path_id}|{course_index}")


def download_all(all_pluralsight_paths: List[PluralsightPath]):
global SAVE_DIRECTORY_PATH

try:
if not os.path.isfile(PROGRESS_FILE_PATH):
save_progress(path_id=1, course_index=0)

current_path_id, current_course_index = map(int, Path(PROGRESS_FILE_PATH).read_text().rstrip().split("|"))

while current_path_id <= len(all_pluralsight_paths):
email, password = get_credential()

for pluralsight_path in all_pluralsight_paths:
if int(current_path_id) == pluralsight_path.id:
while current_course_index < len(pluralsight_path.course_links):
SAVE_DIRECTORY_PATH = get_directory_full_path(SAVE_DIRECTORY_PATH, pluralsight_path)

course_link = pluralsight_path.course_links[current_course_index]
download_result = download_course(course_link, email, password)

if not download_result:
raise Exception("Failed to download course")

current_course_index += 1
save_progress(current_path_id, current_course_index)

current_path_id += 1
save_progress(current_path_id, current_course_index)

break

except Exception as exception:
print(exception)


def main():
global SAVE_DIRECTORY_PATH


Loading…
Cancel
Save