hbmartin commited on
Commit
c3ecb1d
·
1 Parent(s): 896eab0

make length and views properties int

Browse files
Files changed (2) hide show
  1. pytube/__main__.py +5 -5
  2. tests/test_streams.py +49 -0
pytube/__main__.py CHANGED
@@ -310,26 +310,26 @@ 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(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) -> int:
327
  """Get the number of the times the video has been viewed.
328
 
329
  :rtype: str
330
 
331
  """
332
+ return int(
333
  self.player_config_args.get("player_response", {})
334
  .get("videoDetails", {})
335
  .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"}