Improve the code structure by moving the download logic out of solutions/main.py and into a reusable function in solutions/library.py.
- Delete the video file from the
videos/folder if it already exists. - Create a new file called
solutions/library.py. - Inside
solutions/library.py, create a function calleddownload_video. - Move the
yt-dlpdownload logic fromsolutions/main.pyinto that function. - Update
solutions/main.pyso it imports and calls the function.
def download_video(url):
# download one video
...Your solutions/main.py should call the function from solutions/library.py.
Make sure solutions/main.py uses the standard __main__ check:
from ...
if __name__ == "__main__":
...Run:
python solutions/main.pyThe app should still download the same video, but the download logic should now live in solutions/library.py.
After running the script, a fresh video file should appear in the videos/ folder.