hbmartin commited on
Commit
fd8b589
·
unverified ·
2 Parent(s): adc8649 9cbeeca

Merge pull request #39 from hbmartin/yt-prop-tests

Browse files
Files changed (2) hide show
  1. pytube/__main__.py +10 -7
  2. tests/test_streams.py +49 -0
pytube/__main__.py CHANGED
@@ -310,26 +310,29 @@ class YouTube:
310
  )
311
 
312
  @property
313
- def length(self) -> str:
314
  """Get the video length in seconds.
315
 
316
  :rtype: str
317
 
318
  """
319
- return self.player_config_args.get("length_seconds") or (
320
- self.player_config_args.get("player_response", {})
321
- .get("videoDetails", {})
322
- .get("lengthSeconds")
 
 
 
323
  )
324
 
325
  @property
326
- def views(self) -> str:
327
  """Get the number of the times the video has been viewed.
328
 
329
  :rtype: str
330
 
331
  """
332
- return (
333
  self.player_config_args.get("player_response", {})
334
  .get("videoDetails", {})
335
  .get("viewCount")
 
310
  )
311
 
312
  @property
313
+ def length(self) -> int:
314
  """Get the video length in seconds.
315
 
316
  :rtype: str
317
 
318
  """
319
+ return int(
320
+ self.player_config_args.get("length_seconds")
321
+ or (
322
+ self.player_config_args.get("player_response", {})
323
+ .get("videoDetails", {})
324
+ .get("lengthSeconds")
325
+ )
326
  )
327
 
328
  @property
329
+ def views(self) -> int:
330
  """Get the number of the times the video has been viewed.
331
 
332
  :rtype: str
333
 
334
  """
335
+ return int(
336
  self.player_config_args.get("player_response", {})
337
  .get("videoDetails", {})
338
  .get("viewCount")
tests/test_streams.py CHANGED
@@ -37,6 +37,55 @@ def test_title(cipher_signature):
37
  assert stream.title == expected
38
 
39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  def test_download(cipher_signature, mocker):
41
  mocker.patch.object(request, "headers")
42
  request.headers.return_value = {"content-length": "16384"}
 
37
  assert stream.title == expected
38
 
39
 
40
+ def test_description(cipher_signature):
41
+ expected = (
42
+ "PSY - ‘I LUV IT’ M/V @ https://youtu.be/Xvjnoagk6GU\n"
43
+ "PSY - ‘New Face’ M/V @https://youtu.be/OwJPPaEyqhI\n"
44
+ "PSY - 8TH ALBUM '4X2=8' on iTunes @\n"
45
+ "https://smarturl.it/PSY_8thAlbum\n"
46
+ "PSY - GANGNAM STYLE(강남스타일) on iTunes @ http://smarturl.it/PsyGangnam\n"
47
+ "#PSY #싸이 #GANGNAMSTYLE #강남스타일\n"
48
+ "More about PSY@\nhttp://www.youtube.com/officialpsy\n"
49
+ "http://www.facebook.com/officialpsy\n"
50
+ "http://twitter.com/psy_oppa\n"
51
+ "https://www.instagram.com/42psy42\n"
52
+ "http://iTunes.com/PSY\n"
53
+ "http://sptfy.com/PSY\n"
54
+ "http://weibo.com/psyoppa"
55
+ )
56
+ assert cipher_signature.description == expected
57
+
58
+ cipher_signature.vid_descr = None
59
+ expected = (
60
+ "PSY - ‘I LUV IT’ M/V @ https://youtu.be/Xvjnoagk6GU\n"
61
+ "PSY - ‘New Face’ M/V @https://youtu.be/OwJPPaEyqhI\n\n"
62
+ "PSY - 8TH ALBUM '4X2=8' on iTunes @\n"
63
+ "https://smarturl.it/PSY_8thAlbum\n\n"
64
+ "PSY - GANGNAM STYLE(강남스타일) on iTunes @ http://smarturl.it/PsyGangnam\n\n"
65
+ "#PSY #싸이 #GANGNAMSTYLE #강남스타일\n\n"
66
+ "More about PSY@\nhttp://www.youtube.com/officialpsy\n"
67
+ "http://www.facebook.com/officialpsy\n"
68
+ "http://twitter.com/psy_oppa\n"
69
+ "https://www.instagram.com/42psy42\n"
70
+ "http://iTunes.com/PSY\n"
71
+ "http://sptfy.com/PSY\n"
72
+ "http://weibo.com/psyoppa"
73
+ )
74
+ assert cipher_signature.description == expected
75
+
76
+
77
+ def test_rating(cipher_signature):
78
+ assert cipher_signature.rating == 4.522203
79
+
80
+
81
+ def test_length(cipher_signature):
82
+ assert cipher_signature.length == 252
83
+
84
+
85
+ def test_views(cipher_signature):
86
+ assert cipher_signature.views == 3494704859
87
+
88
+
89
  def test_download(cipher_signature, mocker):
90
  mocker.patch.object(request, "headers")
91
  request.headers.return_value = {"content-length": "16384"}