-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhello.py
More file actions
102 lines (79 loc) · 2.13 KB
/
Copy pathhello.py
File metadata and controls
102 lines (79 loc) · 2.13 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import mytube as mt
import os
import pyglet
from pytube.helpers import safe_filename
import glob
import logging as log
import c
log.basicConfig(level=log.INFO, format= c.LOG_FORMAT,handlers=[ log.StreamHandler(), log.FileHandler(c.LOG_PATH+'/'+c.LOG_FILE+'.log')])
#log.info('Logging Started')
def getSize(ss):
fsize= ss/1000000
return round(fsize,2)
def is_downloaded(fname):
fname= safe_filename(fname)
for file in glob.glob('Files/Musics/*.*'):
li= file.rindex('.')
name= file[13:li]
if(name==fname):
return file
return "NO"
def playSong(title, fpath):
log.info("Playing "+safe_filename(title))
song= pyglet.resource.media(fpath,streaming=False)
song.play()
pyglet.app.run()
def download(v):
link= v.url
ress= mt.getAllStreams(link)
audio_streams=[]
for r_stream in ress:
if(r_stream.type=='audio'):
audio_streams.append(r_stream)
r= audio_streams[0]
mt.downloadM(r)
fpath= str(os.path.join('Files/Musics',safe_filename(v.title)))+'.'+r.subtype
#playSong(v.title, fpath)
return fpath
"""
text= input("Enter Video Name:- ")
videos= mt.search_youtube(text)
v= videos[0]
bolo= is_downloaded(v.title)
if(bolo=='NO'):
print("Downloading ",v.title)
download(v)
else:
playSong(v.title, bolo)
"""
def giveInfo(v):
link= v.url
ress= mt.getAllStreams(link)
audio_streams=[]
for r_stream in ress:
if(r_stream.type=='audio'):
audio_streams.append(r_stream)
r= audio_streams[0]
size= getSize(r.filesize)
return size, str(size)+"MB"
def giveTitle(songName):
videos= mt.search_youtube(songName)
v= videos[0]
size, sizes= giveInfo(v)
data= '*Name:* '+v.title+'\n*Size:* '+sizes+'\n*Duration:* '+v.duration
legel= size<=c.SIZE_LIMIT
if(not legel):
data+="\n`File size should be less than "+str(c.SIZE_LIMIT)+" MB`\n*Try with another keyword*"
else:
data+="\n`Downloading, Please wait`"
return legel, data
def giveMe(songName):
videos= mt.search_youtube(songName)
v= videos[0]
bolo= is_downloaded(v.title)
if(bolo=='NO'):
log.info("Downloading "+v.title)
return download(v)
else:
log.info("Already Downloaded")
return bolo