Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[proposal] feat: 黑屏暂停播放. #813

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions NEMbox/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ def songs(cls, songs):
"album_id": album_id,
"mp3_url": url,
"quality": quality,
"expires": song["expires"],
"get_time": song["get_time"],
"expires": song.get("expires",0),
"get_time": song.get("get_time",time.time()),
}
song_info_list.append(song_info)
return song_info_list
Expand Down
13 changes: 11 additions & 2 deletions NEMbox/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from .ui import Ui
from .osdlyrics import show_lyrics_new_process
from .config import Config
from .utils import notify
from .utils import notify, SessionScreenLockDetector
from .storage import Storage
from .cache import Cache
from . import logger
Expand Down Expand Up @@ -121,6 +121,7 @@ def __init__(self):
self.countdown_start = time.time()
self.countdown = -1
self.is_in_countdown = False
self.sys_screen=SessionScreenLockDetector()

@property
def user(self):
Expand Down Expand Up @@ -249,7 +250,7 @@ def previous_song(self):
self.player.prev()

def start(self):
self.menu_starts = time.time()
self.menu_starts = last_check_sys_screen = time.time()
self.ui.build_menu(
self.datatype,
self.title,
Expand Down Expand Up @@ -630,6 +631,14 @@ def start(self):
webbrowser.open_new_tab(
"http://music.163.com/song?id={}".format(self.player.playing_id)
)
else:
# No matching input
if self.player.playing_flag and ( self.sys_screen is not None ) and \
time.time() - last_check_sys_screen > 30 :
last_check_sys_screen=time.time()
if self.sys_screen.is_locked():
self.player.switch()
log.debug("Screen Saver Active. Pause music.")

self.ui.build_process_bar(
self.player.current_song,
Expand Down
43 changes: 42 additions & 1 deletion NEMbox/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import platform
import subprocess
import os
import os,sys
from collections import OrderedDict

from future.builtins import str
Expand Down Expand Up @@ -83,6 +83,47 @@ def notify(msg, msg_type=0, t=None):
return False



try:
import dbus
except:
pass

class SessionScreenLockDetector(object):

def __init__(self):
self.valid=False
if 'Linux' not in platform.system() or "dbus" not in sys.modules:
# Not implemented
return

session_bus = dbus.SessionBus()
screensaver_list = ['org.gnome.ScreenSaver',
'org.cinnamon.ScreenSaver',
'org.kde.screensaver',
'org.freedesktop.ScreenSaver']

for each in screensaver_list:
try:
object_path = '/{0}'.format(each.replace('.', '/'))
self.screen_saver = dbus.Interface(session_bus.get_object(each, object_path), each)
bool(self.screen_saver.GetActive())
except dbus.exceptions.DBusException:
pass
else:
self.valid=True
break

def is_locked(self):
if not self.valid:
return False
else:
try:
state=bool(self.screen_saver.GetActive())
except:
state=False
return state

if __name__ == "__main__":
notify('I\'m test ""quote', msg_type=1, t=1000)
notify("I'm test 1", msg_type=1, t=1000)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
15. Vimer式快捷键让操作丝般顺滑
16. 可使用数字快捷键
17. 可使用自定义全局快捷键
18. 每30秒检查是否锁屏黑屏,黑屏则暂停播放(适用于部分基于dbus的Linux系统)

### 键盘快捷键

Expand Down