⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 audacious.c

📁 ShowLyric是一款用于Audacious的歌词显示插件
💻 C
字号:
/* * * Author: Allan <qimingos_lsk@163.com>, (C) 2005-2007 * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA * */#include <dlfcn.h>#include <audacious/plugin.h>#include <audacious/input.h>#include "../include/ShowLyric.h"#include "../include/Audacious.h"GeneralPlugin lyric_gp ={ 	.description = PLUGIN_NAME,	.init = lyric_init,	.about = lyric_about,	.configure = lyric_prefs,	.cleanup = lyric_cleanup,};GeneralPlugin *lyric_gplist[] ={ &lyric_gp, NULL, };DECLARE_PLUGIN(ShowLyric, NULL, NULL, NULL, NULL, NULL, lyric_gplist, NULL, NULL);void lyric_about(){	theApp.About(NULL);}void lyric_init(){	LyricDebug("lyric_init");	aud_hook_associate("playback begin", lyric_playback_begin, NULL);	theApp.m_player.LoadConfigs = Lyric_LoadConfigs;	theApp.m_player.SaveConfigs = Lyric_SaveConfigs;	theApp.m_player.GetCurrTime = Lyric_GetCurrTime;	theApp.m_player.GetSongInfo = Lyric_GetSongInfo;	theApp.Init();}gint Lyric_GetCurrTime(){	return audacious_drct_get_time();}void lyric_prefs(){	theApp.ShowConfigDlg();}void lyric_cleanup(){	Lyric_SaveConfigs(&theApp.m_configs);	theApp.Clean();}void lyric_playback_begin(gpointer unused, gpointer unused2){	LyricDebug("lyric_playback_begin");	// 获取当前播放的歌曲信息	SongInfo info;	if (!Lyric_GetSongInfo(&info))		return;	if (!theApp.PreChangeSong(&info))		return;	theApp.ChangeSong(info);}gboolean Lyric_GetSongInfo(SongInfo * pInfo){	gchar *pszTitle= NULL, *pszArtist= NULL, *pszFilename= NULL;	Playlist *pl= NULL;	int iPlPos = 0;	LyricDebug("Lyric_GetSongInfo\n");	if (!audacious_drct_get_playing())		return FALSE;	gint iPlLen= audacious_drct_pl_get_length();	LyricDebug("The playlist length is %d!(%s:%d)\n", iPlLen,__FILE__ , __LINE__);	if (iPlLen <= 0)	{		return FALSE;	}	iPlPos = audacious_drct_pl_get_pos();	LyricDebug("The playlist pos is %d!(%s:%d)\n", iPlPos, __FILE__, __LINE__);	if (iPlPos < 0)	{		return FALSE;	}	Tuple *out = NULL;	gint iLen = 0;	pl = aud_playlist_get_active();	out = aud_playlist_get_tuple(pl, iPlPos);	if (!out)	{		return FALSE;	}	iLen = aud_tuple_get_int(out, FIELD_LENGTH, NULL);	if (iLen < 1)	{		LyricLog("The song's tuple is empty!\n");		return FALSE;	}	pszFilename = aud_playlist_get_info_text(pl);	if (!pszFilename)return FALSE;	strncpy(pInfo->szFileName, pszFilename, MAX_PATH);	free(pszFilename);	pszFilename = audacious_drct_pl_get_file(iPlPos);		if (!pszFilename)return FALSE;	memset(pInfo->szSongFolder, 0, MAX_PATH);	strncpy(pInfo->szSongFolder, pszFilename, MAX_PATH);	free(pszFilename);	//pszFilename = aud_uri_to_display_dirname(pInfo->szSongFolder);    gchar *realfn, *utf8fn;    realfn = g_filename_from_uri(pInfo->szSongFolder, NULL, NULL);	if (!realfn)return FALSE;    utf8fn = g_filename_display_name(realfn ? realfn : pInfo->szSongFolder);  // guaranteed to be non-NULL	if (!utf8fn)return FALSE;    pszFilename = g_path_get_dirname(utf8fn);    g_free(realfn); g_free(utf8fn);	if (!pszFilename)return FALSE;	memset(pInfo->szSongFolder, 0, MAX_PATH);	strncpy(pInfo->szSongFolder, pszFilename, MAX_PATH);	free(pszFilename);	pszFilename = NULL;	pszTitle = (gchar *) aud_tuple_get_string(out, FIELD_TITLE, NULL);	if (pszTitle)	{		strncpy(pInfo->szTitle, pszTitle, TITLE_LENGTH);		pInfo->szTitle[TITLE_LENGTH] = 0;		//free(pszTitle);		pszTitle = NULL;	}	else	{		int iLenght = strlen((const char *) pInfo->szFileName);		int iDotPos = iLenght, iNameBegin = 0, iCurr = iLenght;		while (iCurr> 0)		{			if (pInfo->szFileName[iCurr] == '.' && iDotPos == iLenght)			{				iDotPos = iCurr;				iCurr--;				continue;			}			if (pInfo->szFileName[iCurr] == '.')			{				iNameBegin = iCurr + 2;				if (iNameBegin != iDotPos)				break;			}			iCurr--;		}		int iTitleLen = iDotPos - iNameBegin;		LyricDebug ("iDotPos:%d, iNameBegin:%d, iTitleLen:%d, iLenght:%d",		iDotPos, iNameBegin, iTitleLen, strlen((const char *) pInfo->szFileName));		if (iTitleLen <= 0)		return FALSE;		strncpy(pInfo->szTitle, pInfo->szFileName + iNameBegin, iTitleLen);		pInfo->szTitle[iTitleLen] = '\0';	}	pszArtist = (gchar *) aud_tuple_get_string(out, FIELD_ARTIST, NULL);	if (pszArtist)	{		strncpy(pInfo->szArtist, pszArtist, ARTIST_LENGTH);		pInfo->szArtist[ARTIST_LENGTH] = '\0';		//free(pszArtist);		pszArtist = NULL;	}	else	{		pInfo->szArtist[0] = 0;	}	LyricDebug("szSongFolder: %s", pInfo->szSongFolder);	LyricDebug("szFileName: %s", pInfo->szFileName);	LyricDebug("szTitle:    %s", pInfo->szTitle);	LyricDebug("szArtist:   %s", pInfo->szArtist);	return TRUE;}// 加载配置信息// @pConfigs: 配置信息gboolean Lyric_LoadConfigs(OUT Configs* pConfigs){	// 加载配置信息	ConfigDb *cfgfile = aud_cfg_db_open();	gchar *lpszTmp= NULL;	if (aud_cfg_db_get_string(cfgfile, PLUGIN_NAME, "LyricPath", &lpszTmp))	{		strncpy(pConfigs->szLyricPath, lpszTmp, MAX_PATH);	}#define LOAD_COLOR(name, to) if(aud_cfg_db_get_string(cfgfile, PLUGIN_NAME, name, &lpszTmp)) {\		gdk_color_parse(lpszTmp, &to);\	}	LOAD_COLOR("BackgroundColor", pConfigs->colors.background);	LOAD_COLOR("NormalColor", pConfigs->colors.normal);	LOAD_COLOR("CurrColor", pConfigs->colors.current);	LOAD_COLOR("DragColor", pConfigs->colors.drag);	LOAD_COLOR("MsgColor", pConfigs->colors.msg);	LOAD_COLOR("ErrorColor", pConfigs->colors.error);	gboolean bTmp = FALSE;	if (aud_cfg_db_get_bool(cfgfile, PLUGIN_NAME, "SmartShowWin", &bTmp))		pConfigs->bSmartShowWin = bTmp;	if (aud_cfg_db_get_bool(cfgfile, PLUGIN_NAME, "SmartDownLoad", &bTmp))		pConfigs->bSmartDownLoad = bTmp;	if (aud_cfg_db_get_bool(cfgfile, PLUGIN_NAME, "ShowBroad", &bTmp))		pConfigs->bShowBroad = bTmp;	if (aud_cfg_db_get_bool(cfgfile, PLUGIN_NAME, "SaveLyricToSongFolder", &bTmp))		pConfigs->bSaveLyricToSongFolder = bTmp;	int iTmp = 0;	if (aud_cfg_db_get_int(cfgfile, PLUGIN_NAME, "Opacity", &iTmp))		pConfigs->iOpacity = iTmp;	if (aud_cfg_db_get_int(cfgfile, PLUGIN_NAME, "Pos_iX", &iTmp))		pConfigs->pos.iX = iTmp;	if (aud_cfg_db_get_int(cfgfile, PLUGIN_NAME, "Pos_iY", &iTmp))		pConfigs->pos.iY = iTmp;	if (aud_cfg_db_get_string(cfgfile, PLUGIN_NAME, "LyricFontName", &lpszTmp))	{		strncpy(pConfigs->szLyricFontName, lpszTmp, MAX_PATH);	}	aud_cfg_db_close(cfgfile);	return TRUE;}// 保存配置信息// @pConfigs: 配置信息gboolean Lyric_SaveConfigs(IN Configs* pConfigs){	// 保存配置信息	ConfigDb *cfgfile = aud_cfg_db_open();	aud_cfg_db_set_string(cfgfile, PLUGIN_NAME, "LyricPath", pConfigs->szLyricPath);#define SAVE_COLOR(name, color) do {\		gchar* lpszColor = gdk_color_to_string (&color);\		aud_cfg_db_set_string(cfgfile, PLUGIN_NAME, name, lpszColor);\		free(lpszColor);\	}while(0)	SAVE_COLOR("BackgroundColor", pConfigs->colors.background);	SAVE_COLOR("NormalColor", pConfigs->colors.normal);	SAVE_COLOR("CurrColor", pConfigs->colors.current);	SAVE_COLOR("DragColor", pConfigs->colors.drag);	SAVE_COLOR("MsgColor", pConfigs->colors.msg);	SAVE_COLOR("ErrorColor", pConfigs->colors.error);	aud_cfg_db_set_bool(cfgfile, PLUGIN_NAME, "SmartShowWin", pConfigs->bSmartShowWin);	aud_cfg_db_set_bool(cfgfile, PLUGIN_NAME, "ShowBroad", pConfigs->bShowBroad);	aud_cfg_db_set_bool(cfgfile, PLUGIN_NAME, "SmartDownLoad", pConfigs->bSmartDownLoad);	aud_cfg_db_set_bool(cfgfile, PLUGIN_NAME, "SaveLyricToSongFolder", pConfigs->bSaveLyricToSongFolder);	aud_cfg_db_set_int(cfgfile, PLUGIN_NAME, "Opacity", pConfigs->iOpacity);	aud_cfg_db_set_int(cfgfile, PLUGIN_NAME, "Pos_iX", pConfigs->pos.iX);	aud_cfg_db_set_int(cfgfile, PLUGIN_NAME, "Pos_iY", pConfigs->pos.iY);	aud_cfg_db_set_string(cfgfile, PLUGIN_NAME, "LyricFontName", pConfigs->szLyricFontName);	aud_cfg_db_close(cfgfile);	return TRUE;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -