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

Extract logic into a function to make it usable as a library #81

Merged
merged 3 commits into from Jan 25, 2018

Conversation

MattFisher
Copy link
Contributor

I wanted to be able to call use autosub from another project without going through the command line via subprocess.call or similar.
So I created a new function generate_subtitles and put the logic from the main method there.
Functionality is unchanged, but it is now possible to do the following:

from autosub import generate_subtitles
new_subtitle_file_path = generate_subtitles(source_path, output, api_key=some_api_key)

I also updated the code to be compatible with python 2 and 3, though it does introduce six as a dependency.

@MattFisher
Copy link
Contributor Author

Sorry there have been extra commits to the branch in my fork. Will fix.

@MattFisher
Copy link
Contributor Author

Okay that's done.
I realised during more testing that 'bin/autosub.py' wasn't importable when autosub was installed. The packaging docs recommend using something like
entry_points={'console_scripts': ['autosub = autosub:main']} in this scenario, rather than scripts=['bin/autosub'], but it meant I had to move the code from bin/autosub.py to autosub.__init__.py. CLI funtionality is unchanged.

@agermanidis
Copy link
Owner

Thanks so much for this – I verified that everything works as expected.

In the future it might be better to return a Python list containing the subtitles when used as a library instead of the output path of the subtitles.

@agermanidis agermanidis merged commit 408b6db into agermanidis:master Jan 25, 2018
@MattFisher
Copy link
Contributor Author

Yeah good idea!

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

Successfully merging this pull request may close these issues.

None yet

2 participants