Puyodead1 / udemy-downloader

A Udemy downloader that can download courses, with DRM support.
MIT License
1.26k stars 291 forks source link

[Feature Request]: Fix error "AttributeError: 'NoneType' object has no attribute 'get'" when get info #187

Closed tranthanhbinh2603 closed 8 months ago

tranthanhbinh2603 commented 10 months ago

Is your feature request related to a problem?

If yes, please describe

No response

Describe the solution you'd like

I change this source:

for chapter in chapters:
    chapter_title = chapter.get("chapter_title")
    chapter_index = chapter.get("chapter_index")
    chapter_lecture_count = chapter.get("lecture_count")
    chapter_lectures = chapter.get("lectures")

    logger.info("> Chapter: {} ({} of {})".format(chapter_title, chapter_index, chapter_count))

    for lecture in chapter_lectures:
        lecture_index = lecture.get("lecture_index")  # this is the raw object index from udemy
        lecture_title = lecture.get("lecture_title")
        parsed_lecture = udemy._parse_lecture(lecture)

        lecture_sources = parsed_lecture.get("sources")
        lecture_is_encrypted = parsed_lecture.get("is_encrypted")
        lecture_extension = parsed_lecture.get("extension")
        lecture_asset_count = parsed_lecture.get("assets_count")
        lecture_subtitles = parsed_lecture.get("subtitles")
        lecture_video_sources = parsed_lecture.get("video_sources")

        if lecture_sources:
            lecture_sources = sorted(lecture_sources, key=lambda x: int(x.get("height")), reverse=True)
        if lecture_video_sources:
            lecture_video_sources = sorted(lecture_video_sources, key=lambda x: int(x.get("height")), reverse=True)

        if lecture_is_encrypted:
            lecture_qualities = ["{}@{}x{}".format(x.get("type"), x.get("width"), x.get("height")) for x in lecture_video_sources]
        elif not lecture_is_encrypted and lecture_sources:
            lecture_qualities = ["{}@{}x{}".format(x.get("type"), x.get("height"), x.get("width")) for x in lecture_sources]

        if lecture_extension:
            continue

        logger.info("  > Lecture: {} ({} of {})".format(lecture_title, lecture_index, chapter_lecture_count))
        logger.info("    > DRM: {}".format(lecture_is_encrypted))
        logger.info("    > Asset Count: {}".format(lecture_asset_count))
        logger.info("    > Captions: {}".format(", ".join([x.get("language") for x in lecture_subtitles])))
        logger.info("    > Qualities: {}".format(lecture_qualities))

    if chapter_index != chapter_count:
        logger.info("==========================================")

To:

for lecture in chapter_lectures:
    if lecture['_class'] != 'quiz':
        lecture_index = lecture.get("lecture_index")  # this is the raw object index from udemy
        lecture_title = lecture.get("lecture_title")
        parsed_lecture = udemy._parse_lecture(lecture)

        lecture_sources = parsed_lecture.get("sources")
        lecture_is_encrypted = parsed_lecture.get("is_encrypted")
        lecture_extension = parsed_lecture.get("extension")
        lecture_asset_count = parsed_lecture.get("assets_count")
        lecture_subtitles = parsed_lecture.get("subtitles")
        lecture_video_sources = parsed_lecture.get("video_sources")

        if lecture_sources:
            lecture_sources = sorted(lecture_sources, key=lambda x: int(x.get("height")), reverse=True)
        if lecture_video_sources:
            lecture_video_sources = sorted(lecture_video_sources, key=lambda x: int(x.get("height")), reverse=True)

        if lecture_is_encrypted:
            lecture_qualities = ["{}@{}x{}".format(x.get("type"), x.get("width"), x.get("height")) for x in lecture_video_sources]
        elif not lecture_is_encrypted and lecture_sources:
            lecture_qualities = ["{}@{}x{}".format(x.get("type"), x.get("height"), x.get("width")) for x in lecture_sources]

        if lecture_extension:
            continue

        logger.info("  > Lecture: {} ({} of {})".format(lecture_title, lecture_index, chapter_lecture_count))
        logger.info("    > DRM: {}".format(lecture_is_encrypted))
        logger.info("    > Asset Count: {}".format(lecture_asset_count))
        logger.info("    > Captions: {}".format(", ".join([x.get("language") for x in lecture_subtitles])))
        logger.info("    > Qualities: {}".format(lecture_qualities))

if chapter_index != chapter_count:
    logger.info("==========================================")

And the error fix it.

Describe alternatives you've considered

No.

Additional context

No response

Puyodead1 commented 10 months ago

make a PR...

tranthanhbinh2603 commented 10 months ago

make a PR...

I think you forgot skip quiz when print info.

tranthanhbinh2603 commented 10 months ago

Ah, Have Options --download-quizzes. But, i think: Why do you not print quiz info when print info?