From 2dc87da6c3a4086f2f6b0e1d7a6dceb6733b3060 Mon Sep 17 00:00:00 2001 From: Florent Ravenel Date: Fri, 1 Dec 2023 11:07:40 +0100 Subject: [PATCH 1/2] feat(Python): Add Download video from URL --- Python/Python_Download_video_from_URL.ipynb | 252 ++++++++++++++++++++ 1 file changed, 252 insertions(+) create mode 100644 Python/Python_Download_video_from_URL.ipynb diff --git a/Python/Python_Download_video_from_URL.ipynb b/Python/Python_Download_video_from_URL.ipynb new file mode 100644 index 0000000000..947eac6829 --- /dev/null +++ b/Python/Python_Download_video_from_URL.ipynb @@ -0,0 +1,252 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "8b9bdc3d-af13-4761-9f6f-65d2f895b91d", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "\"Naas\"" + ] + }, + { + "cell_type": "markdown", + "id": "662e1c29-6809-4959-b42b-1702aada04a6", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "# Python - Download video from URL" + ] + }, + { + "cell_type": "markdown", + "id": "e35f4522-9c4c-4be4-a648-60f69669e85b", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Tags:** #python #video #download #url #library #function" + ] + }, + { + "cell_type": "markdown", + "id": "0c5297fa-a2dd-44ad-a60e-4f612bdae11e", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Author:** [Florent Ravenel](https://www.linkedin.com/in/florent-ravenel/)" + ] + }, + { + "cell_type": "markdown", + "id": "7ac475c2-e536-4156-ab2b-6742c14ade93", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Last update:** 2023-12-01 (Created: 2023-12-01)" + ] + }, + { + "cell_type": "markdown", + "id": "3ef1efb6-d64b-4761-812c-466d6e5ab557", + "metadata": { + "papermill": {}, + "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." + ] + }, + { + "cell_type": "markdown", + "id": "b5a0df58-d5f1-40b9-bebc-3ab1eb01c84b", + "metadata": { + "papermill": {}, + "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)" + ] + }, + { + "cell_type": "markdown", + "id": "19f32ba6-619c-4e10-82ab-7151e6e3ec1f", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Input" + ] + }, + { + "cell_type": "markdown", + "id": "531ebdee-dc35-47f1-9646-3c847cb94b3f", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Import libraries" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f78e0218-f5b9-4099-8fbb-fdb47fc8258f", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": "import urllib.request\nimport shutil", + "outputs": [] + }, + { + "cell_type": "markdown", + "id": "8f39fb98-34c5-4f8b-9922-9dfff0da325e", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Setup variables\n- `url`: URL of the video to download\n- `file_name`: Name of the file to save the video" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "847a031b-8775-44c4-833b-d28e6a1631b5", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": "url = \"https://www.example.com/video.mp4\"\nfile_name = \"video.mp4\"", + "outputs": [] + }, + { + "cell_type": "markdown", + "id": "c4883771-fbe1-4ed4-9435-1f16537fa2ee", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Model" + ] + }, + { + "cell_type": "markdown", + "id": "1dfa279d-27b2-46e5-98cf-7f50a3124cde", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Download video" + ] + }, + { + "cell_type": "markdown", + "id": "a7504849-6f9a-4573-91db-04e1f3084756", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "Download the video from the given URL and save it to the local file." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3db61a00-5262-4469-a25e-a8f305a48084", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": "with urllib.request.urlopen(url) as response, open(file_name, \"wb\") as out_file:\n shutil.copyfileobj(response, out_file)", + "outputs": [] + }, + { + "cell_type": "markdown", + "id": "0891dc2e-3b34-4c9c-bdf9-90fc4a85d7f8", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Output" + ] + }, + { + "cell_type": "markdown", + "id": "74be6c14-1655-44c9-9e59-b939275418a3", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Display result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7ef22757-0520-4df4-b797-442b379231a1", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": "print(f\"Video saved to {file_name}\")", + "outputs": [] + }, + { + "cell_type": "markdown", + "id": "93156a03-cec3-42c9-a976-24003cd413bf", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + " " + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.6" + }, + "widgets": { + "application/vnd.jupyter.widget-state+json": { + "state": {}, + "version_major": 2, + "version_minor": 0 + } + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} \ No newline at end of file From 9a60eef176793833e1ca3fea5a78e26ec0fd1423 Mon Sep 17 00:00:00 2001 From: Florent Ravenel Date: Fri, 1 Dec 2023 12:01:32 +0100 Subject: [PATCH 2/2] 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 +}