From 9a60eef176793833e1ca3fea5a78e26ec0fd1423 Mon Sep 17 00:00:00 2001 From: Florent Ravenel Date: Fri, 1 Dec 2023 12:01:32 +0100 Subject: [PATCH] feat: download video from url to local --- Python/Python_Download_video_from_URL.ipynb | 51 +++++++++++---------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/Python/Python_Download_video_from_URL.ipynb b/Python/Python_Download_video_from_URL.ipynb index 947eac6829..631077b957 100644 --- a/Python/Python_Download_video_from_URL.ipynb +++ b/Python/Python_Download_video_from_URL.ipynb @@ -63,7 +63,7 @@ "tags": [] }, "source": [ - "**Description:** This notebook downloads a video from a given URL and saves it to a local file. It is usefull for organizations that need to download videos from the web for further processing." + "**Description:** This notebook downloads a video from a given URL and saves it to a local file." ] }, { @@ -74,7 +74,9 @@ "tags": [] }, "source": [ - "**References:**\n- [urllib.request](https://docs.python.org/3/library/urllib.request.html)\n- [shutil](https://docs.python.org/3/library/shutil.html)" + "**References:**\n", + "- [urllib.request](https://docs.python.org/3/library/urllib.request.html)\n", + "- [shutil](https://docs.python.org/3/library/shutil.html)" ] }, { @@ -107,8 +109,11 @@ "papermill": {}, "tags": [] }, - "source": "import urllib.request\nimport shutil", - "outputs": [] + "outputs": [], + "source": [ + "import urllib.request\n", + "import shutil" + ] }, { "cell_type": "markdown", @@ -118,7 +123,9 @@ "tags": [] }, "source": [ - "### Setup variables\n- `url`: URL of the video to download\n- `file_name`: Name of the file to save the video" + "### Setup variables\n", + "- `video_url`: URL of the video to download\n", + "- `output_path`: Name of the file to save the video" ] }, { @@ -129,8 +136,11 @@ "papermill": {}, "tags": [] }, - "source": "url = \"https://www.example.com/video.mp4\"\nfile_name = \"video.mp4\"", - "outputs": [] + "outputs": [], + "source": [ + "video_url = \"https://www.youtube.com/watch?v=ONiILHFItzs\"\n", + "output_path = \"video.mp4\"" + ] }, { "cell_type": "markdown", @@ -151,17 +161,7 @@ "tags": [] }, "source": [ - "### Download video" - ] - }, - { - "cell_type": "markdown", - "id": "a7504849-6f9a-4573-91db-04e1f3084756", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ + "### Download video\n", "Download the video from the given URL and save it to the local file." ] }, @@ -173,8 +173,11 @@ "papermill": {}, "tags": [] }, - "source": "with urllib.request.urlopen(url) as response, open(file_name, \"wb\") as out_file:\n shutil.copyfileobj(response, out_file)", - "outputs": [] + "outputs": [], + "source": [ + "with urllib.request.urlopen(video_url) as response, open(output_path, \"wb\") as out_file:\n", + " shutil.copyfileobj(response, out_file)" + ] }, { "cell_type": "markdown", @@ -206,8 +209,10 @@ "papermill": {}, "tags": [] }, - "source": "print(f\"Video saved to {file_name}\")", - "outputs": [] + "outputs": [], + "source": [ + "print(f\"Video saved to {output_path}\")" + ] }, { "cell_type": "markdown", @@ -249,4 +254,4 @@ }, "nbformat": 4, "nbformat_minor": 5 -} \ No newline at end of file +}