-
Notifications
You must be signed in to change notification settings - Fork 4
/
ytvid.py
38 lines (33 loc) · 1.28 KB
/
ytvid.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 pafy
from downloaderOOP import *
class ytvideo(object):
def __init__(self,url):
self.baseurl=url
self.streamNumber=None ## None will default to best available ##
try:
self.obj=pafy.new(self.baseurl)
except:
print("Error getting downloadable urls.Check your url and internet connection")
exit(1)
self.title=self.obj.title+"."+self.obj.getbest().extension
print(self.title)
def __str__(self):
print(self.obj)
def printStreams(self):
for i in range(len(self.obj.allstreams)):
print("%d "%(i)+str(self.obj.allstreams[i]))
def setStream(self,streamNumber):
self.streamNumber=streamNumber
def download(self,music=False):
if self.streamNumber:
downurl=self.obj.allstreams[self.streamNumber].url
else:
downstream=self.obj.getbest()
if music:
downstream=self.obj.getbestaudio()
download=downloadUrl(downstream.url,downstream.title+"."+downstream.extension)
else:
download=downloadUrl(downstream.url,downstream.title+"."+downstream.extension)
download.sendHead()
download.setDefaultFraglist()
download.downloadAllFrags()