From fd3ed34634598a1e64b04be50addfed3afa615a4 Mon Sep 17 00:00:00 2001 From: Shravan Asati Date: Sat, 12 Oct 2024 22:22:36 +0530 Subject: [PATCH] raise warning instead of printing --- CHANGELOG | 10 +++++++++- README.md | 8 +++++--- pyscreenrec/__init__.py | 38 +++++++++++++++++++++++--------------- 3 files changed, 37 insertions(+), 19 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index d415950..1ca2024 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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. --------------- \ No newline at end of file +-------------- + +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. +-------------- diff --git a/README.md b/README.md index 44e944d..09d3a7d 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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//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() @@ -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.
## 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 diff --git a/pyscreenrec/__init__.py b/pyscreenrec/__init__.py index 1965770..af17b98 100644 --- a/pyscreenrec/__init__.py +++ b/pyscreenrec/__init__.py @@ -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. @@ -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": @@ -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 @@ -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 @@ -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)