-
Notifications
You must be signed in to change notification settings - Fork 460
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2429 from jupyter-naas/2428-python-download-video…
…-from-url feat: 2428 python download video from url
- Loading branch information
Showing
1 changed file
with
257 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,257 @@ | ||
{ | ||
"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." | ||
] | ||
}, | ||
{ | ||
"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": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import urllib.request\n", | ||
"import shutil" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "8f39fb98-34c5-4f8b-9922-9dfff0da325e", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"### Setup variables\n", | ||
"- `video_url`: URL of the video to download\n", | ||
"- `output_path`: Name of the file to save the video" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "847a031b-8775-44c4-833b-d28e6a1631b5", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"video_url = \"https://www.youtube.com/watch?v=ONiILHFItzs\"\n", | ||
"output_path = \"video.mp4\"" | ||
] | ||
}, | ||
{ | ||
"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\n", | ||
"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": [] | ||
}, | ||
"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", | ||
"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": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"print(f\"Video saved to {output_path}\")" | ||
] | ||
}, | ||
{ | ||
"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 | ||
} |