Skip to content

Commit

Permalink
feat: download video from url to local
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorentLvr committed Dec 1, 2023
1 parent 2dc87da commit 9a60eef
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions Python/Python_Download_video_from_URL.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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."
]
},
{
Expand All @@ -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)"
]
},
{
Expand Down Expand Up @@ -107,8 +109,11 @@
"papermill": {},
"tags": []
},
"source": "import urllib.request\nimport shutil",
"outputs": []
"outputs": [],
"source": [
"import urllib.request\n",
"import shutil"
]
},
{
"cell_type": "markdown",
Expand All @@ -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"
]
},
{
Expand All @@ -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",
Expand All @@ -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."
]
},
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -249,4 +254,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}

0 comments on commit 9a60eef

Please sign in to comment.