Skip to content

Commit

Permalink
Merge pull request darknessomi#176 from darknessomi/pr/175
Browse files Browse the repository at this point in the history
add Music Info && Playing song improvement
  • Loading branch information
darknessomi committed Nov 10, 2015
2 parents 6853461 + 14346fd commit c793453
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 24 deletions.
2 changes: 1 addition & 1 deletion NEMbox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import argparse
import sys

version = "0.2.0.2"
version = "0.2.0.4"

def start():
nembox_menu = Menu()
Expand Down
55 changes: 35 additions & 20 deletions NEMbox/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
['-', 'Volume- ', '音量减少'],
['m', 'Menu ', '主菜单'],
['p', 'Present/History ', '当前/历史播放列表'],
["i", 'Music Info ', '当前音乐信息'],
['Shift+p', 'Playing Mode ', '播放模式切换'],
['a', 'Add ', '添加曲目到打碟'],
['z', 'DJ list ', '打碟列表'],
Expand Down Expand Up @@ -97,6 +98,7 @@ def __init__(self):
self.storage.load()
self.collection = self.storage.database['collections'][0]
self.player = Player()
self.player.playing_song_changed_callback = self.song_changed_callback
self.cache = Cache()
self.ui = Ui()
self.netease = NetEase()
Expand Down Expand Up @@ -392,26 +394,8 @@ def start(self):

# 加载当前播放列表
elif key == ord('p'):
if len(self.storage.database['player_info']['player_list']) == 0:
continue
if not self.at_playing_list:
self.stack.append([self.datatype, self.title, self.datalist, self.offset, self.index])
self.at_playing_list = True
self.datatype = self.storage.database['player_info']['player_list_type']
self.title = self.storage.database['player_info']['player_list_title']
self.datalist = []
for i in self.storage.database['player_info']['player_list']:
self.datalist.append(self.storage.database['songs'][i])
self.index = self.storage.database['player_info']['idx']
self.offset = self.storage.database['player_info']['idx'] / self.step * self.step
if self.resume_play:
if self.datatype == "fmsongs":
self.player.end_callback = self.fm_callback
else:
self.player.end_callback = None
self.storage.database['player_info']['idx'] = -1
self.player.play_and_pause(self.index)
self.resume_play = False
self.show_playing_song()


# 播放模式切换
elif key == ord('P'):
Expand Down Expand Up @@ -493,6 +477,10 @@ def start(self):
if datatype == 'help':
webbrowser.open_new_tab('https://github.com/darknessomi/musicbox')

elif key == ord('i'):
if self.player.playing_id != -1:
webbrowser.open_new_tab('http://music.163.com/#/song?id=' + str(self.player.playing_id))

self.ui.build_process_bar(self.player.process_location, self.player.process_length,
self.player.playing_flag,
self.player.pause_flag, self.storage.database['player_info']['playing_mode'])
Expand Down Expand Up @@ -602,6 +590,33 @@ def dispatch_enter(self, idx):
self.datalist = ui.build_search('albums')
self.title = '专辑搜索列表'


def show_playing_song(self):
if len(self.storage.database['player_info']['player_list']) == 0:
return
if not self.at_playing_list:
self.stack.append([self.datatype, self.title, self.datalist, self.offset, self.index])
self.at_playing_list = True
self.datatype = self.storage.database['player_info']['player_list_type']
self.title = self.storage.database['player_info']['player_list_title']
self.datalist = []
for i in self.storage.database['player_info']['player_list']:
self.datalist.append(self.storage.database['songs'][i])
self.index = self.storage.database['player_info']['idx']
self.offset = self.storage.database['player_info']['idx'] / self.step * self.step
if self.resume_play:
if self.datatype == "fmsongs":
self.player.end_callback = self.fm_callback
else:
self.player.end_callback = None
self.storage.database['player_info']['idx'] = -1
self.player.play_and_pause(self.index)
self.resume_play = False

def song_changed_callback(self):
if self.at_playing_list:
self.show_playing_song()

def fm_callback(self):
log.debug("FM CallBack.")
data = self.get_new_fm()
Expand Down
5 changes: 5 additions & 0 deletions NEMbox/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def __init__(self):
self.notifier = self.config.get_item("notifier")
self.mpg123_parameters = self.config.get_item("mpg123_parameters")
self.end_callback = None
self.playing_song_changed_callback = None

def popen_recall(self, onExit, popenArgs):
"""
Expand Down Expand Up @@ -299,6 +300,8 @@ def next_idx(self):
self.info["idx"] = self.info["playing_list"][self.info["ridx"]]
else:
self.info["idx"] += 1
if self.playing_song_changed_callback is not None:
self.playing_song_changed_callback()

def next(self):
self.stop()
Expand Down Expand Up @@ -336,6 +339,8 @@ def prev_idx(self):
self.info["idx"] = self.info["playing_list"][self.info["ridx"]]
else:
self.info["idx"] -= 1
if self.playing_song_changed_callback is not None:
self.playing_song_changed_callback()

def prev(self):
self.stop()
Expand Down
12 changes: 10 additions & 2 deletions NEMbox/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
log = logger.getLogger(__name__)


def escape_quote(text):
return text.replace('\'', '\\\'').replace('\"', '\'\'')

class Ui:
def __init__(self):
self.screen = curses.initscr()
Expand Down Expand Up @@ -51,10 +54,15 @@ def __init__(self):

def notify(self, summary, song, album, artist):
if summary != "disable":
cmd = ""
content = escape_quote("%s %s\nin %s by %s" % (summary, song, album, artist))
if platform.system() == "Darwin":
os.system('/usr/bin/osascript -e \'display notification "' + summary + ' ' + song + '\nin ' + album + ' by ' + artist +'"\'')
cmd = '/usr/bin/osascript -e $\'display notification "' + content + '"\''
else:
os.system('/usr/bin/notify-send "' + summary + song + ' in ' + album + ' by ' + artist + '"')
cmd = '/usr/bin/notify-send "' + content + '"'

os.system(cmd)


def build_playinfo(self, song_name, artist, album_name, quality, start, pause=False):
curses.noecho()
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ NetEase-MusicBox
<tr> <td>?</td> <td>Shuffle</td> <td>手气不错</td> </tr>
<tr> <td>M</td> <td>Menu</td> <td>主菜单</td> </tr>
<tr> <td>P</td> <td>Present/History</td> <td>当前/历史播放列表</td> </tr>
<tr> <td>I</td> <td>Music Info</td> <td>当前音乐信息</td> </tr>
<tr> <td>⇧+P</td> <td>Playing Mode</td> <td>播放模式切换</td> </tr>
<tr> <td>A</td> <td>Add</td> <td>添加曲目到打碟</td> </tr>
<tr> <td>Z</td> <td>DJ list</td> <td>打碟列表</td> </tr>
Expand Down Expand Up @@ -135,6 +136,8 @@ Enjoy it !

### 更新日志

2015-11-10 版本 0.2.0.4 优化切换歌曲时歌单显示, 新增显示歌曲信息功能

2015-11-09 版本 0.2.0.2 修复崩溃错误, 优化榜单排序

2015-11-05 版本 0.2.0.1 优化列表翻页功能
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

setup(
name='NetEase-MusicBox',
version='0.2.0.2',
version='0.2.0.4',
packages=find_packages(),

include_package_data=True,
Expand Down

0 comments on commit c793453

Please sign in to comment.