tenyearscoder
commited on
Commit
·
dab9a64
1
Parent(s):
aac8ac9
get the name of the playlist
Browse files- pytube/contrib/playlist.py +14 -0
- tests/contrib/test_playlist.py +6 -0
pytube/contrib/playlist.py
CHANGED
@@ -173,3 +173,17 @@ class Playlist(object):
|
|
173 |
else:
|
174 |
dl_stream.download(download_path)
|
175 |
logger.debug('download complete')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
173 |
else:
|
174 |
dl_stream.download(download_path)
|
175 |
logger.debug('download complete')
|
176 |
+
|
177 |
+
def title(self):
|
178 |
+
"""return playlist title (name)
|
179 |
+
"""
|
180 |
+
try:
|
181 |
+
url = self.construct_playlist_url()
|
182 |
+
req = request.get(url)
|
183 |
+
open_tag = "<title>"
|
184 |
+
end_tag = "</title>"
|
185 |
+
matchresult = re.compile(open_tag + "(.+?)" + end_tag).search(req).group().replace(open_tag,"").replace(end_tag,"").replace("- YouTube","").strip()
|
186 |
+
return matchresult
|
187 |
+
except Exception as e:
|
188 |
+
logger.debug(e)
|
189 |
+
return None
|
tests/contrib/test_playlist.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pytube import YouTube, Playlist
|
2 |
+
|
3 |
+
def test_title():
|
4 |
+
pl = Playlist("https://www.youtube.com/watch?v=QXeEoD0pB3E&list=PLsyeobzWxl7poL9JTVyndKe62ieoN-MZ3")
|
5 |
+
pl_title = pl.title()
|
6 |
+
assert pl_title == "Python Tutorial for Beginners"
|