hbmartin commited on
Commit
b2aa04f
·
1 Parent(s): 4c59ac5

add author property (thanks DmitryBurnaev)

Browse files
Files changed (2) hide show
  1. pytube/__main__.py +11 -0
  2. tests/test_streams.py +12 -0
pytube/__main__.py CHANGED
@@ -319,6 +319,17 @@ class YouTube(object):
319
  .get("viewCount")
320
  )
321
 
 
 
 
 
 
 
 
 
 
 
 
322
  def register_on_progress_callback(self, func):
323
  """Register a download progress callback function post initialization.
324
 
 
319
  .get("viewCount")
320
  )
321
 
322
+ @property
323
+ def author(self) -> str:
324
+ """Get the video author.
325
+ :rtype: str
326
+ """
327
+ return (
328
+ self.player_config_args.get("player_response", {})
329
+ .get("videoDetails", {})
330
+ .get("author", "unknown")
331
+ )
332
+
333
  def register_on_progress_callback(self, func):
334
  """Register a download progress callback function post initialization.
335
 
tests/test_streams.py CHANGED
@@ -95,6 +95,18 @@ def test_on_complete_hook(cipher_signature, mocker):
95
  assert callback_fn.called
96
 
97
 
 
 
 
 
 
 
 
 
 
 
 
 
98
  @pytest.mark.skip
99
  def test_repr_for_audio_streams(cipher_signature):
100
  stream = str(cipher_signature.streams.filter(only_audio=True).first())
 
95
  assert callback_fn.called
96
 
97
 
98
+ def test_author(cipher_signature):
99
+ expected = "Test author"
100
+ cipher_signature.player_config_args = {
101
+ "player_response": {"videoDetails": {"author": expected}}
102
+ }
103
+ assert cipher_signature.author == expected
104
+
105
+ expected = "unknown"
106
+ cipher_signature.player_config_args = {}
107
+ assert cipher_signature.author == expected
108
+
109
+
110
  @pytest.mark.skip
111
  def test_repr_for_audio_streams(cipher_signature):
112
  stream = str(cipher_signature.streams.filter(only_audio=True).first())