接口参考手册¶
这个参考手册描述了 feeluown 的几大组成部分,各组成部分的主要模块, 以及模块的相对稳定接口。
播放模块¶
播放模块由两部分组成:播放列表(Playlist)和播放器(Player)。
播放列表维护了一个媒体资源集合,并提供若干资源获取接口,播放器通过接口获取资源,
然后进行播放。这些接口包括: current_song
, next_song
, previous_song
。
播放列表吐资源给播放器的时候,是有一定的顺序的,我们称之为回放模式(PlaybackMode)。 回放模式有四种:单曲循环;顺序;循环;随机。上述三个资源访问接口吐资源的顺序都会受回放模式影响。
当播放列表 current_song
变化时,它会发出 song_changed
信号,播放器会监听该信号,
从而播放、停止(song 为空时)或者切换歌曲。播放歌曲时,播放器的状态(State)会发生变化,
当没有歌曲播放的时候,播放器为停止(stopped)状态,有歌曲播放的时候,为正在播放状态。
当一首歌开始播放后,播放器会发出 media_changed
信号,
当一首歌曲播放完毕时,播放器会发出 song_finished
信号。
播放列表和播放器之间的调用关系如下:
Playlist (Mpv)Player
current_song.setter ---[song_changed]---> play_song
^ |
| | <song==None>
|<- play_song |--------------> stop
|<- play_next/play_previous |
|<- play_next <-| prepare_media
|<- replay <-| <mode==one_loop> |
| v
| play ---[media_changed]--->
[song_finished]
|
|
---- event(END_FILE)
^
|
MpvPlayer
通用管理模块¶
-
class
feeluown.task.
TaskKind
[source]¶ An enumeration.
-
preemptive
= 'preemptive'¶ preemptive task
-
cooperative
= 'cooperative'¶ cooperative task
-
-
class
feeluown.task.
PreemptiveTaskSpec
(mgr, name)[source]¶ Preemptive task specification (threadsafe)
GUI 相关管理模块¶
Note
目前,大部分 GUI 组件的接口都不稳定,我们在实现插件时,如果需要从操作 GUI 组件, 请调用以下模块的接口。如果我们想实现的功能通过以下接口在暂时实现不了, 请和 @cosven 联系。
GUI 组件¶
-
class
feeluown.gui.widgets.login.
LoginDialog
[source]¶ Base class for login dialogs
-
login_succeed
¶ login succeed signal
-
-
class
feeluown.gui.widgets.login.
CookiesLoginDialog
(uri=None, required_cookies_fields=None)[source]¶ CookiesLoginDialog provides a text edit area and a login button. User firstly fill in the text edit area with cookies. User can then click the login button. The clicked signal is connected to
login()
.Cookies can be in text or json format. User can copy cookies from web browser like Chrome or Firefox. Cookies copied from firefox are in json format and cookies copied from Chrome are in text format.
Subclass MUST implement four methods.
One usage example: feeluown-qqmusic.
Parse the content in text edit area
Returns: return None when the content is invalid Return type: dict or None
-
show_hint
(text, color=None)[source]¶ Show hint message on dialog
Parameters: color (string) – red for error, orange for warning, green for success
-
autologin
()[source]¶ Try to load user cookies and login with it
Generally, you can call this method after dialog is shown.
Load user cookies from somewhere
Load the cookies that is dumped before. If the load processing failed, just return None.
Returns: cookies in dict format Return type: dict or None
Dump user cookies to somewhere
Generally, you can store the cookies in FeelUOwn data directory with specifical filename.
-
login
()[source]¶ Login with cookies
Read cookies that has been filled in and create a user from it. If succeed, the
login_succeed
signal will be emit. If failed, show specific error message on the dialog based on the exception.
Create a user model from cookies dict
Return type: feeluown.models.UserModel
异常¶
HELP: I do not know how to design exception classes, as a result, these interfaces can be changed frequently.
-
exception
feeluown.excs.
ProviderIOError
(message='', provider=None)[source]¶ Read/write data from/to provider failed
currently, all providers use requests to send http request, and many Requestexception are not catched, so ProviderIOError inherit RequestException.
-
exception
feeluown.excs.
CreateReaderFailed
(message='', provider=None)[source]¶ (DEPRECATED) use ProviderIOError instead
-
exception
feeluown.excs.
ReaderException
(message='', provider=None)[source]¶ (DEPRECATED) use ProviderIOError instead
-
exception
feeluown.excs.
ReadFailed
(message='', provider=None)[source]¶ (DEPRECATED) use ProviderIOError instead