From e1bc89132c0884f45db1ccfacb6c27a9c1b5265a Mon Sep 17 00:00:00 2001 From: Ryuk Date: Tue, 17 Oct 2023 08:19:22 +0530 Subject: [PATCH] Add gdrive-ytdl (#612) Download youtube playlist to google drive --- Video_Scripts/gdrive-ytdl/README.md | 18 ++++ Video_Scripts/gdrive-ytdl/main.ipynb | 146 +++++++++++++++++++++++++++ 2 files changed, 164 insertions(+) create mode 100755 Video_Scripts/gdrive-ytdl/README.md create mode 100755 Video_Scripts/gdrive-ytdl/main.ipynb diff --git a/Video_Scripts/gdrive-ytdl/README.md b/Video_Scripts/gdrive-ytdl/README.md new file mode 100755 index 00000000..e4e7c880 --- /dev/null +++ b/Video_Scripts/gdrive-ytdl/README.md @@ -0,0 +1,18 @@ +# gdrive-ytdl + +Download youtube playlists to your google drive directly using google colab platform. + +### Usage +- Go to [Google colab](https://colab.google/) + +- Click on New Notebook and sign in with your google account. + +- Go to **File** > **Upload notebook** > **Upload** using upload files or from **github** link to file. + +- Click on `Connect` and wait till connect to google colab vps + +- Run + +**Orignal source repo [gdrive-ytdl](https://github.com/0xRyuk/gdrive-ytdl)** + +#### Author: [0xRyuk](https://github.com/0xRyuk) \ No newline at end of file diff --git a/Video_Scripts/gdrive-ytdl/main.ipynb b/Video_Scripts/gdrive-ytdl/main.ipynb new file mode 100755 index 00000000..742ea5f7 --- /dev/null +++ b/Video_Scripts/gdrive-ytdl/main.ipynb @@ -0,0 +1,146 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Install pytube to google colab" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "!pip install pytube" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from pytube import YouTube, Playlist\n", + "import os" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Connect to google drive" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from google.colab import drive\n", + "\n", + "drive.mount(\"/content/drive\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Configuration" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "config = {\n", + " \"resolution\": \"720p\",\n", + " \"path\": \"/content/drive/My Drive/gdrive-ytdl\"\n", + "}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Download function" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "def download(vid, path):\n", + " try:\n", + " yt = YouTube(vid)\n", + " video = yt.streams.filter(progressive=True, res='720p').first()\n", + " out = video.download(path)\n", + " print(out)\n", + " except Exception as e:\n", + " print(e)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Get input from user" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "link = (str(input('Link of Playlist URL: \\n')))\n", + "playlist = Playlist(link)\n", + "print(f'Downloading: {playlist.title}')\n", + "links = [l for l in playlist]\n", + "total_videos = len(links)\n", + "for i in range(total_videos):\n", + " print(f'Download {i + 1}/{total_videos} downloading...')\n", + " download(links[i], config[\"path\"])\n", + " print(f'Download {i+1}/{total_videos} complete.')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Count total size" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# get size\n", + "size = 0\n", + "\n", + "for path, dirs, files in os.walk(config[\"path\"]):\n", + " for f in files:\n", + " fp = os.path.join(path, f)\n", + " size += os.path.getsize(fp)\n", + "\n", + "# display size\n", + "print(\"Folder size: \" + str(size))" + ] + } + ], + "metadata": { + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}