-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmusic.py
56 lines (48 loc) · 1.49 KB
/
music.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import youtube_dl
import os
import getpass
import pafy
from termcolor import colored
from utils import Helpers
user = getpass.getuser()
utils = Helpers()
class Music:
@staticmethod
def create_path(path):
if not os.path.exists(path):
os.mkdir(path)
os.chdir(path)
os.chdir(path)
def mp3(self, url):
path = Helpers.check_platform('Music')
self.create_path(path)
ydl_opts = utils.ydl_options()
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download([url])
print(colored('Download Completed', 'green'))
def mp4(self, url):
path = Helpers.check_platform('Videos')
self.create_path(path)
try:
with youtube_dl.YoutubeDL({}) as ydl:
ydl.download([url])
print(colored('Download Completed', 'green'))
except:
print(colored('something went wrong try again', 'red'))
def playlist(self, url):
playlist = pafy.get_playlist(url)
path = Helpers.check_platform() + "/Playlists/{}".format(playlist['title'])
join_ = os.path.join(path)
file = Helpers.check_platform('Playlists')
if os.path.isdir(file) == True:
pass
else:
os.mkdir(file)
if os.path.isdir(path) == True:
pass
else:
os.mkdir(join_)
os.chdir(join_)
utils.playlist_info(url)
with youtube_dl.YoutubeDL({}) as ydl:
ydl.download([url])