akinuri / llvd

Linkedin Learning Video Downloader
https://pypi.org/project/llvd
MIT License
0 stars 0 forks source link

Testing the package #1

Closed akinuri closed 2 years ago

akinuri commented 2 years ago

Hi

I'd like to make some improvements on this package. I never did this (work on a package) before, so I'm not sure how to set things up in VS Code.

After forking, I created a test.py file in the project dir (where the setup.py is) and this is its content:

import llvd

llvd.main(
    True,
    "learning-npm-the-node-package-manager-2018",
    "360",
    True,
)

This does not seem to work. I get the following error:

Exception has occurred: TypeError
'bool' object is not iterable
  File "C:\...\akinuri\llvd\test.py", line 3, in <module>
    llvd.main(

I also tried using launch.json (before the test.py), but couldn't make it work either.

I've tried to look it up*, but no luck so far. Can you guide me here? How do I test/debug this (or rather any) package?


* Pages I've visited:

@knowbee

knowbee commented 2 years ago

If I may ask, what improvements would you like to make?

akinuri commented 2 years ago

I've been using LinkedIn Learning for many years (from the early days of lynda.com). I usually download the courses (manually) for offline viewing, and when I do, I gather the course info as much as I can to make it complete.

My main goal here is to solve these issues (my preferences?), and if they make sense (for others), then maybe do PRs.


So, about the original issue, what am I doing wrong? :)

knowbee commented 2 years ago

Good ideas, I would love to see most them implemented.

llvd.main(
    True,
    "learning-npm-the-node-package-manager-2018",
    "360",
    True,
)

this is wrong since the main function expects this => main(cookies, course, resolution, caption, path, throttle):

akinuri commented 2 years ago

I just tried passing None for the path and throttle parameters, and got a different error. (check below for the code)

Exception has occurred: TypeError
BaseCommand.main() takes from 1 to 5 positional arguments but 7 were given
  File "C:\...\akinuri\llvd\test.py", line 3, in <module>
    llvd.main(True, 'learning-npm-the-node-package-manager-2018', '360', True, None, None)

Just to make sure that I'm doing the right thing, instead of the fork, I inspected the globally installed package. Injected a print statement at the start of main, and then run this command:

llvd --course "learning-npm-the-node-package-manager-2018" --cookies --caption --resolution 360
def main(cookies, course, resolution, caption, path, throttle):

    print([
        cookies,
        course,
        resolution,
        caption,
        path,
        throttle,
    ])

    """
    Linkedin learning video downloader cli tool
    example: llvd --course "java-8-essential"
    """

It started downloading the course as expected, and the print output was:

[True, 'learning-npm-the-node-package-manager-2018', '360', True, None, None]


Now, since I pass the exact values to the main function, why is it not working?

import llvd

llvd.main(True, 'learning-npm-the-node-package-manager-2018', '360', True, None, None)

This throws the error that is mentioned above.

I suspect the click package. It might be requiring llvd to be called from CLI. Not sure.


Just to make things clear, maybe I should provide more info about the env/setup. I have already installed llvd globally and it's working fine. Then I forked your repo and want to work on it. I want to debug the fork. So I'm trying to run the llvd in the forked repo. To run it manually, I created a test.py file right in the forked repo and trying to pass llvd some values manually (in the test.py). This does not seem to work.

Am I using a correct method to run the forked llvd? How do you do it? What am I doing wrong here?

knowbee commented 2 years ago

llvd is supposed to work as a command line program and that is how it should be tested

llvd always expects cookies (object) otherwise it is gonna prompt a user to enter their credentials. So keep that in mind while you are testing

akinuri commented 2 years ago

Well, then, is there a way to run the llvd in the fork repo (not the global package) via CLI, and preferably use the python debugger? If I can't use the debugger, it's going to be pain to debug/test the package using the traditional ways (print(), etc.).

If not, I'll have to make the llvd work programmatically (without needing CLI) first. The need for the CLI should be optional (a wrapper around the actual app) for development. This seems to be the first thing that requires fixing.

akinuri commented 2 years ago

For the time being, I decided to go with the following setup:

# test.py

from llvd.app import App
from llvd import config
from llvd.process_io import parse_cookie_file
from llvd.utils import clean_dir

COURSE = "course"

email = config.email
password = config.password

course = 'learning-npm-the-node-package-manager-2018'
resolution = '360'
caption = True
throttle = None
course_slug = (clean_dir(course), COURSE)

cookie_dict = parse_cookie_file()

llvd = App(email, password, course_slug, resolution, caption, throttle)
llvd.run(cookie_dict)

I think, most of the code/checks in the main() (__init__.py) should be handled by the App so that the app does not depend on the main()/@click etc.

If one were to create a GUI for this app, one would have to decouple the CLI and the app.

Anyway, since I got it working, I might refactor the CLI/App later :)