Skip to content

Instantly share code, notes, and snippets.

@pouyaardehkhani
Last active February 13, 2022 08:51
Show Gist options
  • Select an option

  • Save pouyaardehkhani/537958a13e23088b63769fbf65dde119 to your computer and use it in GitHub Desktop.

Select an option

Save pouyaardehkhani/537958a13e23088b63769fbf65dde119 to your computer and use it in GitHub Desktop.
Download_from_youtube
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "Download from youtube.ipynb",
"provenance": [],
"collapsed_sections": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"7a0491e67c8c49cf98700d8a148c2d31": {
"model_module": "@jupyter-widgets/controls",
"model_name": "HBoxModel",
"model_module_version": "1.5.0",
"state": {
"_view_name": "HBoxView",
"_dom_classes": [],
"_model_name": "HBoxModel",
"_view_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"_view_count": null,
"_view_module_version": "1.5.0",
"box_style": "",
"layout": "IPY_MODEL_55e7d09763174e109eadfac9d913c9eb",
"_model_module": "@jupyter-widgets/controls",
"children": [
"IPY_MODEL_c9dd84068507470da27e4af5c66b4fce",
"IPY_MODEL_087ecf20373f4584af76f8f2f2c8123a",
"IPY_MODEL_2d2ded35015743fa85d5700a36cc9614"
]
}
},
"55e7d09763174e109eadfac9d913c9eb": {
"model_module": "@jupyter-widgets/base",
"model_name": "LayoutModel",
"model_module_version": "1.2.0",
"state": {
"_view_name": "LayoutView",
"grid_template_rows": null,
"right": null,
"justify_content": null,
"_view_module": "@jupyter-widgets/base",
"overflow": null,
"_model_module_version": "1.2.0",
"_view_count": null,
"flex_flow": null,
"width": null,
"min_width": null,
"border": null,
"align_items": null,
"bottom": null,
"_model_module": "@jupyter-widgets/base",
"top": null,
"grid_column": null,
"overflow_y": null,
"overflow_x": null,
"grid_auto_flow": null,
"grid_area": null,
"grid_template_columns": null,
"flex": null,
"_model_name": "LayoutModel",
"justify_items": null,
"grid_row": null,
"max_height": null,
"align_content": null,
"visibility": null,
"align_self": null,
"height": null,
"min_height": null,
"padding": null,
"grid_auto_rows": null,
"grid_gap": null,
"max_width": null,
"order": null,
"_view_module_version": "1.2.0",
"grid_template_areas": null,
"object_position": null,
"object_fit": null,
"grid_auto_columns": null,
"margin": null,
"display": null,
"left": null
}
},
"c9dd84068507470da27e4af5c66b4fce": {
"model_module": "@jupyter-widgets/controls",
"model_name": "HTMLModel",
"model_module_version": "1.5.0",
"state": {
"_view_name": "HTMLView",
"style": "IPY_MODEL_b355de23c8c64f3c964c0144d2eb9a63",
"_dom_classes": [],
"description": "",
"_model_name": "HTMLModel",
"placeholder": "​",
"_view_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"value": "100%",
"_view_count": null,
"_view_module_version": "1.5.0",
"description_tooltip": null,
"_model_module": "@jupyter-widgets/controls",
"layout": "IPY_MODEL_3476e18c5dfe4b0ca4e719863fc3655f"
}
},
"087ecf20373f4584af76f8f2f2c8123a": {
"model_module": "@jupyter-widgets/controls",
"model_name": "FloatProgressModel",
"model_module_version": "1.5.0",
"state": {
"_view_name": "ProgressView",
"style": "IPY_MODEL_b764e6d391d241f48d6e0f72aa99e4ea",
"_dom_classes": [],
"description": "",
"_model_name": "FloatProgressModel",
"bar_style": "success",
"max": 3,
"_view_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"value": 3,
"_view_count": null,
"_view_module_version": "1.5.0",
"orientation": "horizontal",
"min": 0,
"description_tooltip": null,
"_model_module": "@jupyter-widgets/controls",
"layout": "IPY_MODEL_82b8b8e272384b12b56a845eed655b88"
}
},
"2d2ded35015743fa85d5700a36cc9614": {
"model_module": "@jupyter-widgets/controls",
"model_name": "HTMLModel",
"model_module_version": "1.5.0",
"state": {
"_view_name": "HTMLView",
"style": "IPY_MODEL_f3dbaec5df714998b0dc3830f1a900ce",
"_dom_classes": [],
"description": "",
"_model_name": "HTMLModel",
"placeholder": "​",
"_view_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"value": " 3/3 [00:09<00:00, 3.45s/it]",
"_view_count": null,
"_view_module_version": "1.5.0",
"description_tooltip": null,
"_model_module": "@jupyter-widgets/controls",
"layout": "IPY_MODEL_56664b992a6c4bb9a366903c6ee0abbe"
}
},
"b355de23c8c64f3c964c0144d2eb9a63": {
"model_module": "@jupyter-widgets/controls",
"model_name": "DescriptionStyleModel",
"model_module_version": "1.5.0",
"state": {
"_view_name": "StyleView",
"_model_name": "DescriptionStyleModel",
"description_width": "",
"_view_module": "@jupyter-widgets/base",
"_model_module_version": "1.5.0",
"_view_count": null,
"_view_module_version": "1.2.0",
"_model_module": "@jupyter-widgets/controls"
}
},
"3476e18c5dfe4b0ca4e719863fc3655f": {
"model_module": "@jupyter-widgets/base",
"model_name": "LayoutModel",
"model_module_version": "1.2.0",
"state": {
"_view_name": "LayoutView",
"grid_template_rows": null,
"right": null,
"justify_content": null,
"_view_module": "@jupyter-widgets/base",
"overflow": null,
"_model_module_version": "1.2.0",
"_view_count": null,
"flex_flow": null,
"width": null,
"min_width": null,
"border": null,
"align_items": null,
"bottom": null,
"_model_module": "@jupyter-widgets/base",
"top": null,
"grid_column": null,
"overflow_y": null,
"overflow_x": null,
"grid_auto_flow": null,
"grid_area": null,
"grid_template_columns": null,
"flex": null,
"_model_name": "LayoutModel",
"justify_items": null,
"grid_row": null,
"max_height": null,
"align_content": null,
"visibility": null,
"align_self": null,
"height": null,
"min_height": null,
"padding": null,
"grid_auto_rows": null,
"grid_gap": null,
"max_width": null,
"order": null,
"_view_module_version": "1.2.0",
"grid_template_areas": null,
"object_position": null,
"object_fit": null,
"grid_auto_columns": null,
"margin": null,
"display": null,
"left": null
}
},
"b764e6d391d241f48d6e0f72aa99e4ea": {
"model_module": "@jupyter-widgets/controls",
"model_name": "ProgressStyleModel",
"model_module_version": "1.5.0",
"state": {
"_view_name": "StyleView",
"_model_name": "ProgressStyleModel",
"description_width": "",
"_view_module": "@jupyter-widgets/base",
"_model_module_version": "1.5.0",
"_view_count": null,
"_view_module_version": "1.2.0",
"bar_color": null,
"_model_module": "@jupyter-widgets/controls"
}
},
"82b8b8e272384b12b56a845eed655b88": {
"model_module": "@jupyter-widgets/base",
"model_name": "LayoutModel",
"model_module_version": "1.2.0",
"state": {
"_view_name": "LayoutView",
"grid_template_rows": null,
"right": null,
"justify_content": null,
"_view_module": "@jupyter-widgets/base",
"overflow": null,
"_model_module_version": "1.2.0",
"_view_count": null,
"flex_flow": null,
"width": null,
"min_width": null,
"border": null,
"align_items": null,
"bottom": null,
"_model_module": "@jupyter-widgets/base",
"top": null,
"grid_column": null,
"overflow_y": null,
"overflow_x": null,
"grid_auto_flow": null,
"grid_area": null,
"grid_template_columns": null,
"flex": null,
"_model_name": "LayoutModel",
"justify_items": null,
"grid_row": null,
"max_height": null,
"align_content": null,
"visibility": null,
"align_self": null,
"height": null,
"min_height": null,
"padding": null,
"grid_auto_rows": null,
"grid_gap": null,
"max_width": null,
"order": null,
"_view_module_version": "1.2.0",
"grid_template_areas": null,
"object_position": null,
"object_fit": null,
"grid_auto_columns": null,
"margin": null,
"display": null,
"left": null
}
},
"f3dbaec5df714998b0dc3830f1a900ce": {
"model_module": "@jupyter-widgets/controls",
"model_name": "DescriptionStyleModel",
"model_module_version": "1.5.0",
"state": {
"_view_name": "StyleView",
"_model_name": "DescriptionStyleModel",
"description_width": "",
"_view_module": "@jupyter-widgets/base",
"_model_module_version": "1.5.0",
"_view_count": null,
"_view_module_version": "1.2.0",
"_model_module": "@jupyter-widgets/controls"
}
},
"56664b992a6c4bb9a366903c6ee0abbe": {
"model_module": "@jupyter-widgets/base",
"model_name": "LayoutModel",
"model_module_version": "1.2.0",
"state": {
"_view_name": "LayoutView",
"grid_template_rows": null,
"right": null,
"justify_content": null,
"_view_module": "@jupyter-widgets/base",
"overflow": null,
"_model_module_version": "1.2.0",
"_view_count": null,
"flex_flow": null,
"width": null,
"min_width": null,
"border": null,
"align_items": null,
"bottom": null,
"_model_module": "@jupyter-widgets/base",
"top": null,
"grid_column": null,
"overflow_y": null,
"overflow_x": null,
"grid_auto_flow": null,
"grid_area": null,
"grid_template_columns": null,
"flex": null,
"_model_name": "LayoutModel",
"justify_items": null,
"grid_row": null,
"max_height": null,
"align_content": null,
"visibility": null,
"align_self": null,
"height": null,
"min_height": null,
"padding": null,
"grid_auto_rows": null,
"grid_gap": null,
"max_width": null,
"order": null,
"_view_module_version": "1.2.0",
"grid_template_areas": null,
"object_position": null,
"object_fit": null,
"grid_auto_columns": null,
"margin": null,
"display": null,
"left": null
}
}
}
}
},
"cells": [
{
"cell_type": "markdown",
"source": [
"# Downloading videos from Youtube"
],
"metadata": {
"id": "fBujf9LZD5GF"
}
},
{
"cell_type": "code",
"source": [
"pip install git+https://github.com/baxterisme/pytube"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "RIuTKr1g0cDx",
"outputId": "e3c75597-9e08-41e4-c33a-e0c92cc118e9"
},
"execution_count": 17,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Collecting git+https://github.com/baxterisme/pytube\n",
" Cloning https://github.com/baxterisme/pytube to /tmp/pip-req-build-82fy2wvr\n",
" Running command git clone -q https://github.com/baxterisme/pytube /tmp/pip-req-build-82fy2wvr\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"from pytube import YouTube"
],
"metadata": {
"id": "VCVcaMduy0TR"
},
"execution_count": 18,
"outputs": []
},
{
"cell_type": "code",
"source": [
"from tqdm.notebook import tqdm"
],
"metadata": {
"id": "oorpTo9sFhr6"
},
"execution_count": 19,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"# From a single link"
],
"metadata": {
"id": "b-EeNmf1D7gS"
}
},
{
"cell_type": "code",
"source": [
"link = \"https://www.youtube.com/watch?v=r3ToTU1_iL8\"\n",
"yt = YouTube(link)"
],
"metadata": {
"id": "9l9pHm1O3d7L"
},
"execution_count": 20,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"## Show all the streams available"
],
"metadata": {
"id": "AdvQ6LohECST"
}
},
{
"cell_type": "code",
"source": [
"yt.streams.all()"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "XZxkGnuy3_or",
"outputId": "61a2262a-4625-4c98-fe2e-fbd371d264f8"
},
"execution_count": 21,
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"/usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:1: DeprecationWarning: Call to deprecated function all (This object can be treated as a list, all() is useless).\n",
" \"\"\"Entry point for launching an IPython kernel.\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"[<Stream: itag=\"17\" mime_type=\"video/3gpp\" res=\"144p\" fps=\"8fps\" vcodec=\"mp4v.20.3\" acodec=\"mp4a.40.2\" progressive=\"True\" type=\"video\">,\n",
" <Stream: itag=\"18\" mime_type=\"video/mp4\" res=\"360p\" fps=\"30fps\" vcodec=\"avc1.42001E\" acodec=\"mp4a.40.2\" progressive=\"True\" type=\"video\">,\n",
" <Stream: itag=\"22\" mime_type=\"video/mp4\" res=\"720p\" fps=\"30fps\" vcodec=\"avc1.64001F\" acodec=\"mp4a.40.2\" progressive=\"True\" type=\"video\">,\n",
" <Stream: itag=\"136\" mime_type=\"video/mp4\" res=\"720p\" fps=\"30fps\" vcodec=\"avc1.4d401f\" progressive=\"False\" type=\"video\">,\n",
" <Stream: itag=\"247\" mime_type=\"video/webm\" res=\"720p\" fps=\"30fps\" vcodec=\"vp9\" progressive=\"False\" type=\"video\">,\n",
" <Stream: itag=\"398\" mime_type=\"video/mp4\" res=\"720p\" fps=\"30fps\" vcodec=\"av01.0.05M.08\" progressive=\"False\" type=\"video\">,\n",
" <Stream: itag=\"135\" mime_type=\"video/mp4\" res=\"480p\" fps=\"30fps\" vcodec=\"avc1.4d401f\" progressive=\"False\" type=\"video\">,\n",
" <Stream: itag=\"244\" mime_type=\"video/webm\" res=\"480p\" fps=\"30fps\" vcodec=\"vp9\" progressive=\"False\" type=\"video\">,\n",
" <Stream: itag=\"397\" mime_type=\"video/mp4\" res=\"480p\" fps=\"30fps\" vcodec=\"av01.0.04M.08\" progressive=\"False\" type=\"video\">,\n",
" <Stream: itag=\"134\" mime_type=\"video/mp4\" res=\"360p\" fps=\"30fps\" vcodec=\"avc1.4d401e\" progressive=\"False\" type=\"video\">,\n",
" <Stream: itag=\"243\" mime_type=\"video/webm\" res=\"360p\" fps=\"30fps\" vcodec=\"vp9\" progressive=\"False\" type=\"video\">,\n",
" <Stream: itag=\"396\" mime_type=\"video/mp4\" res=\"360p\" fps=\"30fps\" vcodec=\"av01.0.01M.08\" progressive=\"False\" type=\"video\">,\n",
" <Stream: itag=\"133\" mime_type=\"video/mp4\" res=\"240p\" fps=\"30fps\" vcodec=\"avc1.4d4015\" progressive=\"False\" type=\"video\">,\n",
" <Stream: itag=\"242\" mime_type=\"video/webm\" res=\"240p\" fps=\"30fps\" vcodec=\"vp9\" progressive=\"False\" type=\"video\">,\n",
" <Stream: itag=\"395\" mime_type=\"video/mp4\" res=\"240p\" fps=\"30fps\" vcodec=\"av01.0.00M.08\" progressive=\"False\" type=\"video\">,\n",
" <Stream: itag=\"160\" mime_type=\"video/mp4\" res=\"144p\" fps=\"30fps\" vcodec=\"avc1.4d400c\" progressive=\"False\" type=\"video\">,\n",
" <Stream: itag=\"278\" mime_type=\"video/webm\" res=\"144p\" fps=\"30fps\" vcodec=\"vp9\" progressive=\"False\" type=\"video\">,\n",
" <Stream: itag=\"394\" mime_type=\"video/mp4\" res=\"144p\" fps=\"30fps\" vcodec=\"av01.0.00M.08\" progressive=\"False\" type=\"video\">,\n",
" <Stream: itag=\"139\" mime_type=\"audio/mp4\" abr=\"48kbps\" acodec=\"mp4a.40.5\" progressive=\"False\" type=\"audio\">,\n",
" <Stream: itag=\"140\" mime_type=\"audio/mp4\" abr=\"128kbps\" acodec=\"mp4a.40.2\" progressive=\"False\" type=\"audio\">,\n",
" <Stream: itag=\"249\" mime_type=\"audio/webm\" abr=\"50kbps\" acodec=\"opus\" progressive=\"False\" type=\"audio\">,\n",
" <Stream: itag=\"250\" mime_type=\"audio/webm\" abr=\"70kbps\" acodec=\"opus\" progressive=\"False\" type=\"audio\">,\n",
" <Stream: itag=\"251\" mime_type=\"audio/webm\" abr=\"160kbps\" acodec=\"opus\" progressive=\"False\" type=\"audio\">]"
]
},
"metadata": {},
"execution_count": 21
}
]
},
{
"cell_type": "markdown",
"source": [
"### the streams with audio"
],
"metadata": {
"id": "Fvo0FZw2EKby"
}
},
{
"cell_type": "code",
"source": [
"yt.streams.filter(progressive=True).all()"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "zSQnKVva5UIR",
"outputId": "9d7056a5-8a46-4f3f-ca52-c2dd6204ca25"
},
"execution_count": 22,
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"/usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:1: DeprecationWarning: Call to deprecated function all (This object can be treated as a list, all() is useless).\n",
" \"\"\"Entry point for launching an IPython kernel.\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"[<Stream: itag=\"17\" mime_type=\"video/3gpp\" res=\"144p\" fps=\"8fps\" vcodec=\"mp4v.20.3\" acodec=\"mp4a.40.2\" progressive=\"True\" type=\"video\">,\n",
" <Stream: itag=\"18\" mime_type=\"video/mp4\" res=\"360p\" fps=\"30fps\" vcodec=\"avc1.42001E\" acodec=\"mp4a.40.2\" progressive=\"True\" type=\"video\">,\n",
" <Stream: itag=\"22\" mime_type=\"video/mp4\" res=\"720p\" fps=\"30fps\" vcodec=\"avc1.64001F\" acodec=\"mp4a.40.2\" progressive=\"True\" type=\"video\">]"
]
},
"metadata": {},
"execution_count": 22
}
]
},
{
"cell_type": "markdown",
"source": [
"### streams without the audio \n",
"\n",
"you need to download both audio and video then combine them together"
],
"metadata": {
"id": "d-VoowS5ESt6"
}
},
{
"cell_type": "code",
"source": [
"yt.streams.filter(adaptive=True).all()"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "PwYk0x6i5S6y",
"outputId": "afef4e58-bbd5-426e-8514-b14af880ea36"
},
"execution_count": 23,
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"/usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:1: DeprecationWarning: Call to deprecated function all (This object can be treated as a list, all() is useless).\n",
" \"\"\"Entry point for launching an IPython kernel.\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"[<Stream: itag=\"136\" mime_type=\"video/mp4\" res=\"720p\" fps=\"30fps\" vcodec=\"avc1.4d401f\" progressive=\"False\" type=\"video\">,\n",
" <Stream: itag=\"247\" mime_type=\"video/webm\" res=\"720p\" fps=\"30fps\" vcodec=\"vp9\" progressive=\"False\" type=\"video\">,\n",
" <Stream: itag=\"398\" mime_type=\"video/mp4\" res=\"720p\" fps=\"30fps\" vcodec=\"av01.0.05M.08\" progressive=\"False\" type=\"video\">,\n",
" <Stream: itag=\"135\" mime_type=\"video/mp4\" res=\"480p\" fps=\"30fps\" vcodec=\"avc1.4d401f\" progressive=\"False\" type=\"video\">,\n",
" <Stream: itag=\"244\" mime_type=\"video/webm\" res=\"480p\" fps=\"30fps\" vcodec=\"vp9\" progressive=\"False\" type=\"video\">,\n",
" <Stream: itag=\"397\" mime_type=\"video/mp4\" res=\"480p\" fps=\"30fps\" vcodec=\"av01.0.04M.08\" progressive=\"False\" type=\"video\">,\n",
" <Stream: itag=\"134\" mime_type=\"video/mp4\" res=\"360p\" fps=\"30fps\" vcodec=\"avc1.4d401e\" progressive=\"False\" type=\"video\">,\n",
" <Stream: itag=\"243\" mime_type=\"video/webm\" res=\"360p\" fps=\"30fps\" vcodec=\"vp9\" progressive=\"False\" type=\"video\">,\n",
" <Stream: itag=\"396\" mime_type=\"video/mp4\" res=\"360p\" fps=\"30fps\" vcodec=\"av01.0.01M.08\" progressive=\"False\" type=\"video\">,\n",
" <Stream: itag=\"133\" mime_type=\"video/mp4\" res=\"240p\" fps=\"30fps\" vcodec=\"avc1.4d4015\" progressive=\"False\" type=\"video\">,\n",
" <Stream: itag=\"242\" mime_type=\"video/webm\" res=\"240p\" fps=\"30fps\" vcodec=\"vp9\" progressive=\"False\" type=\"video\">,\n",
" <Stream: itag=\"395\" mime_type=\"video/mp4\" res=\"240p\" fps=\"30fps\" vcodec=\"av01.0.00M.08\" progressive=\"False\" type=\"video\">,\n",
" <Stream: itag=\"160\" mime_type=\"video/mp4\" res=\"144p\" fps=\"30fps\" vcodec=\"avc1.4d400c\" progressive=\"False\" type=\"video\">,\n",
" <Stream: itag=\"278\" mime_type=\"video/webm\" res=\"144p\" fps=\"30fps\" vcodec=\"vp9\" progressive=\"False\" type=\"video\">,\n",
" <Stream: itag=\"394\" mime_type=\"video/mp4\" res=\"144p\" fps=\"30fps\" vcodec=\"av01.0.00M.08\" progressive=\"False\" type=\"video\">,\n",
" <Stream: itag=\"139\" mime_type=\"audio/mp4\" abr=\"48kbps\" acodec=\"mp4a.40.5\" progressive=\"False\" type=\"audio\">,\n",
" <Stream: itag=\"140\" mime_type=\"audio/mp4\" abr=\"128kbps\" acodec=\"mp4a.40.2\" progressive=\"False\" type=\"audio\">,\n",
" <Stream: itag=\"249\" mime_type=\"audio/webm\" abr=\"50kbps\" acodec=\"opus\" progressive=\"False\" type=\"audio\">,\n",
" <Stream: itag=\"250\" mime_type=\"audio/webm\" abr=\"70kbps\" acodec=\"opus\" progressive=\"False\" type=\"audio\">,\n",
" <Stream: itag=\"251\" mime_type=\"audio/webm\" abr=\"160kbps\" acodec=\"opus\" progressive=\"False\" type=\"audio\">]"
]
},
"metadata": {},
"execution_count": 23
}
]
},
{
"cell_type": "markdown",
"source": [
"## download via stream itag"
],
"metadata": {
"id": "nukJe2izEhpJ"
}
},
{
"cell_type": "code",
"source": [
"stream = yt.streams.get_by_itag('22')\n",
"stream.download()"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 35
},
"id": "YND7K4OI4J2g",
"outputId": "09c25d74-e221-4b5d-a79d-9e94ed327bd5"
},
"execution_count": 24,
"outputs": [
{
"output_type": "execute_result",
"data": {
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "string"
},
"text/plain": [
"'/content/The Top 15 Greatest Coaches in NBA History NBA on TNT.mp4'"
]
},
"metadata": {},
"execution_count": 24
}
]
},
{
"cell_type": "markdown",
"source": [
"# download a playlist"
],
"metadata": {
"id": "RpzJ_YWFEvUc"
}
},
{
"cell_type": "code",
"source": [
"from pytube import Playlist\n",
"playlist = Playlist(\"https://www.youtube.com/watch?v=Edpy1szoG80&list=PL153hDY-y1E00uQtCVCVC8xJ25TYX8yPU\")\n",
"for video in tqdm(playlist):\n",
" yt = YouTube(video)\n",
" stream = yt.streams.get_by_itag('22') # 720p with audio\n",
" stream.download(output_path=\"/content/playlist/\") # you can specify an output location like this"
],
"metadata": {
"id": "CCjVIEEIExyw",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 49,
"referenced_widgets": [
"7a0491e67c8c49cf98700d8a148c2d31",
"55e7d09763174e109eadfac9d913c9eb",
"c9dd84068507470da27e4af5c66b4fce",
"087ecf20373f4584af76f8f2f2c8123a",
"2d2ded35015743fa85d5700a36cc9614",
"b355de23c8c64f3c964c0144d2eb9a63",
"3476e18c5dfe4b0ca4e719863fc3655f",
"b764e6d391d241f48d6e0f72aa99e4ea",
"82b8b8e272384b12b56a845eed655b88",
"f3dbaec5df714998b0dc3830f1a900ce",
"56664b992a6c4bb9a366903c6ee0abbe"
]
},
"outputId": "54a68953-ed00-4978-bebe-0a142517b1a8"
},
"execution_count": 25,
"outputs": [
{
"output_type": "display_data",
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "7a0491e67c8c49cf98700d8a148c2d31",
"version_minor": 0,
"version_major": 2
},
"text/plain": [
" 0%| | 0/3 [00:00<?, ?it/s]"
]
},
"metadata": {}
}
]
},
{
"cell_type": "markdown",
"source": [
"in order to download from Google Colab first zip your playlist folder"
],
"metadata": {
"id": "767XrC7bQrms"
}
},
{
"cell_type": "code",
"source": [
"!zip -r /content/name.zip /content/playlist"
],
"metadata": {
"id": "b7keO8KCQP4k"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"now run this code to download your zip file "
],
"metadata": {
"id": "1xCD4XSdQ536"
}
},
{
"cell_type": "code",
"source": [
"from google.colab import files\n",
"files.download(f\"/content/name.zip\")"
],
"metadata": {
"id": "lniHxExVQ-97"
},
"execution_count": null,
"outputs": []
}
]
}

This is a simple way to download a video or a playlist from Youtube via Google Colab or Jupyter Notebook.

I personaly recommend to use the following notebook in Google Colab.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment