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

New Feature: currently it does not support cookie #37

Open
Niraj-Kamdar opened this issue Sep 14, 2019 · 0 comments
Open

New Feature: currently it does not support cookie #37

Niraj-Kamdar opened this issue Sep 14, 2019 · 0 comments

Comments

@Niraj-Kamdar
Copy link

One may want to download from a site which require Authentication or cookie to download.
changes in pySmartDL.py:
So, i tried to introduce a cookie_jar in the constructor on pySmartDL
def __init__(self, urls, dest=None, progress_bar=True, fix_urls=True, threads=5, timeout=5, logger=None, connect_default_logger=False, request_args=None, cookie_jar=cookie()):
self.cookie_jar = cookie_jar

and did following change in start() method:

        for i, arg in enumerate(args):
            req = self.pool.submit(
                download,
                self.url,
                self.dest+".%.3d" % i,
                self.requestArgs,
                arg[0],
                arg[1],
                self.timeout,
                self.shared_var,
                self.thread_shared_cmds,
                self.logger,
                3,
                self.cookie_jar
            )

changes in download.py:

    opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cookie_jar))
    cj = cookie_jar._cookies[domain]['/'][cookie_name]  #i provided domain and cookie_name explicitly but we also have to fetch it or take it from user
    ctuple = (cj.name, cj.value)
    opener.addheaders = [ctuple, ('User-Agent', 'Mozilla/5.0')]
    urllib.request.install_opener(opener)

but after introducing it, it still not working on site with cookies it is giving socket time out error and i don't know much about networking so i hope you can help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant