Skip to content

Commit

Permalink
feat(Python): Add Download video from URL
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorentLvr committed Dec 1, 2023
1 parent 6100789 commit 2dc87da
Showing 1 changed file with 252 additions and 0 deletions.
252 changes: 252 additions & 0 deletions Python/Python_Download_video_from_URL.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "8b9bdc3d-af13-4761-9f6f-65d2f895b91d",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"<img width=\"10%\" alt=\"Naas\" src=\"https://landen.imgix.net/jtci2pxwjczr/assets/5ice39g4.png?w=160\"/>"
]
},
{
"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
}

0 comments on commit 2dc87da

Please sign in to comment.