These changes retain the original functionality but intelligently parse/manipulate paths and URLs, hopefully making the code more flexible and modular.
Make a dedicated function for parsing a book URL and obtaining the
necessary download URL for the desired format (pdf or epub) and the
local human-friendly filename.
Clean up path, URL, and string manipulations.
Use file open context manager for safer file writing.
These changes retain the original functionality but intelligently parse/manipulate paths and URLs, hopefully making the code more flexible and modular.
Make a dedicated function for parsing a book URL and obtaining the necessary download URL for the desired format (pdf or epub) and the local human-friendly filename.
Clean up path, URL, and string manipulations.
Use file open context manager for safer file writing.