This repository has been archived by the owner on Jun 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Download youtube playlist to google drive
- Loading branch information
Showing
2 changed files
with
164 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,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) |
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,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 | ||
} |