Puyodead1 / udemy-downloader

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

[Feature Request] Path length detection +chapter title or lecture title truncation if needed #50

Open tinfever opened 3 years ago

tinfever commented 3 years ago

First of all, thank you for this program. It works extremely well for backing up the Udemy courses I've purchased.

I ran into an issue with one of my courses that has very long chapter title and lecture titles which caused the path length to exceed the Windows 255 character limit. This caused lots of weird errors about "cannot write to file" or "file not found" during the download process.

Example (256 characters long): Z:\Udemy\outdir\crash-course-electronics-and-pcb-design\08 - Graduating to Design Engineer CircuitMaker Fundamentals and Real-World Projects/004 CircuitMaker Fundamentals_ Magic Wand 555 Timer Design & Parts Selection Process.encrypted.m4a.part.frag.urls

I worked around the issue by putting the udemy-downloader folder in the root folder of my drive, renaming the udemy-downloader folder to just "Udemy", and finally I had to add a line to the main.py to truncate any chapter title greater than 51 characters:

for chapter in _udemy.get("chapters"):
        chapter_title = chapter.get("chapter_title")
        chapter_title = chapter_title[:51]                                           <<<
        chapter_index = chapter.get("chapter_index")
        chapter_dir = os.path.join(course_dir, chapter_title)
        if not os.path.exists(chapter_dir):
            os.mkdir(chapter_dir)

This all worked fine for me but it might be worth adding a mechanism to detect if the program is going to try to access a path longer than 256 characters, and if so either just arbitrarily truncate the chapter titles and lecture titles if necessary, or give the user an option to select what to truncate and how much. Or even just print an error and quit rather than have the user receive lots of weird errors. For me, I figured the information in the long lecture titles was more useful so I opted to truncate the chapter titles. Although, I did add a txt file with the full chapter titles "just in case".

Just some thoughts I thought I'd share. Thanks again!

Leftifield commented 2 years ago

nice thank you - I was having trouble as udemy-downloader-id-as-course-name which was released to address this issue was having a problem parsing something through to a library as INT and failed.

Puyodead1 commented 2 years ago

First of all, thank you for this program. It works extremely well for backing up the Udemy courses I've purchased.

I ran into an issue with one of my courses that has very long chapter title and lecture titles which caused the path length to exceed the Windows 255 character limit. This caused lots of weird errors about "cannot write to file" or "file not found" during the download process.

Example (256 characters long): Z:\Udemy\outdir\crash-course-electronics-and-pcb-design\08 - Graduating to Design Engineer CircuitMaker Fundamentals and Real-World Projects/004 CircuitMaker Fundamentals_ Magic Wand 555 Timer Design & Parts Selection Process.encrypted.m4a.part.frag.urls

I worked around the issue by putting the udemy-downloader folder in the root folder of my drive, renaming the udemy-downloader folder to just "Udemy", and finally I had to add a line to the main.py to truncate any chapter title greater than 51 characters:

for chapter in _udemy.get("chapters"):
        chapter_title = chapter.get("chapter_title")
        chapter_title = chapter_title[:51]                                           <<<
        chapter_index = chapter.get("chapter_index")
        chapter_dir = os.path.join(course_dir, chapter_title)
        if not os.path.exists(chapter_dir):
            os.mkdir(chapter_dir)

This all worked fine for me but it might be worth adding a mechanism to detect if the program is going to try to access a path longer than 256 characters, and if so either just arbitrarily truncate the chapter titles and lecture titles if necessary, or give the user an option to select what to truncate and how much. Or even just print an error and quit rather than have the user receive lots of weird errors. For me, I figured the information in the long lecture titles was more useful so I opted to truncate the chapter titles. Although, I did add a txt file with the full chapter titles "just in case".

Just some thoughts I thought I'd share. Thanks again!

Yikes, this got buried :eyes:

The path length issue has been a real pain in the ass, i have suggested to people that encounter this issue to move the tool as close to the root of the drive as possible, I even made a new branch id-as-course-name to help shorten the path which now that i think if it could be merged right into the main branch as an option. truncating is also a good idea, not sure why i didnt think of that.

Puyodead1 commented 2 years ago

nice thank you - I was having trouble as udemy-downloader-id-as-course-name which was released to address this issue was having a problem parsing something through to a library as INT and failed.

what was the error?

Leftifield commented 2 years ago

nice thank you - I was having trouble as udemy-downloader-id-as-course-name which was released to address this issue was having a problem parsing something through to a library as INT and failed.

what was the error?

I logged it as 81 with traceback added. https://github.com/Puyodead1/udemy-downloader/issues/81