-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.py
38 lines (32 loc) · 1.03 KB
/
player.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
import youtube_dl as yt_dl
import Values
from youtubesearchpython import VideosSearch
import os
def Search(song_requested):
search_result = VideosSearch(f'{song_requested} song', limit=1)
return search_result
def download_func(url, id):
if os.path.isfile(f'./Storage/{id}.mp3'):
print(f'{Values.Song_exists} ({id})')
return
else:
print(f'{Values.song_isDownloading} ({id})')
ydl_opts = {
'format': 'bestaudio',
'extractaudio': True,
'preferredcodec': 'mp3',
'preferredquality': Values.Song_bitrate,
'verbose': True,
'outtmpl': f'Storage/{id}.mp3',
'fragment_retries': 3,
'restrictfilenames': True,
'noplaylist': True,
'nocheckcertificate': True,
'ignoreerrors': False,
'logtostderr': False,
'quiet': True,
'no_warnings': True,
'default_search': 'auto',
}
yt_dl.YoutubeDL(ydl_opts).download([url])
#yt_dl.YoutubeDL(ydl_opts).download([search_result.result()['result'][0]['link']])