Last active
May 1, 2023 18:21
-
-
Save mablue/afb0d4b2ef54a7f72564ede7127fa7aa to your computer and use it in GitHub Desktop.
youtube-download-to-google-drive-with-putube.ipynb
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
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"provenance": [], | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/mablue/afb0d4b2ef54a7f72564ede7127fa7aa/youtube-download-to-google-drive-with-putube.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"!pip install pytube\n", | |
"!pip install google-auth google-auth-oauthlib google-auth-httplib2" | |
], | |
"metadata": { | |
"id": "d-4tZciN_axq" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"from pytube import YouTube\n", | |
"from pytube.cli import on_progress\n", | |
"from google.colab import drive\n", | |
"import os" | |
], | |
"metadata": { | |
"id": "ygfsvdY8_bwg" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"drive.mount('/content/drive')" | |
], | |
"metadata": { | |
"id": "NpVkXaHb1ftQ" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"folder_name = 'YouTube Videos'\n", | |
"path = '/content/drive/MyDrive/' + folder_name\n", | |
"\n", | |
"if not os.path.exists(path):\n", | |
" os.makedirs(path)" | |
], | |
"metadata": { | |
"id": "TC_xhlAL_1cd" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"url = 'https://www.youtube.com/watch?v=Z_ikDlimN6A'\n", | |
"yt = YouTube(url, use_oauth=True, allow_oauth_cache=True,on_progress_callback=on_progress)\n", | |
"for stream in yt.streams:\n", | |
" print(stream)" | |
], | |
"metadata": { | |
"id": "Xuj7nsNKAQ24" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"video = yt.streams.get_by_itag(22)\n", | |
"video.download(output_path=path)" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 70 | |
}, | |
"id": "JDBKmzF9KtUa", | |
"outputId": "8e17bb12-ed1d-41c1-bd33-ff6f0fb6f0d9" | |
}, | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [] | |
}, | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"'/content/drive/MyDrive/YouTube Videos/Learn PyTorch for deep learning in a day Literally.mp4'" | |
], | |
"application/vnd.google.colaboratory.intrinsic+json": { | |
"type": "string" | |
} | |
}, | |
"metadata": {}, | |
"execution_count": 30 | |
} | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment