Skip to content
This repository has been archived by the owner on Jun 8, 2024. It is now read-only.

Commit

Permalink
Add gdrive-ytdl (#612)
Browse files Browse the repository at this point in the history
Download youtube playlist to google drive
  • Loading branch information
0xRyuk authored Oct 17, 2023
1 parent 713fc74 commit e1bc891
Show file tree
Hide file tree
Showing 2 changed files with 164 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Video_Scripts/gdrive-ytdl/README.md
Original file line number Diff line number Diff line change
@@ -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)
146 changes: 146 additions & 0 deletions Video_Scripts/gdrive-ytdl/main.ipynb
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit e1bc891

Please sign in to comment.