对外接口

这部分文档覆盖了 fuocore 对外提供的所有模块和接口。

class fuocore.models.BaseModel(*args, **kwargs)[源代码]

Base model for music resource.

参数:

identifier – model object identifier, unique in each provider

变量:
  • allow_get – meta var, whether model has a valid get method
  • allow_list – meta var, whether model has a valid list method
classmethod get(identifier)[源代码]

获取 model 详情

这个方法必须尽量初始化所有字段,确保它们的值不是 None。

classmethod list(identifier_list)[源代码]

Model batch get method

class fuocore.models.SongModel(*args, **kwargs)[源代码]

Song Model

参数:
  • title (str) – song title
  • url (str) – song url (http url or local filepath)
  • duration (float) – song duration
  • album (AlbumModel) – album which song belong to
  • artists (list) – song artists ArtistModel
  • lyric (LyricModel) – song lyric
class fuocore.models.LyricModel(*args, **kwargs)[源代码]

Lyric Model

参数:
  • song (SongModel) – song which lyric belongs to
  • content (str) – lyric content
  • trans_content (str) – translated lyric content
class fuocore.models.AlbumModel(*args, **kwargs)[源代码]

Album Model

参数:
  • name (str) – album name
  • cover (str) – album cover image url
  • songs (list) – album songs
  • artists (list) – album artists
  • desc (str) – album description
class fuocore.models.ArtistModel(*args, **kwargs)[源代码]

Artist Model

参数:
  • name (str) – artist name
  • cover (str) – artist cover image url
  • songs (list) – artist songs
  • desc (str) – artist description
class fuocore.models.PlaylistModel(*args, **kwargs)[源代码]

Playlist Model

参数:
  • name – playlist name
  • cover – playlist cover image url
  • desc – playlist description
  • songs – playlist songs
add(song_id)[源代码]

add song to playlist, return true if succeed.

If the song was in playlist already, return true.

remove(song_id)[源代码]

remove songs from playlist, return true if succeed

If song is not in playlist, return true.

class fuocore.models.UserModel(*args, **kwargs)[源代码]

User Model

参数:
  • name – user name
  • playlists – playlists created by user
  • fav_playlists – playlists collected by user
  • fav_songs – songs collected by user
  • fav_albums – albums collected by user
  • fav_artists – artists collected by user
add_to_fav_songs(song_id)[源代码]

add song to favorite songs, return True if success

参数:song_id – song identifier
返回:Ture if success else False
返回类型:boolean
class fuocore.models.SearchModel(*args, **kwargs)[源代码]

Search Model

参数:
  • q – search query string
  • songs – songs in search result

TODO: support album and artist

class fuocore.provider.AbstractProvider[源代码]

abstract music resource provider

Song

fuocore.models.SongModel 的别名

Artist

fuocore.models.ArtistModel 的别名

Album

fuocore.models.AlbumModel 的别名

Playlist

fuocore.models.PlaylistModel 的别名

Lyric

fuocore.models.LyricModel 的别名

User

fuocore.models.UserModel 的别名

identifier

provider identify

name

provider name

auth_as(user)[源代码]

auth as a user temporarily

auth(user)[源代码]

use provider as a specific user

class fuocore.player.State[源代码]

Player states.

stopped = 0
paused = 1
playing = 2
class fuocore.player.PlaybackMode[源代码]

Playlist playback mode.

one_loop = 0

One Loop

sequential = 1

Sequential

loop = 2

Loop

random = 3

Random

class fuocore.player.Playlist(songs=None, playback_mode=<PlaybackMode.loop: 2>)[源代码]

player playlist provide a list of song model to play

NOTE - Design: Why we use song model instead of url? Theoretically, using song model may increase the coupling. However, simple url do not obtain enough metadata.

playback_mode_changed = None

playback mode changed signal

song_changed = None

current song changed signal

add(song)[源代码]

往播放列表末尾添加一首歌曲

insert(song)[源代码]

在当前歌曲后插入一首歌曲

remove(song)[源代码]

Remove song from playlist. O(n)

If song is current song, remove the song and play next. Otherwise, just remove it.

clear()[源代码]

remove all songs from playlists

list()[源代码]

get all songs in playlists

current_song

current playing song, return None if there is no current song

next_song

next song for player, calculated based on playback_mode

previous_song

previous song for player to play

NOTE: not the last played song


class fuocore.live_lyric.LiveLyric[源代码]

live lyric

LiveLyric listens to song changed signal and position changed signal and emit sentence changed signal. It also has a current_sentence property.

Usage:

live_lyric = LiveLyric()
player.song_changed.connect(live_lyric.on_song_changed)
player.position_change.connect(live_lyric.on_position_changed)
current_sentence

get current lyric sentence

on_position_changed(position)[源代码]

bind position changed signal with this

on_song_changed(song)[源代码]

bind song changed signal with this