Nick Ficano
commited on
Commit
·
a1c74e0
1
Parent(s):
d5e6100
replaced properties w/ methods, set url in init
Browse files* switched references to self.video to get_videos().
* added add_video method.
- pytube/api.py +31 -8
pytube/api.py
CHANGED
@@ -55,11 +55,14 @@ YT_ENCODING_KEYS = (
|
|
55 |
|
56 |
|
57 |
class YouTube(object):
|
58 |
-
def __init__(self):
|
59 |
self._filename = None
|
60 |
self._fmt_values = []
|
61 |
self._video_url = None
|
62 |
self._js_code = False
|
|
|
|
|
|
|
63 |
|
64 |
@property
|
65 |
def url(self):
|
@@ -113,9 +116,8 @@ class YouTube(object):
|
|
113 |
if "signature=" not in url:
|
114 |
signature = self._get_cipher(stream_map["s"][i], js_url)
|
115 |
url = "{}&signature={}".format(url, signature)
|
116 |
-
self.
|
117 |
self._fmt_values.append(fmt)
|
118 |
-
self.videos.sort()
|
119 |
|
120 |
@property
|
121 |
def filename(self):
|
@@ -144,8 +146,8 @@ class YouTube(object):
|
|
144 |
The filename of the video.
|
145 |
"""
|
146 |
self._filename = filename
|
147 |
-
if self.
|
148 |
-
for video in self.
|
149 |
video.filename = filename
|
150 |
|
151 |
@property
|
@@ -157,6 +159,28 @@ class YouTube(object):
|
|
157 |
video_id = parse_qs(qs).get('v')
|
158 |
if video_id:
|
159 |
return video_id.pop()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
160 |
|
161 |
def get(self, extension=None, resolution=None, profile=None):
|
162 |
"""Return a single video given a file extention and/or resolution
|
@@ -170,7 +194,7 @@ class YouTube(object):
|
|
170 |
The desired quality profile.
|
171 |
"""
|
172 |
result = []
|
173 |
-
for v in self.
|
174 |
if extension and v.extension != extension:
|
175 |
continue
|
176 |
elif resolution and v.resolution != resolution:
|
@@ -200,7 +224,7 @@ class YouTube(object):
|
|
200 |
The desired quality profile.
|
201 |
"""
|
202 |
results = []
|
203 |
-
for v in self.
|
204 |
if extension and v.extension != extension:
|
205 |
continue
|
206 |
elif resolution and v.resolution != resolution:
|
@@ -243,7 +267,6 @@ class YouTube(object):
|
|
243 |
def get_video_data(self):
|
244 |
"""Fetch the page and extract out the video data."""
|
245 |
self.title = None
|
246 |
-
self.videos = []
|
247 |
|
248 |
response = urlopen(self.url)
|
249 |
|
|
|
55 |
|
56 |
|
57 |
class YouTube(object):
|
58 |
+
def __init__(self, url=None):
|
59 |
self._filename = None
|
60 |
self._fmt_values = []
|
61 |
self._video_url = None
|
62 |
self._js_code = False
|
63 |
+
self._videos = []
|
64 |
+
if url:
|
65 |
+
self.from_url(url)
|
66 |
|
67 |
@property
|
68 |
def url(self):
|
|
|
116 |
if "signature=" not in url:
|
117 |
signature = self._get_cipher(stream_map["s"][i], js_url)
|
118 |
url = "{}&signature={}".format(url, signature)
|
119 |
+
self.add_video(url, self.filename, **fmt_data)
|
120 |
self._fmt_values.append(fmt)
|
|
|
121 |
|
122 |
@property
|
123 |
def filename(self):
|
|
|
146 |
The filename of the video.
|
147 |
"""
|
148 |
self._filename = filename
|
149 |
+
if self.get_videos():
|
150 |
+
for video in self.get_videos():
|
151 |
video.filename = filename
|
152 |
|
153 |
@property
|
|
|
159 |
video_id = parse_qs(qs).get('v')
|
160 |
if video_id:
|
161 |
return video_id.pop()
|
162 |
+
return False
|
163 |
+
|
164 |
+
def get_videos(self):
|
165 |
+
"""Returns all videos.
|
166 |
+
"""
|
167 |
+
return self._videos
|
168 |
+
|
169 |
+
def add_video(self, url, filename, **kwargs):
|
170 |
+
"""Adds new video object to videos.
|
171 |
+
"""
|
172 |
+
video = Video(url, filename, **kwargs)
|
173 |
+
self._videos.append(video)
|
174 |
+
self._videos.sort()
|
175 |
+
return True
|
176 |
+
|
177 |
+
@property
|
178 |
+
def videos(self):
|
179 |
+
"""Returns all videos
|
180 |
+
"""
|
181 |
+
warnings.warn("videos property deprecated, use `get_videos()` "
|
182 |
+
"instead.", DeprecationWarning)
|
183 |
+
return self._videos
|
184 |
|
185 |
def get(self, extension=None, resolution=None, profile=None):
|
186 |
"""Return a single video given a file extention and/or resolution
|
|
|
194 |
The desired quality profile.
|
195 |
"""
|
196 |
result = []
|
197 |
+
for v in self.get_videos():
|
198 |
if extension and v.extension != extension:
|
199 |
continue
|
200 |
elif resolution and v.resolution != resolution:
|
|
|
224 |
The desired quality profile.
|
225 |
"""
|
226 |
results = []
|
227 |
+
for v in self.get_videos():
|
228 |
if extension and v.extension != extension:
|
229 |
continue
|
230 |
elif resolution and v.resolution != resolution:
|
|
|
267 |
def get_video_data(self):
|
268 |
"""Fetch the page and extract out the video data."""
|
269 |
self.title = None
|
|
|
270 |
|
271 |
response = urlopen(self.url)
|
272 |
|