tenyearscoder
commited on
Commit
·
5e51daa
1
Parent(s):
dab9a64
travisCI mod
Browse files
pytube/contrib/playlist.py
CHANGED
@@ -176,14 +176,20 @@ class Playlist(object):
|
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
|
186 |
return matchresult
|
187 |
except Exception as e:
|
188 |
logger.debug(e)
|
189 |
-
return None
|
|
|
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)
|
186 |
+
matchresult = matchresult.search(req).group()
|
187 |
+
matchresult = matchresult.replace(open_tag,"")
|
188 |
+
matchresult = matchresult.replace(end_tag,"")
|
189 |
+
matchresult = matchresult.replace("- YouTube","")
|
190 |
+
matchresult = matchresult.strip()
|
191 |
+
|
192 |
return matchresult
|
193 |
except Exception as e:
|
194 |
logger.debug(e)
|
195 |
+
return None
|
tests/contrib/__pycache__/tmpgekc8jvs
ADDED
Binary file (1.36 kB). View file
|
|
tests/contrib/test_playlist.py
CHANGED
@@ -1,6 +1,8 @@
|
|
1 |
-
from pytube import
|
|
|
2 |
|
3 |
def test_title():
|
4 |
-
|
5 |
-
|
6 |
-
|
|
|
|
1 |
+
from pytube import Playlist
|
2 |
+
|
3 |
|
4 |
def test_title():
|
5 |
+
url = "https://www.youtube.com/watch?v=QXeEoD0pB3E&list=PLsyeobzWxl7poL9JTVyndKe62ieoN-MZ3"
|
6 |
+
pl = Playlist(url)
|
7 |
+
pl_title = pl.title()
|
8 |
+
assert pl_title == "Python Tutorial for Beginners"
|