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

添加了快进功能 #6

Merged
merged 2 commits into from
Feb 28, 2019
Merged
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
- q 退出
- Enter 播放电台
- Space 暂停 or 继续播放
- L 快进
- d 下载电台
- w 打开时间轴图片(或打开链接)
- o 打开时间轴来源
21 changes: 16 additions & 5 deletions gaycore/gcore_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ def _init_curses(self):
curses.curs_set(0)
curses.start_color()
try:
curses.init_pair(1, curses.COLOR_BLACK, 197) # 接近机核主题的颜色
curses.init_pair(1, curses.COLOR_BLACK, 197) # 接近机核主题的颜色
except:
curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_RED) # 树莓派 windows无法使用机核like色
# 树莓派 windows无法使用机核like色
curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_RED)
curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_BLACK)
self.stdscr.bkgd(curses.color_pair(2))
self.stdscr.timeout(100)
Expand Down Expand Up @@ -261,6 +262,10 @@ def mainloop(self):
if c == ord(" "):
self.player.pause_or_resume_mp3()

# 快进/倒退
if c == ord("L"):
self.player.forward_mp3(5)

# 播放时间轴
self._play_timeflow_info()

Expand All @@ -279,9 +284,15 @@ def f_parser(x): return ', '.join([i[0] for i in eval(x)])
self.windows[-1].box()
self.windows[-1].addstr(1, 1, "时间轴")
self.windows[-1].addstr(1, self.BOX_WIDTH//2-25, "主播:" + djs_info)
play_time = str(datetime.timedelta(
seconds=self.player.process_length))
self.windows[-1].addstr(3, 1, "time: " + play_time)
# play_time = str(datetime.timedelta(
# seconds=self.player.process_length))
play_time_hrs, play_time_min = divmod(
self.player.process_location, 3600)
play_time_min, play_time_sec = divmod(
self.player.process_location, 60)

self.windows[-1].addstr(3, 1, "time: " + str(play_time_hrs).zfill(
2) + ':' + str(play_time_min).zfill(2) + ':' + str(play_time_sec).zfill(2))
if flow_info.get("content"):
try:
self.flow_img = flow_info.get("img", "")
Expand Down
11 changes: 11 additions & 0 deletions gaycore/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def __init__(self):
self.popen_handler = None
self.process_location = 0
self.process_length = 0
self.fps = 0

# 参考musicibox代码
def run_mpg123(self, url, expires=-1, get_time=-1):
Expand All @@ -31,6 +32,8 @@ def run_mpg123(self, url, expires=-1, get_time=-1):
out = strout.split(" ")
self.process_location = int(float(out[3]))
self.process_length = int(float(out[3]) + float(out[4]))
if(float(out[3]) != 0):
self.fps = float(out[1]) / float(out[3])

elif strout == "@P 0":
# end, moving to next
Expand All @@ -48,6 +51,14 @@ def pause_or_resume_mp3(self):
self.popen_handler.stdin.write(b"P\n")
self.popen_handler.stdin.flush()

# 快进/倒退10s
def forward_mp3(self, seconds):
if not self.popen_handler:
return
self.popen_handler.stdin.write(
b"J +" + str(seconds*int(self.fps)).encode("utf-8") + b"\n")
self.popen_handler.stdin.flush()

# 退出播放
def q_mp3(self):
if self.popen_handler:
Expand Down