add comment
This commit is contained in:
@@ -3,32 +3,60 @@ import subprocess
|
|||||||
|
|
||||||
|
|
||||||
class MediaPlayerController:
|
class MediaPlayerController:
|
||||||
|
"""
|
||||||
|
Модуль для манипуляции музыкой
|
||||||
|
"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.os_type = platform.system()
|
self.os_type = platform.system()
|
||||||
|
|
||||||
def play_pause(self):
|
def play_pause(self) -> None:
|
||||||
|
"""
|
||||||
|
Запуск/остановка музыки
|
||||||
|
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
if self.os_type == 'Windows':
|
if self.os_type == 'Windows':
|
||||||
self._windows_play_pause()
|
self._windows_play_pause()
|
||||||
elif self.os_type == 'Linux':
|
elif self.os_type == 'Linux':
|
||||||
self._linux_control("play-pause")
|
self._linux_control("play-pause")
|
||||||
|
|
||||||
def next_track(self):
|
def next_track(self) -> None:
|
||||||
|
"""
|
||||||
|
Включает следующею композицию
|
||||||
|
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
if self.os_type == 'Windows':
|
if self.os_type == 'Windows':
|
||||||
self._windows_control("next")
|
self._windows_control("next")
|
||||||
elif self.os_type == 'Linux':
|
elif self.os_type == 'Linux':
|
||||||
self._linux_control("next")
|
self._linux_control("next")
|
||||||
|
|
||||||
def previous_track(self):
|
def previous_track(self) -> None:
|
||||||
|
"""
|
||||||
|
Включает предыдущею композицию
|
||||||
|
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
if self.os_type == 'Windows':
|
if self.os_type == 'Windows':
|
||||||
self._windows_control("previous")
|
self._windows_control("previous")
|
||||||
elif self.os_type == 'Linux':
|
elif self.os_type == 'Linux':
|
||||||
self._linux_control("previous")
|
self._linux_control("previous")
|
||||||
|
|
||||||
def _windows_play_pause(self):
|
def _windows_play_pause(self) -> None:
|
||||||
|
"""
|
||||||
|
Запуск/остановка музыки в windows
|
||||||
|
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
import win32con
|
import win32con
|
||||||
self.key_press(win32con.VK_MEDIA_PLAY_PAUSE)
|
self.key_press(win32con.VK_MEDIA_PLAY_PAUSE)
|
||||||
|
|
||||||
def _windows_control(self, action):
|
def _windows_control(self, action: str) -> None:
|
||||||
|
"""
|
||||||
|
Включает предыдущею или следующею композицию в windows
|
||||||
|
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
import win32con
|
import win32con
|
||||||
if action == "next":
|
if action == "next":
|
||||||
self.key_press(win32con.VK_MEDIA_NEXT_TRACK)
|
self.key_press(win32con.VK_MEDIA_NEXT_TRACK)
|
||||||
@@ -36,15 +64,26 @@ class MediaPlayerController:
|
|||||||
self.key_press(win32con.VK_MEDIA_PREV_TRACK)
|
self.key_press(win32con.VK_MEDIA_PREV_TRACK)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def key_press(key_code):
|
def key_press(key_code: str) -> None:
|
||||||
"""Симуляция нажатия и отпускания клавиши."""
|
"""
|
||||||
|
Симуляция нажатия и отпускания клавиши
|
||||||
|
|
||||||
|
:param key_code: str - какую кнопку нажать
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
import win32api
|
import win32api
|
||||||
import win32con
|
import win32con
|
||||||
win32api.keybd_event(key_code, 0, 0, 0)
|
win32api.keybd_event(key_code, 0, 0, 0)
|
||||||
win32api.keybd_event(key_code, 0, win32con.KEYEVENTF_KEYUP, 0)
|
win32api.keybd_event(key_code, 0, win32con.KEYEVENTF_KEYUP, 0)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _linux_control(command):
|
def _linux_control(command: str) -> None:
|
||||||
|
"""
|
||||||
|
Запускает команду для linux систем
|
||||||
|
|
||||||
|
:param command: str - команда для запуска
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
subprocess.run(["playerctl", command], check=True)
|
subprocess.run(["playerctl", command], check=True)
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user