diff --git a/README.md b/README.md index 914e0d2..cd84294 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ - q 退出 - Enter 播放电台 - Space 暂停 or 继续播放 +- L 快进 - d 下载电台 - w 打开时间轴图片(或打开链接) - o 打开时间轴来源 diff --git a/gaycore/gcore_box.py b/gaycore/gcore_box.py index b3f4bc8..d7d7efd 100644 --- a/gaycore/gcore_box.py +++ b/gaycore/gcore_box.py @@ -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) @@ -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() @@ -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", "") diff --git a/gaycore/player.py b/gaycore/player.py index 5d7c4a0..3e091d9 100644 --- a/gaycore/player.py +++ b/gaycore/player.py @@ -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): @@ -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 @@ -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: