muteaimp 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- muteaimp-0.1.0/LICENSE +21 -0
- muteaimp-0.1.0/PKG-INFO +82 -0
- muteaimp-0.1.0/README.md +67 -0
- muteaimp-0.1.0/muteaimp/__init__.py +0 -0
- muteaimp-0.1.0/muteaimp/main.py +97 -0
- muteaimp-0.1.0/pyproject.toml +30 -0
- muteaimp-0.1.0/pyproject.toml.orig +30 -0
muteaimp-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Groot
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
muteaimp-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: muteaimp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Script to stop AIMP when other video or audio is playing
|
|
5
|
+
Author: Groot
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Dist: pyaimp>=0.2,<1
|
|
9
|
+
Requires-Dist: pycaw>=20260921
|
|
10
|
+
Requires-Python: >=3.9
|
|
11
|
+
Project-URL: Homepage, https://github.com/grootle/muteAIMP
|
|
12
|
+
Project-URL: Repository, https://github.com/grootle/muteAIMP
|
|
13
|
+
Project-URL: Issues, https://github.com/grootle/muteAIMP/issues
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
|
|
16
|
+
# AIMP Auto Pause/Resume
|
|
17
|
+
|
|
18
|
+
AIMP Auto Pause/Resume is a Python utility that automatically controls the playback of the AIMP music player based on the state of other audio sessions on your system. When any other application (e.g., a video player) is actively running the utility will pause AIMP. Once these sessions become inactive, AIMP will resume playing.
|
|
19
|
+
|
|
20
|
+
## Features
|
|
21
|
+
|
|
22
|
+
- **Automatic Detection:** Monitors system audio sessions using the [pycaw](https://github.com/AndreMiras/pycaw) library.
|
|
23
|
+
- **Seamless AIMP Control:** Automatically pauses AIMP when another application is active and resumes playback when all other sessions are inactive.
|
|
24
|
+
|
|
25
|
+
## Prerequisites
|
|
26
|
+
|
|
27
|
+
- **Python:** 3.6+
|
|
28
|
+
- **Required Python Packages:**
|
|
29
|
+
- [pyaimp](https://pypi.org/project/pyaimp/)
|
|
30
|
+
- [pycaw](https://github.com/AndreMiras/pycaw)
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
1. **Clone the Repository:**
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
git clone https://github.com/grootle/muteAIMP.git
|
|
38
|
+
cd muteAIMP
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
2. **Create a Virtual Environment (Optional):**
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
python -m venv venv
|
|
45
|
+
source venv/Scripts/activate # On Windows: venv\Scripts\activate
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
3. **Install Dependencies:**
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pip install -r requirements.txt
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
If you do not have a `requirements.txt`, you can install the packages individually:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
pip install pyaimp pycaw
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Usage
|
|
61
|
+
|
|
62
|
+
1. **Ensure AIMP is Installed:**
|
|
63
|
+
Make sure AIMP is installed on your system and that the executable name is `AIMP.exe`.
|
|
64
|
+
|
|
65
|
+
2. **Run the Script:**
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
python main.py
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
The script will register for audio session notifications on your system. It will monitor the audio sessions and automatically pause AIMP if any other session becomes active, resuming playback when they become inactive.
|
|
72
|
+
|
|
73
|
+
3. **Logging:**
|
|
74
|
+
The console output will display debugging messages, such as active session changes and AIMP control actions (pause/resume).
|
|
75
|
+
|
|
76
|
+
## Customization
|
|
77
|
+
|
|
78
|
+
- **AIMP Executable Name:**
|
|
79
|
+
If your AIMP executable has a different name, update the `AIMP_EXE` constant in `main.py`.
|
|
80
|
+
|
|
81
|
+
- **Polling Interval:**
|
|
82
|
+
The script uses an infinite loop with a 1-second delay to keep running. Adjust `time.sleep(1)` in the main loop if you need a different interval.
|
muteaimp-0.1.0/README.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# AIMP Auto Pause/Resume
|
|
2
|
+
|
|
3
|
+
AIMP Auto Pause/Resume is a Python utility that automatically controls the playback of the AIMP music player based on the state of other audio sessions on your system. When any other application (e.g., a video player) is actively running the utility will pause AIMP. Once these sessions become inactive, AIMP will resume playing.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Automatic Detection:** Monitors system audio sessions using the [pycaw](https://github.com/AndreMiras/pycaw) library.
|
|
8
|
+
- **Seamless AIMP Control:** Automatically pauses AIMP when another application is active and resumes playback when all other sessions are inactive.
|
|
9
|
+
|
|
10
|
+
## Prerequisites
|
|
11
|
+
|
|
12
|
+
- **Python:** 3.6+
|
|
13
|
+
- **Required Python Packages:**
|
|
14
|
+
- [pyaimp](https://pypi.org/project/pyaimp/)
|
|
15
|
+
- [pycaw](https://github.com/AndreMiras/pycaw)
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
1. **Clone the Repository:**
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
git clone https://github.com/grootle/muteAIMP.git
|
|
23
|
+
cd muteAIMP
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
2. **Create a Virtual Environment (Optional):**
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
python -m venv venv
|
|
30
|
+
source venv/Scripts/activate # On Windows: venv\Scripts\activate
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
3. **Install Dependencies:**
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pip install -r requirements.txt
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
If you do not have a `requirements.txt`, you can install the packages individually:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install pyaimp pycaw
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Usage
|
|
46
|
+
|
|
47
|
+
1. **Ensure AIMP is Installed:**
|
|
48
|
+
Make sure AIMP is installed on your system and that the executable name is `AIMP.exe`.
|
|
49
|
+
|
|
50
|
+
2. **Run the Script:**
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
python main.py
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
The script will register for audio session notifications on your system. It will monitor the audio sessions and automatically pause AIMP if any other session becomes active, resuming playback when they become inactive.
|
|
57
|
+
|
|
58
|
+
3. **Logging:**
|
|
59
|
+
The console output will display debugging messages, such as active session changes and AIMP control actions (pause/resume).
|
|
60
|
+
|
|
61
|
+
## Customization
|
|
62
|
+
|
|
63
|
+
- **AIMP Executable Name:**
|
|
64
|
+
If your AIMP executable has a different name, update the `AIMP_EXE` constant in `main.py`.
|
|
65
|
+
|
|
66
|
+
- **Polling Interval:**
|
|
67
|
+
The script uses an infinite loop with a 1-second delay to keep running. Adjust `time.sleep(1)` in the main loop if you need a different interval.
|
|
File without changes
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import time
|
|
2
|
+
from pyaimp import Client, PlayBackState
|
|
3
|
+
from pycaw.pycaw import AudioUtilities, IAudioMeterInformation
|
|
4
|
+
|
|
5
|
+
# Constant for the AIMP executable name
|
|
6
|
+
AIMP_EXE = 'AIMP.exe'
|
|
7
|
+
# Variable to keep track of the last command sent to avoid redundant actions
|
|
8
|
+
sent_command = 'play'
|
|
9
|
+
|
|
10
|
+
last_message = ''
|
|
11
|
+
PAUSE_MESSAGE = "AIMP paused due to active session."
|
|
12
|
+
RESUME_MESSAGE = "AIMP resumed as no active session found."
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def display_message(message):
|
|
16
|
+
global last_message
|
|
17
|
+
|
|
18
|
+
if last_message != message:
|
|
19
|
+
print(message)
|
|
20
|
+
last_message = message
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def is_peak_value_exist(session) -> bool:
|
|
24
|
+
"""Check if the audio session is producing any significant sound"""
|
|
25
|
+
|
|
26
|
+
# Query the IAudioMeterInformation interface for peak audio value
|
|
27
|
+
volume = session._ctl.QueryInterface(IAudioMeterInformation)
|
|
28
|
+
peak = volume.GetPeakValue()
|
|
29
|
+
|
|
30
|
+
# If the peak value is greater than the threshold, consider it as active
|
|
31
|
+
return peak > 0.00001
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def get_audio_sessions() -> list:
|
|
35
|
+
"""
|
|
36
|
+
Get a list of process names that are actively producing audio.
|
|
37
|
+
|
|
38
|
+
Returns:
|
|
39
|
+
List of process names with active audio output.
|
|
40
|
+
"""
|
|
41
|
+
sessions = AudioUtilities.GetAllSessions()
|
|
42
|
+
|
|
43
|
+
# Filter sessions to include only those with an associated process
|
|
44
|
+
active_sessions = [
|
|
45
|
+
session.Process.name() for session in sessions if session.Process and is_peak_value_exist(session) and session.Process.name() != AIMP_EXE
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
if active_sessions:
|
|
49
|
+
message = f"Active sessions: {' - '.join(active_sessions)}"
|
|
50
|
+
display_message(message)
|
|
51
|
+
|
|
52
|
+
return active_sessions
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def control_aimp():
|
|
56
|
+
"""
|
|
57
|
+
Control AIMP playback based on other active audio sessions.
|
|
58
|
+
|
|
59
|
+
If AIMP is playing and other processes are producing audio, pause AIMP.
|
|
60
|
+
If AIMP is paused (by this script) and no other audio is active, resume playback.
|
|
61
|
+
"""
|
|
62
|
+
global sent_command # Declare the global variable so we can modify it
|
|
63
|
+
|
|
64
|
+
active_sessions = get_audio_sessions()
|
|
65
|
+
|
|
66
|
+
try:
|
|
67
|
+
# Create a client instance for AIMP control
|
|
68
|
+
client = Client()
|
|
69
|
+
state = client.get_playback_state()
|
|
70
|
+
|
|
71
|
+
# If AIMP is playing and there are other active audio sessions, pause playback.
|
|
72
|
+
if state == PlayBackState.Playing and active_sessions:
|
|
73
|
+
client.pause()
|
|
74
|
+
sent_command = 'pause'
|
|
75
|
+
display_message(PAUSE_MESSAGE)
|
|
76
|
+
# If AIMP is not playing and it was paused by this script, resume playback when no other audio is active.
|
|
77
|
+
elif state != PlayBackState.Playing and sent_command == 'pause' and not active_sessions:
|
|
78
|
+
client.play()
|
|
79
|
+
sent_command = 'play'
|
|
80
|
+
display_message(RESUME_MESSAGE)
|
|
81
|
+
except RuntimeError:
|
|
82
|
+
# In case of errors with AIMP client operations, do nothing.
|
|
83
|
+
pass
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def main():
|
|
87
|
+
"""Main loop that continuously checks active audio sessions and controls AIMP playback"""
|
|
88
|
+
while True:
|
|
89
|
+
control_aimp()
|
|
90
|
+
# Delay between checks; lower this value for faster response at the expense of higher CPU usage.
|
|
91
|
+
time.sleep(1)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
if __name__ == "__main__":
|
|
95
|
+
main()
|
|
96
|
+
# This sleep is redundant because main() has an infinite loop, but kept for safety.
|
|
97
|
+
time.sleep(100)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "muteaimp"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Script to stop AIMP when other video or audio is playing"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
requires-python = ">=3.9"
|
|
9
|
+
dependencies = [
|
|
10
|
+
"pyaimp>=0.2,<1",
|
|
11
|
+
"pycaw>=20260921",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
[[project.authors]]
|
|
15
|
+
name = "Groot"
|
|
16
|
+
|
|
17
|
+
[project.urls]
|
|
18
|
+
Homepage = "https://github.com/grootle/muteAIMP"
|
|
19
|
+
Repository = "https://github.com/grootle/muteAIMP"
|
|
20
|
+
Issues = "https://github.com/grootle/muteAIMP/issues"
|
|
21
|
+
|
|
22
|
+
[project.scripts]
|
|
23
|
+
muteaimp = "muteaimp.main:main"
|
|
24
|
+
|
|
25
|
+
[build-system]
|
|
26
|
+
requires = ["uv_build>=0.12.9,<0.13.0"]
|
|
27
|
+
build-backend = "uv_build"
|
|
28
|
+
|
|
29
|
+
[tool.uv.build-backend]
|
|
30
|
+
module-root = ""
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "muteaimp"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Script to stop AIMP when other video or audio is playing"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
authors = [
|
|
9
|
+
{ name = "Groot" }
|
|
10
|
+
]
|
|
11
|
+
requires-python = ">=3.9"
|
|
12
|
+
dependencies = [
|
|
13
|
+
"pyaimp>=0.2,<1",
|
|
14
|
+
"pycaw>=20260921",
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
[project.urls]
|
|
18
|
+
Homepage = "https://github.com/grootle/muteAIMP"
|
|
19
|
+
Repository = "https://github.com/grootle/muteAIMP"
|
|
20
|
+
Issues = "https://github.com/grootle/muteAIMP/issues"
|
|
21
|
+
|
|
22
|
+
[project.scripts]
|
|
23
|
+
muteaimp = "muteaimp.main:main"
|
|
24
|
+
|
|
25
|
+
[build-system]
|
|
26
|
+
requires = ["uv_build>=0.12.9,<0.13.0"]
|
|
27
|
+
build-backend = "uv_build"
|
|
28
|
+
|
|
29
|
+
[tool.uv.build-backend]
|
|
30
|
+
module-root = ""
|