hbmartin commited on
Commit
45402b8
·
1 Parent(s): 7d3bb49

handle missing bitrate

Browse files
pytube/__main__.py CHANGED
@@ -276,7 +276,7 @@ class YouTube:
276
  """
277
  return self.player_response.get("videoDetails", {}).get(
278
  "shortDescription"
279
- ) or extract.get_vid_descr(self.watch_html)
280
 
281
  @property
282
  def rating(self) -> float:
 
276
  """
277
  return self.player_response.get("videoDetails", {}).get(
278
  "shortDescription"
279
+ ) or extract._get_vid_descr(self.watch_html)
280
 
281
  @property
282
  def rating(self) -> float:
pytube/extract.py CHANGED
@@ -182,7 +182,7 @@ def get_ytplayer_config(html: str, age_restricted: bool = False) -> Any:
182
  return json.loads(yt_player_config)
183
 
184
 
185
- def get_vid_descr(html: Optional[str]) -> str:
186
  html_parser = PytubeHTMLParser()
187
  if html:
188
  html_parser.feed(html)
 
182
  return json.loads(yt_player_config)
183
 
184
 
185
+ def _get_vid_descr(html: Optional[str]) -> str:
186
  html_parser = PytubeHTMLParser()
187
  if html:
188
  html_parser.feed(html)
pytube/query.py CHANGED
@@ -172,8 +172,8 @@ class StreamQuery:
172
 
173
  def _filter(self, filters: List[Callable]) -> "StreamQuery":
174
  fmt_streams = self.fmt_streams
175
- for fn in filters:
176
- fmt_streams = filter(fn, fmt_streams)
177
  print(fmt_streams)
178
  return StreamQuery(list(fmt_streams))
179
 
 
172
 
173
  def _filter(self, filters: List[Callable]) -> "StreamQuery":
174
  fmt_streams = self.fmt_streams
175
+ for filter_lambda in filters:
176
+ fmt_streams = filter(filter_lambda, fmt_streams)
177
  print(fmt_streams)
178
  return StreamQuery(list(fmt_streams))
179
 
pytube/streams.py CHANGED
@@ -59,7 +59,7 @@ class Stream:
59
  self.video_codec, self.audio_codec = self.parse_codecs()
60
 
61
  self.is_otf: bool = stream["is_otf"]
62
- self.bitrate: int = stream["bitrate"]
63
 
64
  self._filesize: Optional[int] = None # filesize in bytes
65
 
@@ -159,16 +159,18 @@ class Stream:
159
 
160
  @property
161
  def filesize_approx(self) -> int:
162
- """Get approximate filesize of the video, avoiding HTTP call
 
 
163
 
164
  :rtype: int
165
  :returns: size of video in bytes
166
  """
167
- if self._monostate.duration:
168
  bits_in_byte = 8
169
  return int((self._monostate.duration * self.bitrate) / bits_in_byte)
170
- else:
171
- return self.filesize
172
 
173
  @property
174
  def default_filename(self) -> str:
 
59
  self.video_codec, self.audio_codec = self.parse_codecs()
60
 
61
  self.is_otf: bool = stream["is_otf"]
62
+ self.bitrate: Optional[int] = stream["bitrate"]
63
 
64
  self._filesize: Optional[int] = None # filesize in bytes
65
 
 
159
 
160
  @property
161
  def filesize_approx(self) -> int:
162
+ """Get approximate filesize of the video
163
+
164
+ Falls back to HTTP call if there is not sufficient information to approximate
165
 
166
  :rtype: int
167
  :returns: size of video in bytes
168
  """
169
+ if self._monostate.duration and self.bitrate:
170
  bits_in_byte = 8
171
  return int((self._monostate.duration * self.bitrate) / bits_in_byte)
172
+
173
+ return self.filesize
174
 
175
  @property
176
  def default_filename(self) -> str:
tests/test_extract.py CHANGED
@@ -57,7 +57,7 @@ def test_get_vid_desc(cipher_signature):
57
  "http://sptfy.com/PSY\n"
58
  "http://weibo.com/psyoppa"
59
  )
60
- assert extract.get_vid_descr(cipher_signature.watch_html) == expected
61
 
62
 
63
  def test_mime_type_codec():
 
57
  "http://sptfy.com/PSY\n"
58
  "http://weibo.com/psyoppa"
59
  )
60
+ assert extract._get_vid_descr(cipher_signature.watch_html) == expected
61
 
62
 
63
  def test_mime_type_codec():