예제 #1
0
def download_on_demand_class(args, class_name):
    """
    Download all requested resources from the on-demand class given in class_name.

    Returns True if the class appears completed.
    """

    session = get_session()
    login(session, args.username, args.password)

    # get the syllabus listing
    page = get_on_demand_syllabus(session, class_name)

    ignored_formats = []
    if args.ignore_formats:
        ignored_formats = args.ignore_formats.split(",")

    # parse it
    modules = parse_on_demand_syllabus(
        session, page, args.reverse, args.intact_fnames, args.subtitle_language, args.video_resolution
    )

    downloader = get_downloader(session, class_name, args)

    # obtain the resources
    completed = True
    for idx, module in enumerate(modules):
        module_name = "%02d_%s" % (idx + 1, module[0])
        sections = module[1]

        result = download_lectures(
            downloader,
            module_name,
            sections,
            args.file_formats,
            args.overwrite,
            args.skip_download,
            args.section_filter,
            args.lecture_filter,
            args.resource_filter,
            os.path.join(args.path, class_name),
            args.verbose_dirs,
            args.preview,
            args.combined_section_lectures_nums,
            args.hooks,
            args.playlist,
            args.intact_fnames,
            ignored_formats,
            args.resume,
        )
        completed = completed and result

    return completed
예제 #2
0
def download_class(args, class_name):
    """
    Download all requested resources from the class given in class_name.
    Returns True if the class appears completed.
    """

    session = requests.Session()

    if args.preview:
        # Todo, remove this.
        session.cookie_values = 'dummy=dummy'
    else:
        get_cookies_for_class(
            session,
            class_name,
            cookies_file=args.cookies_file,
            username=args.username, password=args.password
        )
        session.cookie_values = make_cookie_values(session.cookies, class_name)

    # get the syllabus listing
    page = get_syllabus(session, class_name, args.local_page, args.preview)

    # parse it
    sections = parse_syllabus(session, page, args.reverse,
                              args.intact_fnames)

    if args.about:
        download_about(session, class_name, args.path, args.overwrite)

    downloader = get_downloader(session, class_name, args)

    # obtain the resources
    completed = download_lectures(
        downloader,
        class_name,
        sections,
        args.file_formats,
        args.overwrite,
        args.skip_download,
        args.section_filter,
        args.lecture_filter,
        args.resource_filter,
        args.path,
        args.verbose_dirs,
        args.preview,
        args.combined_section_lectures_nums,
        args.hooks,
        args.playlist,
        args.intact_fnames)

    return completed
예제 #3
0
def download_on_demand_class(args, class_name):
    """
    Download all requested resources from the on-demand class given in class_name.

    Returns True if the class appears completed.
    """

    session = get_session()
    extractor = CourseraExtractor(session, args.username, args.password)

    modules = extractor.get_modules(class_name,
                                    args.reverse,
                                    args.unrestricted_filenames,
                                    args.subtitle_language,
                                    args.video_resolution)

    if is_debug_run():
        with open('%s-syllabus-parsed.json' % class_name, 'w') as file_object:
            json.dump(modules, file_object, indent=4)

    downloader = get_downloader(session, class_name, args)

    # obtain the resources

    ignored_formats = []
    if args.ignore_formats:
        ignored_formats = args.ignore_formats.split(",")

    course_downloader = CourseraDownloader(
        downloader,
        commandline_args=args,
        class_name=class_name,
        path=args.path,
        ignored_formats=ignored_formats,
        disable_url_skipping=args.disable_url_skipping
    )

    completed = course_downloader.download_modules(modules)

    # Print skipped URLs if any
    if course_downloader.skipped_urls:
        print_skipped_urls(course_downloader.skipped_urls)

    # Print failed URLs if any
    # FIXME: should we set non-zero exit code if we have failed URLs?
    if course_downloader.failed_urls:
        print_failed_urls(course_downloader.failed_urls)

    return completed
예제 #4
0
def download_class(args, class_name):
    """
    Download all requested resources from the class given in class_name.
    Returns True if the class appears completed.
    """

    session = requests.Session()

    if args.preview:
        # Todo, remove this.
        session.cookie_values = 'dummy=dummy'
    else:
        get_cookies_for_class(session,
                              class_name,
                              cookies_file=args.cookies_file,
                              username=args.username,
                              password=args.password)
        session.cookie_values = make_cookie_values(session.cookies, class_name)

    # get the syllabus listing
    page = get_syllabus(session, class_name, args.local_page, args.preview)

    # parse it
    sections = parse_syllabus(session, page, args.reverse, args.intact_fnames)

    if args.about:
        download_about(session, class_name, args.path, args.overwrite)

    downloader = get_downloader(session, class_name, args)

    # obtain the resources
    completed = download_lectures(
        downloader, class_name, sections, args.file_formats, args.overwrite,
        args.skip_download, args.section_filter, args.lecture_filter,
        args.resource_filter, args.path, args.verbose_dirs, args.preview,
        args.combined_section_lectures_nums, args.hooks, args.playlist,
        args.intact_fnames)

    return completed
예제 #5
0
def download_old_style_class(args, class_name):
    """
    Download all requested resources from the class given in class_name.
    Old style classes are classes located at class.coursera.org.
    Read more about course types here:
    https://learner.coursera.help/hc/en-us/articles/203879739-Course-Types

    Returns True if the class appears completed.
    """
    session = get_session()

    if args.preview:
        # Todo, remove this.
        session.cookie_values = "dummy=dummy"
    else:
        get_cookies_for_class(
            session, class_name, cookies_file=args.cookies_file, username=args.username, password=args.password
        )
        session.cookie_values = make_cookie_values(session.cookies, class_name)

    subtitle_language = args.subtitle_language
    if args.about or args.subtitle_language != "en":
        about = download_about(session, class_name, args.path, args.overwrite, args.subtitle_language)
        # Check if subtitle is available
        if not about or not about["subtitleLanguagesCsv"].split(",").count(args.subtitle_language):
            logging.warning("Subtitle unavailable in specified language")
            subtitle_language = "en"

    # get the syllabus listing
    page = get_old_style_syllabus(session, class_name, args.local_page, args.preview)

    # parse it
    sections = parse_old_style_syllabus(session, page, args.reverse, args.intact_fnames, subtitle_language)

    downloader = get_downloader(session, class_name, args)

    ignored_formats = []
    if args.ignore_formats:
        ignored_formats = args.ignore_formats.split(",")

    # obtain the resources
    completed = download_lectures(
        downloader,
        class_name,
        sections,
        args.file_formats,
        args.overwrite,
        args.skip_download,
        args.section_filter,
        args.lecture_filter,
        args.resource_filter,
        args.path,
        args.verbose_dirs,
        args.preview,
        args.combined_section_lectures_nums,
        args.hooks,
        args.playlist,
        args.intact_fnames,
        ignored_formats,
        args.resume,
        args.video_resolution,
    )

    return completed