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

Commit e1bc891

Browse files
authored
Add gdrive-ytdl (#612)
Download youtube playlist to google drive
1 parent 713fc74 commit e1bc891

File tree

2 files changed

+164
-0
lines changed

2 files changed

+164
-0
lines changed

Video_Scripts/gdrive-ytdl/README.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# gdrive-ytdl
2+
3+
Download youtube playlists to your google drive directly using google colab platform.
4+
5+
### Usage
6+
- Go to [Google colab](https://colab.google/)
7+
8+
- Click on New Notebook and sign in with your google account.
9+
10+
- Go to **File** > **Upload notebook** > **Upload** using upload files or from **github** link to file.
11+
12+
- Click on `Connect` and wait till connect to google colab vps
13+
14+
- Run
15+
16+
**Orignal source repo [gdrive-ytdl](https://github.com/0xRyuk/gdrive-ytdl)**
17+
18+
#### Author: [0xRyuk](https://github.com/0xRyuk)

Video_Scripts/gdrive-ytdl/main.ipynb

+146
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"Install pytube to google colab"
8+
]
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": null,
13+
"metadata": {},
14+
"outputs": [],
15+
"source": [
16+
"!pip install pytube"
17+
]
18+
},
19+
{
20+
"cell_type": "code",
21+
"execution_count": null,
22+
"metadata": {},
23+
"outputs": [],
24+
"source": [
25+
"from pytube import YouTube, Playlist\n",
26+
"import os"
27+
]
28+
},
29+
{
30+
"cell_type": "markdown",
31+
"metadata": {},
32+
"source": [
33+
"Connect to google drive"
34+
]
35+
},
36+
{
37+
"cell_type": "code",
38+
"execution_count": null,
39+
"metadata": {},
40+
"outputs": [],
41+
"source": [
42+
"from google.colab import drive\n",
43+
"\n",
44+
"drive.mount(\"/content/drive\")"
45+
]
46+
},
47+
{
48+
"cell_type": "markdown",
49+
"metadata": {},
50+
"source": [
51+
"Configuration"
52+
]
53+
},
54+
{
55+
"cell_type": "code",
56+
"execution_count": null,
57+
"metadata": {},
58+
"outputs": [],
59+
"source": [
60+
"config = {\n",
61+
" \"resolution\": \"720p\",\n",
62+
" \"path\": \"/content/drive/My Drive/gdrive-ytdl\"\n",
63+
"}"
64+
]
65+
},
66+
{
67+
"cell_type": "markdown",
68+
"metadata": {},
69+
"source": [
70+
"Download function"
71+
]
72+
},
73+
{
74+
"cell_type": "code",
75+
"execution_count": null,
76+
"metadata": {},
77+
"outputs": [],
78+
"source": [
79+
"def download(vid, path):\n",
80+
" try:\n",
81+
" yt = YouTube(vid)\n",
82+
" video = yt.streams.filter(progressive=True, res='720p').first()\n",
83+
" out = video.download(path)\n",
84+
" print(out)\n",
85+
" except Exception as e:\n",
86+
" print(e)"
87+
]
88+
},
89+
{
90+
"cell_type": "markdown",
91+
"metadata": {},
92+
"source": [
93+
"Get input from user"
94+
]
95+
},
96+
{
97+
"cell_type": "code",
98+
"execution_count": null,
99+
"metadata": {},
100+
"outputs": [],
101+
"source": [
102+
"link = (str(input('Link of Playlist URL: \\n')))\n",
103+
"playlist = Playlist(link)\n",
104+
"print(f'Downloading: {playlist.title}')\n",
105+
"links = [l for l in playlist]\n",
106+
"total_videos = len(links)\n",
107+
"for i in range(total_videos):\n",
108+
" print(f'Download {i + 1}/{total_videos} downloading...')\n",
109+
" download(links[i], config[\"path\"])\n",
110+
" print(f'Download {i+1}/{total_videos} complete.')"
111+
]
112+
},
113+
{
114+
"cell_type": "markdown",
115+
"metadata": {},
116+
"source": [
117+
"Count total size"
118+
]
119+
},
120+
{
121+
"cell_type": "code",
122+
"execution_count": null,
123+
"metadata": {},
124+
"outputs": [],
125+
"source": [
126+
"# get size\n",
127+
"size = 0\n",
128+
"\n",
129+
"for path, dirs, files in os.walk(config[\"path\"]):\n",
130+
" for f in files:\n",
131+
" fp = os.path.join(path, f)\n",
132+
" size += os.path.getsize(fp)\n",
133+
"\n",
134+
"# display size\n",
135+
"print(\"Folder size: \" + str(size))"
136+
]
137+
}
138+
],
139+
"metadata": {
140+
"language_info": {
141+
"name": "python"
142+
}
143+
},
144+
"nbformat": 4,
145+
"nbformat_minor": 2
146+
}

0 commit comments

Comments
 (0)