mirror of
https://gitea.phreedom.club/localhost_frssoft/funkwlmpv
synced 2024-11-15 19:53:02 +00:00
34 lines
972 B
Python
34 lines
972 B
Python
|
import subprocess
|
||
|
import os
|
||
|
import json
|
||
|
import threading
|
||
|
from src.mpv_control import player
|
||
|
from loguru import logger
|
||
|
'''Warning! This module can be very battery drain'''
|
||
|
|
||
|
|
||
|
@logger.catch
|
||
|
def handle_vol_lvl_as_switch_track():
|
||
|
volume_diff = []
|
||
|
while True:
|
||
|
volume = subprocess.Popen("termux-volume", stdout=subprocess.PIPE).stdout
|
||
|
json_volume = json.loads(volume.read())
|
||
|
for i in json_volume:
|
||
|
if i['stream'] == 'music':
|
||
|
volume_diff.append(i['volume'])
|
||
|
if len(volume_diff) == 2:
|
||
|
before, after = volume_diff
|
||
|
difference = after - before
|
||
|
if difference == 2:
|
||
|
try:
|
||
|
player.playlist_next()
|
||
|
except:
|
||
|
pass
|
||
|
os.system(f'termux-volume music {before}')
|
||
|
volume_diff = []
|
||
|
|
||
|
|
||
|
handle_vol_lvl = threading.Thread(
|
||
|
target=handle_vol_lvl_as_switch_track, daemon=True)
|
||
|
handle_vol_lvl.start()
|