Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The path of downloaded file went wrong when specifing --aria2 and --path arguments #275

Open
FinalTheory opened this issue Oct 7, 2014 · 2 comments · May be fixed by #825
Open

The path of downloaded file went wrong when specifing --aria2 and --path arguments #275

FinalTheory opened this issue Oct 7, 2014 · 2 comments · May be fixed by #825

Comments

@FinalTheory
Copy link

For example, if I use coursera-dl -u **** -p **** ml-007 --path=/srv/ftp/Samba/Coursera/, then everything goes right, but when I add --aria2, then actually the file will be downloaded to (path to coursera-dl)/srv/ftp/Samba/Coursera/, maybe there's some problem when dealing with paths.

@rbrito
Copy link
Member

rbrito commented Oct 13, 2014

@FinalTheory, can you please put the option --aria2 right before another option that starts with a hyphen?

It works for me this way (Python's argparse is a bit funny with respect to the order of the parameters and how it parses things).

Thanks for your feedback,

Rogério Brito.

@holocronweaver
Copy link

holocronweaver commented May 26, 2022

The downloader for aria2 has a bug which prevents it from supporting absolute paths.

From aria2c manpage (v1.35.0):

-o, --out=<FILE>
              The file name of the downloaded file.  It is always relative  to
              the    directory    given    in    --dir   option.    When   the
              --force-sequential option is used, this option is ignored.

Thus both --dir and --out should be specified together for absolute paths, but instead Aria2Downloader in downloaders.py specifies the full path in --out, causing the working directory to be appended to all paths:

def _create_command(self, url, filename):
        return [self.bin, url, '-o', filename,
                '--check-certificate=false', '--log-level=notice',
                '--max-connection-per-server=4', '--min-split-size=1M']

For example, if you run coursera-dl in working directory /home/user1/ and specify --path /home/user1/downloads, aria2 will download to a directory /home/user1//home/user1/downloads. This is what @FinalTheory reported, and is still the behavior as of the latest coursera-dl on PyPi (0.11.5).

A simple fix is:

def _create_command(self, url, filepath):
        filedir, filename = os.path.split(filepath)
        return [self.bin, url, '-o', filename, '--dir', filedir or '.',
                '--check-certificate=false', '--log-level=notice',
                '--max-connection-per-server=4', '--min-split-size=1M']

though I suspect it would be easier and more robust to change the _create_command interface to pass in filedir and filename separately.

@holocronweaver holocronweaver linked a pull request May 27, 2022 that will close this issue
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants