示例#1
0
文件: run.py 项目: ranganathsb/Lyndor
def download_course(url):
    ''' download course '''
    # Check for a valid url
    if url.find('.html') == -1:
        sys.exit(message.animate_characters(Fore.LIGHTRED_EX, draw.ANONYMOUS, 0.02))

    url = url[:url.find(".html")+5] #strip any extra text after .html in the url

    # Folder/File paths
    lynda_folder_path = read.settings_json('preferences', 'location') + '/'
    course_folder_path = save.course_path(url, lynda_folder_path)
    desktop_folder_path = install.get_path("Desktop")
    download_folder_path = install.get_path("Downloads")
    
    # Read preferences
    download_exercise_file = read.settings_json('preferences', 'download_exercise_file')
    use_cookie_for_download = read.settings_json('credentials', 'use_cookie_for_download')

    if use_cookie_for_download:
        cookie_path = cookies.find_cookie(desktop_folder_path, download_folder_path)
    else:
        cookie_path = ''
        usr_pass_message = message.return_colored_message(Fore.LIGHTGREEN_EX, 'Using username and password combination for download\n')
        message.carriage_return_animate(usr_pass_message)

    try:
        # main operations ->
        save.course(url, lynda_folder_path)                 # Create course folder
        save.info_file(url, course_folder_path)             # Gather information
        save.chapters(url, course_folder_path)              # Create chapter folders
        save.contentmd(url)                                 # Create content.md
        save.videos(url, cookie_path, course_folder_path)   # Download videos
        rename.videos(course_folder_path)                   # rename videos
        rename.subtitles(course_folder_path)                # rename subtitles
        move.vid_srt_to_chapter(url, course_folder_path)    # Move videos and subtitles to chapter folders
        
        # Download exercise file
        if download_exercise_file:                  # check if user wants to download exercise file
            if not use_cookie_for_download:         # make sure user is downloading via user + password
                if save.check_exercise_file(url):
                    exercise_file.download(url, course_folder_path) # Download exercise-file
                else:
                    print('\n-> Exercise file not available.')
            else:
                print('\nExercise file downloads for organizational login is not supported, please download manually.')
        
    except KeyboardInterrupt:
        sys.exit(message.colored_message(Fore.LIGHTRED_EX, "\n- Program Interrupted!!\n"))
示例#2
0
def download_course(url):
    ''' download course '''

    # Check for a valid url
    if url.find('.html') == -1:
        sys.exit(
            message.animate_characters(Fore.LIGHTRED_EX, draw.ANONYMOUS, 0.02))

    url = url[:url.find(".html") +
              5]  #strip any extra text after .html in the url

    # Folder/File paths
    lynda_folder_path = read.settings_json('preferences', 'location') + '/'
    course_folder_path = save.course_path(url, lynda_folder_path)
    desktop_folder_path = install.get_path("Desktop")
    download_folder_path = install.get_path("Downloads")

    # Read preferences
    use_cookie_for_download = read.course_download_pref

    if use_cookie_for_download in ['cookies', 'cookie']:
        cookie_path = cookies.find_cookie(desktop_folder_path,
                                          download_folder_path)
    else:
        cookie_path = ''
        usr_pass_message = message.return_colored_message(
            Fore.LIGHTGREEN_EX,
            'Using username and password combination for download\n')
        message.carriage_return_animate(usr_pass_message)

    try:
        # main operations ->
        save.course(url, lynda_folder_path)  # Create course folder
        save.info_file(url, course_folder_path)  # Gather information
        save.chapters(url, course_folder_path)  # Create chapter folders
        save.contentmd(url)  # Create content.md
        save.videos(url, cookie_path, course_folder_path)  # Download videos
        rename.videos(course_folder_path)  # rename videos
        rename.subtitles(course_folder_path)  # rename subtitles
        move.vid_srt_to_chapter(
            url,
            course_folder_path)  # Move videos and subtitles to chapter folders

        # Download exercise files
        if save.check_exercise_file(url):
            print('\nExercise file is available to download')
            if not read.download_exercise_file:
                # if user do not want to download ex-file
                print(
                    "settings.json says you do not want to download ex-file -> 'download_exercise_file': false"
                )
            else:
                # if user wants to download ex-file
                if read.course_download_pref == 'regular-login':
                    exercise_file.download(url, course_folder_path)
                elif read.exfile_download_pref == 'library-login':
                    if read.card_number == '':
                        print(
                            '\nTo download ex-file via library login -> Please save library card details in settings.json'
                        )
                    else:
                        exercise_file.download(url, course_folder_path)
                else:
                    print(
                        '\nThe exercise file can only be downloaded through one of the below combinations:'
                    )
                    print('~ Regular login: username + password or')
                    print('~ Library login: card number, pin and org. url\n')
        else:  # if exercise file not present
            print('This course does not include Exercise files.')

    except KeyboardInterrupt:
        sys.exit(
            message.colored_message(Fore.LIGHTRED_EX,
                                    "\n- Program Interrupted!!\n"))
示例#3
0
def download_course(url):
    ''' download course '''
    # Check for a valid url
    if url.find('.html') == -1:
        sys.exit(
            message.animate_characters(Fore.LIGHTRED_EX, draw.ANONYMOUS, 0.02))

    url = url[:url.find(".html") +
              5]  #strip any extra text after .html in the url

    # Folder/File paths
    lynda_folder_path = install.read_settings_json('preferences',
                                                   'location') + '/'
    course_folder_path = save.course_path(url, lynda_folder_path)
    desktop_folder_path = install.folder_path("Desktop")
    download_folder_path = install.folder_path("Downloads")
    if install.read_settings_json('credentials', 'use_cookie_for_download'):
        cookie_path = cookies.find_cookie(desktop_folder_path,
                                          download_folder_path)
    else:
        cookie_path = ''
        usr_pass_message = message.return_colored_message(
            Fore.LIGHTGREEN_EX,
            'Using username and password combination for download\n')
        message.carriage_return_animate(usr_pass_message)

    try:
        save.course(url, lynda_folder_path)  # Create course folder
        save.info_file(url, course_folder_path)  # Gather information
        save.chapters(
            url, course_folder_path)  # Create chapters inside course folder
        videos.download(
            url, cookie_path,
            course_folder_path)  # Downloading lynda videos to course folder
        # Download exercise file
        # check for organizational login, should be false to download.
        if not install.read_settings_json('credentials',
                                          'use_cookie_for_download'):
            if save.check_exercise_file(url):
                exercise_file.download(
                    url, course_folder_path)  # Download exercise-file
            else:
                print('\n-> Exercise file not available.')
        else:
            print(
                '\nExercise file downloads for organizational login is not supported, please download manually.'
            )

    except KeyboardInterrupt:
        sys.exit(
            message.colored_message(Fore.LIGHTRED_EX,
                                    "\n- Program Interrupted!!\n"))

    # Rename files
    try:
        path = rename_files.assign_folder(course_folder_path)
    except KeyboardInterrupt:
        sys.exit(
            message.colored_message(Fore.LIGHTRED_EX,
                                    "\n- Program Interrupted!!\n"))
    except:
        sys.exit('error in assigning path')
    try:
        rename_files.execute(path)
    except KeyboardInterrupt:
        sys.exit(
            message.colored_message(Fore.LIGHTRED_EX,
                                    "\n- Program Interrupted!!\n"))
    except:
        sys.exit(message.RENAMING_ERROR)