hbmartin commited on
Commit
3584e5b
·
1 Parent(s): c7b0cc4

on_complete handler take a file_path string instead of IO object

Browse files
Files changed (3) hide show
  1. pytube/extract.py +2 -2
  2. pytube/monostate.py +3 -4
  3. pytube/streams.py +6 -7
pytube/extract.py CHANGED
@@ -228,8 +228,8 @@ def apply_signature(config_args: Dict, fmt: str, js: str) -> None:
228
  except KeyError:
229
  live_stream = (
230
  json.loads(config_args["player_response"])
231
- .get("playabilityStatus", {}, )
232
- .get("liveStreamability")
233
  )
234
  if live_stream:
235
  raise LiveStreamError("UNKNOWN")
 
228
  except KeyError:
229
  live_stream = (
230
  json.loads(config_args["player_response"])
231
+ .get("playabilityStatus", {},)
232
+ .get("liveStreamability")
233
  )
234
  if live_stream:
235
  raise LiveStreamError("UNKNOWN")
pytube/monostate.py CHANGED
@@ -33,17 +33,16 @@ class OnProgress(Protocol):
33
 
34
 
35
  class OnComplete(Protocol):
36
- def __call__(self, stream: Any, file_handler: io.BufferedWriter) -> None:
37
  """On download complete handler function.
38
 
39
  :param stream:
40
  An instance of :class:`Stream <Stream>` being downloaded.
41
  :type stream:
42
  :py:class:`pytube.Stream`
43
- :param file_handler:
44
  The file handle where the media is being written to.
45
- :type file_handler:
46
- :py:class:`io.BufferedWriter`
47
 
48
  :rtype: None
49
  """
 
33
 
34
 
35
  class OnComplete(Protocol):
36
+ def __call__(self, stream: Any, file_path: Optional[str]) -> None:
37
  """On download complete handler function.
38
 
39
  :param stream:
40
  An instance of :class:`Stream <Stream>` being downloaded.
41
  :type stream:
42
  :py:class:`pytube.Stream`
43
+ :param file_path:
44
  The file handle where the media is being written to.
45
+ :type file_path: str
 
46
 
47
  :rtype: None
48
  """
pytube/streams.py CHANGED
@@ -245,7 +245,7 @@ class Stream:
245
  bytes_remaining -= len(chunk)
246
  # send to the on_progress callback.
247
  self.on_progress(chunk, fh, bytes_remaining)
248
- self.on_complete(fh)
249
  return file_path
250
 
251
  def stream_to_buffer(self) -> io.BytesIO:
@@ -264,7 +264,7 @@ class Stream:
264
  bytes_remaining -= len(chunk)
265
  # send to the on_progress callback.
266
  self.on_progress(chunk, buffer, bytes_remaining)
267
- self.on_complete(buffer)
268
  return buffer
269
 
270
  def on_progress(self, chunk, file_handler, bytes_remaining):
@@ -300,13 +300,12 @@ class Stream:
300
  logger.debug("calling on_progress callback %s", on_progress)
301
  on_progress(self, chunk, file_handler, bytes_remaining)
302
 
303
- def on_complete(self, file_handle):
304
  """On download complete handler function.
305
 
306
- :param file_handle:
307
  The file handle where the media is being written to.
308
- :type file_handle:
309
- :py:class:`io.BufferedWriter`
310
 
311
  :rtype: None
312
 
@@ -315,7 +314,7 @@ class Stream:
315
  on_complete = self._monostate.on_complete
316
  if on_complete:
317
  logger.debug("calling on_complete callback %s", on_complete)
318
- on_complete(self, file_handle)
319
 
320
  def __repr__(self) -> str:
321
  """Printable object representation.
 
245
  bytes_remaining -= len(chunk)
246
  # send to the on_progress callback.
247
  self.on_progress(chunk, fh, bytes_remaining)
248
+ self.on_complete(file_path)
249
  return file_path
250
 
251
  def stream_to_buffer(self) -> io.BytesIO:
 
264
  bytes_remaining -= len(chunk)
265
  # send to the on_progress callback.
266
  self.on_progress(chunk, buffer, bytes_remaining)
267
+ self.on_complete(None)
268
  return buffer
269
 
270
  def on_progress(self, chunk, file_handler, bytes_remaining):
 
300
  logger.debug("calling on_progress callback %s", on_progress)
301
  on_progress(self, chunk, file_handler, bytes_remaining)
302
 
303
+ def on_complete(self, file_path: Optional[str]):
304
  """On download complete handler function.
305
 
306
+ :param file_path:
307
  The file handle where the media is being written to.
308
+ :type file_handle: str
 
309
 
310
  :rtype: None
311
 
 
314
  on_complete = self._monostate.on_complete
315
  if on_complete:
316
  logger.debug("calling on_complete callback %s", on_complete)
317
+ on_complete(self, file_path)
318
 
319
  def __repr__(self) -> str:
320
  """Printable object representation.