Skip to content

Commit

Permalink
raise warning instead of printing
Browse files Browse the repository at this point in the history
  • Loading branch information
shravanasati committed Oct 12, 2024
1 parent b32b66c commit fd3ed34
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 19 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,12 @@ Change Log
- Manually set FPS for the screen recording, by an extra `fps` argument in `start_recording` method.
- Introduced a one more exception class named `InvalidFPS`.
- Minor bug fixes.
--------------
--------------

0.4 (13/10/24)
--------------
- Remove the `HighFPSWarning` and `InvalidFPS` exception classes.
- Raise frame count by almost 2 times.
- Calling start and resume recording methods on an already running recorder instance raises a warning instead of printing, and vice versa.
- Temporary screenshots are now stored in `~/.pyscreenrec_data` folder.
--------------
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

*pyscreenrec* is a small and cross-platform python library for recording screen.

**NO LONGER MAINTAINED.**

[![Downloads](https://pepy.tech/badge/pyscreenrec)](https://pepy.tech/project/pyscreenrec)

Expand All @@ -25,7 +24,7 @@ Install on Linux/macOS:
>>> # to start recording
>>> recorder.start_recording("recording.mp4", 10)
>>> # 'recording.mp4' is the name of the output video file, may also contain full path like 'C:/Users/<user>/Videos/video.mp4'
>>> # the second parameter(10) is the FPS. You can specify the FPS for the screen recording using the second parameter. It must not be greater than 60.
>>> # the second parameter(10) is the FPS. You can specify the FPS for the screen recording using the second parameter.

>>> # to pause recording
>>> recorder.pause_recording()
Expand All @@ -40,11 +39,14 @@ Install on Linux/macOS:
The `stop_recording` saves the video and deletes all screenshots used in the session.
So calling the `stop_recording` method is necessary when `start_recording` is called.

If a screen recording session is already running, calling the `start_recording` and `resume_recording` methods raises a `ScreenRecodingInProgress` warning.

Similarly, if a screen recording session is not running, calling the `stop_recording` and `pause_recording` methods raises a `NoScreenRecodingInProgress` warning.

<br>

## Known limitations
*pyscreenrec* is yet not able to:
*pyscreenrec* is not able to:
- capture the system sound during screen recording
- capture only a certain part of the screen

Expand Down
38 changes: 23 additions & 15 deletions pyscreenrec/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,24 @@ class InvalidStartMode(Exception):
pass


class ScreenRecordingInProgress(Warning):
"""
This warning is raised when the `start_recording` or `resume_recording` methods
are called upon a `ScreenRecorder` instance which is already running.
"""

pass


class NoScreenRecordingInProgress(Warning):
"""
This warning is raised when the `stop_recording` or `pause_recording` methods
are called upon a `ScreenRecorder` instance which is not running.
"""

pass


class ScreenRecorder:
"""
Base class for screen recording.
Expand Down Expand Up @@ -57,9 +75,7 @@ def _start_recording(self, video_name: str, fps: int) -> None:

# checking if screen is already being recorded
if self.__running:
# todo decide the behavior on such cases
# whether an error/warning should be raised or ignored
print("Screen recording is already running.")
raise ScreenRecordingInProgress("Screen recording is already running.")

else:
if self.__start_mode == "start":
Expand Down Expand Up @@ -125,10 +141,8 @@ def stop_recording(self) -> None:
Stops screen recording.
"""
if not self.__running:
# todo decide the behavior on such cases
# whether an error/warning should be raised or ignored
print("No screen recording session is going on.")
return None
raise NoScreenRecordingInProgress("No screen recording session is going on.")

self.__running = False

# saving the video and clearing all screenshots
Expand All @@ -140,10 +154,7 @@ def pause_recording(self) -> None:
Pauses screen recording.
"""
if not self.__running:
# todo decide the behavior on such cases
# whether an error/warning should be raised or ignored
print("No screen recording session is going on.")
return None
raise NoScreenRecordingInProgress("No screen recording session is going on.")

self.__running = False

Expand All @@ -152,10 +163,7 @@ def resume_recording(self) -> None:
Resumes screen recording.
"""
if self.__running:
# todo decide the behavior on such cases
# whether an error/warning should be raised or ignored
print("Screen recording is already running.")
return None
raise ScreenRecordingInProgress("Screen recording is already running.")

self.__start_mode = "resume"
self.start_recording(self.video_name)
Expand Down

0 comments on commit fd3ed34

Please sign in to comment.