dgorissen / coursera-dl

A script for downloading course material (video's, pdfs, quizzes, etc) from coursera.org
http://dirkgorissen.com/2012/09/07/coursera-dl-a-coursera-download-script/
GNU General Public License v3.0
1.74k stars 300 forks source link

Limit path on windows to 260 characters max #112

Closed aeunson closed 10 years ago

aeunson commented 10 years ago

In windows the max path allowed is 260 characters.

Truncate or abbreviate files to stay within the limit.

thank you

jackmaney commented 10 years ago

Look at the -mppl argument.

aeunson commented 10 years ago

it appears that the -mppl feature doesn't work

referencing the code below if a MPPL is specified, it gets overwritten on windows.

I tried -mppl 40 to keep a course running to long and it gets ignored.

for windows, logic should check to see if a value is specified in args, if not default to 90 if a value is specfied in windows, used the value specified in args

#should we be trimming paths?
# TODO: this is a simple hack, something more elaborate needed
mppl = None
if args.mppl:
    if platform.system() == "Windows":
        mppl = 90
        print_("Maximum length of a path component set to %s" % mppl)
    else:
        # linux max path length is typically around 4060 so assume thats ok
        pass
aeunson commented 10 years ago

maybe something like this?

# should we be trimming paths?
# TODO: this is a simple hack, something more elaborate needed
mppl = None
if args.mppl:
    if platform.system() == "Windows":
        if args.mppl > 0 :
            mppl = args.mppl
        else:
            mppl = 90
        print_("Maximum length of a path component set to %s" % mppl)
    else:
        # linux max path length is typically around 4060 so assume thats ok
        pass
jayhenry commented 10 years ago

Yeah, I think so. The original code didn't handle the user defined length under windows.

发自我的 iPhone

在 2013年11月24日,12:47,aeunson notifications@github.com 写道:

maybe something like this?

should we be trimming paths?

TODO: this is a simple hack, something more elaborate needed

mppl = None if args.mppl: if platform.system() == "Windows": if args.mppl > 0 : mppl = args.mppl else: mppl = 90 print_("Maximum length of a path component set to %s" % mppl) else:

linux max path length is typically around 4060 so assume thats ok

    pass

— Reply to this email directly or view it on GitHub.

aeunson commented 10 years ago

this feels like it might be what's intended

a. always use the MPPL value if its supplied by the user b. only set a default if on windows and mppl isn't provided

# should we be trimming paths?
mppl = None
if args.mppl:
    if args.mppl > 0 :
        mppl = args.mppl
    elif platform.system() == "Windows":
        mppl = 90

print_("Maximum length of a path component set to %s" % mppl)
dgorissen commented 10 years ago

Im a bit all over the place at the moment so cant look at it in depth right now. Will do so asap. However, if you submit a pull request I will merge.

On Sun, Nov 24, 2013 at 1:05 PM, aeunson notifications@github.com wrote:

this feels like it might be what's intended

  1. if MPPL is set, use it (regardless of platform)
  2. if MMPL is not set, and the user is on windows, default to 90
  3. if MMPL is not set, and the user is not on windows, leave MPPL null as there are checks to ignore MMPL if its not set elsewhere

should we be trimming paths?

mppl = None if args.mppl:

if args.mppl > 0 : mppl = args.mppl else if platform.system() == "Windows": mppl = 90

print_("Maximum length of a path component set to %s" % mppl)

Reply to this email directly or view it on GitHubhttps://github.com/dgorissen/coursera-dl/issues/112#issuecomment-29154936 .

aeunson commented 10 years ago

it appears the script is having trouble with the ... in the trim_path_part function where ... is appended to the end of the truncated name.

I played with a bunch of stuff including truncating the week name and file name but used __ (2 underscores) and that appears to be working.

i think i have to find a way to preserve the file extension when doing a rename as things renamed come through as "file"

dgorissen commented 10 years ago

Quick fix per your previous comment. Reopen if other issues remain.