hbmartin commited on
Commit
a138039
·
1 Parent(s): 418ce93

better fallbacks for title and description

Browse files
Files changed (2) hide show
  1. pytube/__main__.py +11 -3
  2. pytube/streams.py +4 -12
pytube/__main__.py CHANGED
@@ -275,7 +275,11 @@ class YouTube(object):
275
  :rtype: str
276
 
277
  """
278
- return self.player_config_args["title"]
 
 
 
 
279
 
280
  @property
281
  def description(self) -> str:
@@ -284,7 +288,11 @@ class YouTube(object):
284
  :rtype: str
285
 
286
  """
287
- return self.vid_descr
 
 
 
 
288
 
289
  @property
290
  def rating(self) -> float:
@@ -306,7 +314,7 @@ class YouTube(object):
306
  :rtype: str
307
 
308
  """
309
- return (
310
  self.player_config_args.get("player_response", {})
311
  .get("videoDetails", {})
312
  .get("lengthSeconds")
 
275
  :rtype: str
276
 
277
  """
278
+ return self.player_config_args.get("title") or (
279
+ self.player_config_args.get("player_response", {})
280
+ .get("videoDetails", {})
281
+ .get("title")
282
+ )
283
 
284
  @property
285
  def description(self) -> str:
 
288
  :rtype: str
289
 
290
  """
291
+ return self.vid_descr or (
292
+ self.player_config_args.get("player_response", {})
293
+ .get("videoDetails", {})
294
+ .get("shortDescription")
295
+ )
296
 
297
  @property
298
  def rating(self) -> float:
 
314
  :rtype: str
315
 
316
  """
317
+ return self.player_config_args.get("length_seconds") or (
318
  self.player_config_args.get("player_response", {})
319
  .get("videoDetails", {})
320
  .get("lengthSeconds")
pytube/streams.py CHANGED
@@ -176,20 +176,12 @@ class Stream(object):
176
  :returns:
177
  Youtube video title
178
  """
179
- player_config_args = self.player_config_args or {}
180
-
181
- if "title" in player_config_args:
182
- return player_config_args["title"]
183
-
184
- details = self.player_config_args.get("player_response", {},).get(
185
- "videoDetails", {}
186
  )
187
 
188
- if "title" in details:
189
- return details["title"]
190
-
191
- return "Unknown YouTube Video Title"
192
-
193
  @property
194
  def default_filename(self) -> str:
195
  """Generate filename based on the video title.
 
176
  :returns:
177
  Youtube video title
178
  """
179
+ return self.player_config_args.get("title") or (
180
+ self.player_config_args.get("player_response", {})
181
+ .get("videoDetails", {})
182
+ .get("title")
 
 
 
183
  )
184
 
 
 
 
 
 
185
  @property
186
  def default_filename(self) -> str:
187
  """Generate filename based on the video title.