hbmartin commited on
Commit
c4dc4b2
·
1 Parent(s): 00b0902

reformatting

Browse files
pytube/extract.py CHANGED
@@ -101,9 +101,7 @@ def video_info_url(
101
  # Here we use ``OrderedDict`` so that the output is consistent between
102
  # Python 2.7+.
103
  eurl = f"https://youtube.googleapis.com/v/{video_id}"
104
- params = OrderedDict(
105
- [("video_id", video_id), ("eurl", eurl), ("sts", sts),]
106
- )
107
  else:
108
  params = OrderedDict(
109
  [
 
101
  # Here we use ``OrderedDict`` so that the output is consistent between
102
  # Python 2.7+.
103
  eurl = f"https://youtube.googleapis.com/v/{video_id}"
104
+ params = OrderedDict([("video_id", video_id), ("eurl", eurl), ("sts", sts),])
 
 
105
  else:
106
  params = OrderedDict(
107
  [
pytube/monostate.py CHANGED
@@ -52,7 +52,11 @@ class OnComplete(Protocol):
52
 
53
  class Monostate:
54
  def __init__(
55
- self, on_progress: Optional[OnProgress], on_complete: Optional[OnComplete], title: Optional[str]=None, duration: Optional[int] = None
 
 
 
 
56
  ):
57
  self.on_progress = on_progress
58
  self.on_complete = on_complete
 
52
 
53
  class Monostate:
54
  def __init__(
55
+ self,
56
+ on_progress: Optional[OnProgress],
57
+ on_complete: Optional[OnComplete],
58
+ title: Optional[str] = None,
59
+ duration: Optional[int] = None,
60
  ):
61
  self.on_progress = on_progress
62
  self.on_complete = on_complete
pytube/streams.py CHANGED
@@ -155,7 +155,7 @@ class Stream:
155
  :returns:
156
  Youtube video title
157
  """
158
- return self._monostate.title
159
 
160
  @property
161
  def filesize_approx(self) -> int:
@@ -164,8 +164,9 @@ class Stream:
164
  :rtype: int
165
  :returns: size of video in bytes
166
  """
 
167
  bits_in_byte = 8
168
- return (self._monostate.duration * self.bitrate) / bits_in_byte
169
 
170
  @property
171
  def default_filename(self) -> str:
 
155
  :returns:
156
  Youtube video title
157
  """
158
+ return self._monostate.title or "Unknown YouTube Video Title"
159
 
160
  @property
161
  def filesize_approx(self) -> int:
 
164
  :rtype: int
165
  :returns: size of video in bytes
166
  """
167
+ assert self._monostate.duration is not None
168
  bits_in_byte = 8
169
+ return int((self._monostate.duration * self.bitrate) / bits_in_byte)
170
 
171
  @property
172
  def default_filename(self) -> str:
tests/test_extract.py CHANGED
@@ -12,12 +12,6 @@ def test_extract_video_id():
12
  assert video_id == "9bZkp7q19f0"
13
 
14
 
15
- def test_extract_watch_url():
16
- video_id = "9bZkp7q19f0"
17
- watch_url = extract.watch_url(video_id)
18
- assert watch_url == "https://youtube.com/watch?v=9bZkp7q19f0"
19
-
20
-
21
  def test_info_url(cipher_signature):
22
  video_info_url = extract.video_info_url(
23
  video_id=cipher_signature.video_id,
@@ -66,11 +60,6 @@ def test_get_vid_desc(cipher_signature):
66
  assert extract.get_vid_descr(cipher_signature.watch_html) == expected
67
 
68
 
69
- def test_eurl():
70
- url = extract.eurl("videoid")
71
- assert url == "https://youtube.googleapis.com/v/videoid"
72
-
73
-
74
  def test_mime_type_codec():
75
  mime_type, mime_subtype = extract.mime_type_codec('audio/webm; codecs="opus"')
76
  assert mime_type == "audio/webm"
 
12
  assert video_id == "9bZkp7q19f0"
13
 
14
 
 
 
 
 
 
 
15
  def test_info_url(cipher_signature):
16
  video_info_url = extract.video_info_url(
17
  video_id=cipher_signature.video_id,
 
60
  assert extract.get_vid_descr(cipher_signature.watch_html) == expected
61
 
62
 
 
 
 
 
 
63
  def test_mime_type_codec():
64
  mime_type, mime_subtype = extract.mime_type_codec('audio/webm; codecs="opus"')
65
  assert mime_type == "audio/webm"
tests/test_streams.py CHANGED
@@ -21,19 +21,14 @@ def test_default_filename(cipher_signature):
21
 
22
 
23
  def test_title(cipher_signature):
24
- expected = "PSY - GANGNAM STYLE(강남스타일) M/V"
25
- stream = cipher_signature.streams.first()
26
- assert stream.title == expected
27
-
28
- expected = "PSY - GANGNAM STYLE(강남스타일)"
29
- stream.player_config_args = {
30
- "player_response": {"videoDetails": {"title": expected}},
31
- }
32
- assert stream.title == expected
33
-
34
- expected = "Unknown YouTube Video Title"
35
- stream.player_config_args = {}
36
- assert stream.title == expected
37
 
38
 
39
  def test_caption_tracks(presigned_video):
 
21
 
22
 
23
  def test_title(cipher_signature):
24
+ expected = "title"
25
+ cipher_signature.player_config_args["title"] = expected
26
+ assert cipher_signature.title == expected
27
+
28
+ expected = "title2"
29
+ del cipher_signature.player_config_args["title"]
30
+ cipher_signature.player_response = {"videoDetails": {"title": expected}}
31
+ assert cipher_signature.title == expected
 
 
 
 
 
32
 
33
 
34
  def test_caption_tracks(presigned_video):