7
7
QColor , QLinearGradient , QPalette , QPainter ,
8
8
)
9
9
10
- from feeluown .player import PlaybackMode , SongsRadio
10
+ from feeluown .player import PlaybackMode , SongsRadio , AIRadio , AI_RADIO_SUPPORTED
11
11
from feeluown .gui .helpers import fetch_cover_wrapper , esc_hide_widget
12
12
from feeluown .gui .components .player_playlist import PlayerPlaylistView
13
13
from feeluown .gui .widgets .textbtn import TextButton
@@ -46,6 +46,7 @@ def __init__(self, app, *args, **kwargs):
46
46
self ._playback_mode_switch = PlaybackModeSwitch (app )
47
47
self ._goto_current_song_btn = TextButton ('跳转到当前歌曲' )
48
48
self ._songs_radio_btn = TextButton ('自动续歌' )
49
+ self ._ai_radio_btn = TextButton ('AI电台' )
49
50
# Please update the list when you add new buttons.
50
51
self ._btns = [
51
52
self ._clear_playlist_btn ,
@@ -65,13 +66,24 @@ def __init__(self, app, *args, **kwargs):
65
66
self ._clear_playlist_btn .clicked .connect (self ._app .playlist .clear )
66
67
self ._goto_current_song_btn .clicked .connect (self .goto_current_song )
67
68
self ._songs_radio_btn .clicked .connect (self .enter_songs_radio )
69
+ self ._ai_radio_btn .clicked .connect (self .enter_ai_radio )
68
70
esc_hide_widget (self )
69
71
q_app = QApplication .instance ()
70
72
assert q_app is not None # make type checker happy.
71
73
# type ignore: q_app has focusChanged signal, but type checker can't find it.
72
74
q_app .focusChanged .connect (self .on_focus_changed ) # type: ignore
73
75
self ._app .installEventFilter (self )
74
76
self ._tabbar .currentChanged .connect (self .show_tab )
77
+
78
+ if (
79
+ AI_RADIO_SUPPORTED is True
80
+ and self ._app .config .OPENAI_API_KEY
81
+ and self ._app .config .OPENAI_MODEL
82
+ and self ._app .config .OPENAI_API_BASEURL
83
+ ):
84
+ self ._ai_radio_btn .clicked .connect (self .enter_ai_radio )
85
+ else :
86
+ self ._ai_radio_btn .setDisabled (True )
75
87
self .setup_ui ()
76
88
77
89
def setup_ui (self ):
@@ -97,6 +109,7 @@ def setup_ui(self):
97
109
self ._btn_layout .addWidget (self ._playback_mode_switch )
98
110
self ._btn_layout .addWidget (self ._goto_current_song_btn )
99
111
self ._btn_layout2 .addWidget (self ._songs_radio_btn )
112
+ self ._btn_layout2 .addWidget (self ._ai_radio_btn )
100
113
self ._btn_layout .addStretch (0 )
101
114
self ._btn_layout2 .addStretch (0 )
102
115
@@ -125,6 +138,14 @@ def enter_songs_radio(self):
125
138
self ._app .fm .activate (radio .fetch_songs_func , reset = False )
126
139
self ._app .show_msg ('“自动续歌”功能已激活' )
127
140
141
+ def enter_ai_radio (self ):
142
+ if self ._app .playlist .list ():
143
+ radio = AIRadio (self ._app )
144
+ self ._app .fm .activate (radio .fetch_songs_func , reset = False )
145
+ self ._app .show_msg ('已经进入 AI 电台模式 ~' )
146
+ else :
147
+ self ._app .show_msg ('播放列表为空,暂时不能开启 AI 电台' )
148
+
128
149
def show_tab (self , index ):
129
150
if not self .isVisible ():
130
151
return
0 commit comments