📄 libmpdclient.c
字号:
entity->info.song->artist = strdup(re->value); } else if(!entity->info.song->album && strcmp(re->name,"Album")==0) { entity->info.song->album = strdup(re->value); } else if(!entity->info.song->title && strcmp(re->name,"Title")==0) { entity->info.song->title = strdup(re->value); } else if(!entity->info.song->track && strcmp(re->name,"Track")==0) { entity->info.song->track = strdup(re->value); } else if(!entity->info.song->name && strcmp(re->name,"Name")==0) { entity->info.song->name = strdup(re->value); } else if(entity->info.song->time==MPD_SONG_NO_TIME && strcmp(re->name,"Time")==0) { entity->info.song->time = atoi(re->value); } else if(entity->info.song->pos==MPD_SONG_NO_NUM && strcmp(re->name,"Pos")==0) { entity->info.song->pos = atoi(re->value); } else if(entity->info.song->id==MPD_SONG_NO_ID && strcmp(re->name,"Id")==0) { entity->info.song->id = atoi(re->value); } else if(!entity->info.song->date && strcmp(re->name, "Date") == 0) { entity->info.song->date = strdup(re->value); } } else if(entity->type == MPD_INFO_ENTITY_TYPE_DIRECTORY) { } else if(entity->type == MPD_INFO_ENTITY_TYPE_PLAYLISTFILE) { } mpd_getNextReturnElement(connection); } return entity;}char * mpd_getNextReturnElementNamed(mpd_Connection * connection, const char * name) { if(connection->doneProcessing || (connection->listOks && connection->doneListOk)) { return NULL; } mpd_getNextReturnElement(connection); while(connection->returnElement) { mpd_ReturnElement * re = connection->returnElement; if(strcmp(re->name,name)==0) return strdup(re->value); mpd_getNextReturnElement(connection); } return NULL;}char * mpd_getNextArtist(mpd_Connection * connection) { return mpd_getNextReturnElementNamed(connection,"Artist");}char * mpd_getNextAlbum(mpd_Connection * connection) { return mpd_getNextReturnElementNamed(connection,"Album");}void mpd_sendPlaylistInfoCommand(mpd_Connection * connection, int songPos) { char * string = malloc(strlen("playlistinfo")+25); sprintf(string,"playlistinfo \"%i\"\n",songPos); mpd_sendInfoCommand(connection,string); free(string);}void mpd_sendPlaylistIdCommand(mpd_Connection * connection, int id) { char * string = malloc(strlen("playlistid")+25); sprintf(string, "playlistid \"%i\"\n", id); mpd_sendInfoCommand(connection, string); free(string);}void mpd_sendPlChangesCommand(mpd_Connection * connection, long long playlist) { char * string = malloc(strlen("plchanges")+25); sprintf(string,"plchanges \"%lld\"\n",playlist); mpd_sendInfoCommand(connection,string); free(string);}void mpd_sendListallCommand(mpd_Connection * connection, const char * dir) { char * sDir = mpd_sanitizeArg(dir); char * string = malloc(strlen("listall")+strlen(sDir)+5); sprintf(string,"listall \"%s\"\n",sDir); mpd_sendInfoCommand(connection,string); free(string); free(sDir);}void mpd_sendListallInfoCommand(mpd_Connection * connection, const char * dir) { char * sDir = mpd_sanitizeArg(dir); char * string = malloc(strlen("listallinfo")+strlen(sDir)+5); sprintf(string,"listallinfo \"%s\"\n",sDir); mpd_sendInfoCommand(connection,string); free(string); free(sDir);}void mpd_sendLsInfoCommand(mpd_Connection * connection, const char * dir) { char * sDir = mpd_sanitizeArg(dir); char * string = malloc(strlen("lsinfo")+strlen(sDir)+5); sprintf(string,"lsinfo \"%s\"\n",sDir); mpd_sendInfoCommand(connection,string); free(string); free(sDir);}void mpd_sendCurrentSongCommand(mpd_Connection * connection) { mpd_executeCommand(connection,"currentsong\n");}void mpd_sendSearchCommand(mpd_Connection * connection, int table, const char * str) { char st[10]; char * string; char * sanitStr = mpd_sanitizeArg(str); if(table == MPD_TABLE_ARTIST) strcpy(st,"artist"); else if(table == MPD_TABLE_ALBUM) strcpy(st,"album"); else if(table == MPD_TABLE_TITLE) strcpy(st,"title"); else if(table == MPD_TABLE_FILENAME) strcpy(st,"filename"); else { connection->error = 1; strcpy(connection->errorStr,"unknown table for search"); return; } string = malloc(strlen("search")+strlen(sanitStr)+strlen(st)+6); sprintf(string,"search %s \"%s\"\n",st,sanitStr); mpd_sendInfoCommand(connection,string); free(string); free(sanitStr);}void mpd_sendFindCommand(mpd_Connection * connection, int table, const char * str) { char st[10]; char * string; char * sanitStr = mpd_sanitizeArg(str); if(table == MPD_TABLE_ARTIST) strcpy(st,"artist"); else if(table == MPD_TABLE_ALBUM) strcpy(st,"album"); else if(table == MPD_TABLE_TITLE) strcpy(st,"title"); else { connection->error = 1; strcpy(connection->errorStr,"unknown table for find"); return; } string = malloc(strlen("find")+strlen(sanitStr)+strlen(st)+6); sprintf(string,"find %s \"%s\"\n",st,sanitStr); mpd_sendInfoCommand(connection,string); free(string); free(sanitStr);}void mpd_sendListCommand(mpd_Connection * connection, int table, const char * arg1) { char st[10]; char * string; if(table == MPD_TABLE_ARTIST) strcpy(st,"artist"); else if(table == MPD_TABLE_ALBUM) strcpy(st,"album"); else { connection->error = 1; strcpy(connection->errorStr,"unknown table for list"); return; } if(arg1) { char * sanitArg1 = mpd_sanitizeArg(arg1); string = malloc(strlen("list")+strlen(sanitArg1)+strlen(st)+6); sprintf(string,"list %s \"%s\"\n",st,sanitArg1); free(sanitArg1); } else { string = malloc(strlen("list")+strlen(st)+3); sprintf(string,"list %s\n",st); } mpd_sendInfoCommand(connection,string); free(string);}void mpd_sendAddCommand(mpd_Connection * connection, const char * file) { char * sFile = mpd_sanitizeArg(file); char * string = malloc(strlen("add")+strlen(sFile)+5); sprintf(string,"add \"%s\"\n",sFile); mpd_executeCommand(connection,string); free(string); free(sFile);}void mpd_sendDeleteCommand(mpd_Connection * connection, int songPos) { char * string = malloc(strlen("delete")+25); sprintf(string,"delete \"%i\"\n",songPos); mpd_sendInfoCommand(connection,string); free(string);}void mpd_sendDeleteIdCommand(mpd_Connection * connection, int id) { char * string = malloc(strlen("deleteid")+25); sprintf(string, "deleteid \"%i\"\n", id); mpd_sendInfoCommand(connection,string); free(string);}void mpd_sendSaveCommand(mpd_Connection * connection, const char * name) { char * sName = mpd_sanitizeArg(name); char * string = malloc(strlen("save")+strlen(sName)+5); sprintf(string,"save \"%s\"\n",sName); mpd_executeCommand(connection,string); free(string); free(sName);}void mpd_sendLoadCommand(mpd_Connection * connection, const char * name) { char * sName = mpd_sanitizeArg(name); char * string = malloc(strlen("load")+strlen(sName)+5); sprintf(string,"load \"%s\"\n",sName); mpd_executeCommand(connection,string); free(string); free(sName);}void mpd_sendRmCommand(mpd_Connection * connection, const char * name) { char * sName = mpd_sanitizeArg(name); char * string = malloc(strlen("rm")+strlen(sName)+5); sprintf(string,"rm \"%s\"\n",sName); mpd_executeCommand(connection,string); free(string); free(sName);}void mpd_sendShuffleCommand(mpd_Connection * connection) { mpd_executeCommand(connection,"shuffle\n");}void mpd_sendClearCommand(mpd_Connection * connection) { mpd_executeCommand(connection,"clear\n");}void mpd_sendPlayCommand(mpd_Connection * connection, int songPos) { char * string = malloc(strlen("play")+25); sprintf(string,"play \"%i\"\n",songPos); mpd_sendInfoCommand(connection,string); free(string);}void mpd_sendPlayIdCommand(mpd_Connection * connection, int id) { char * string = malloc(strlen("playid")+25); sprintf(string,"playid \"%i\"\n",id); mpd_sendInfoCommand(connection,string); free(string);}void mpd_sendStopCommand(mpd_Connection * connection) { mpd_executeCommand(connection,"stop\n");}void mpd_sendPauseCommand(mpd_Connection * connection, int pauseMode) { char * string = malloc(strlen("pause")+25); sprintf(string,"pause \"%i\"\n",pauseMode); mpd_executeCommand(connection,string); free(string);}void mpd_sendNextCommand(mpd_Connection * connection) { mpd_executeCommand(connection,"next\n");}void mpd_sendMoveCommand(mpd_Connection * connection, int from, int to) { char * string = malloc(strlen("move")+25); sprintf(string,"move \"%i\" \"%i\"\n",from,to); mpd_sendInfoCommand(connection,string); free(string);}void mpd_sendMoveIdCommand(mpd_Connection * connection, int id, int to) { char * string = malloc(strlen("moveid")+25); sprintf(string, "moveid \"%i\" \"%i\"\n", id, to); mpd_sendInfoCommand(connection,string); free(string);}void mpd_sendSwapCommand(mpd_Connection * connection, int song1, int song2) { char * string = malloc(strlen("swap")+25); sprintf(string,"swap \"%i\" \"%i\"\n",song1,song2); mpd_sendInfoCommand(connection,string); free(string);}void mpd_sendSwapIdCommand(mpd_Connection * connection, int id1, int id2) { char * string = malloc(strlen("swapid")+25); sprintf(string, "swapid \"%i\" \"%i\"\n", id1, id2); mpd_sendInfoCommand(connection,string); free(string);}void mpd_sendSeekCommand(mpd_Connection * connection, int song, int time) { char * string = malloc(strlen("seek")+25); sprintf(string,"seek \"%i\" \"%i\"\n",song,time); mpd_sendInfoCommand(connection,string); free(string);}void mpd_sendSeekIdCommand(mpd_Connection * connection, int id, int time) { char * string = malloc(strlen("seekid")+25); sprintf(string,"seekid \"%i\" \"%i\"\n",id,time); mpd_sendInfoCommand(connection,string); free(string);}void mpd_sendUpdateCommand(mpd_Connection * connection, char * path) { char * sPath = mpd_sanitizeArg(path); char * string = malloc(strlen("update")+strlen(sPath)+5); sprintf(string,"update \"%s\"\n",sPath); mpd_sendInfoCommand(connection,string); free(string); free(sPath);}int mpd_getUpdateId(mpd_Connection * connection) { char * jobid; int ret = 0; jobid = mpd_getNextReturnElementNamed(connection,"updating_db"); if(jobid) { ret = atoi(jobid); free(jobid); } return ret;}void mpd_sendPrevCommand(mpd_Connection * connection) { mpd_executeCommand(connection,"previous\n");}void mpd_sendRepeatCommand(mpd_Connection * connection, int repeatMode) { char * string = malloc(strlen("repeat")+25); sprintf(string,"repeat \"%i\"\n",repeatMode); mpd_executeCommand(connection,string); free(string);}void mpd_sendRandomCommand(mpd_Connection * connection, int randomMode) { char * string = malloc(strlen("random")+25); sprintf(string,"random \"%i\"\n",randomMode); mpd_executeCommand(connection,string); free(string);}void mpd_sendSetvolCommand(mpd_Connection * connection, int volumeChange) { char * string = malloc(strlen("setvol")+25); sprintf(string,"setvol \"%i\"\n",volumeChange); mpd_executeCommand(connection,string); free(string);}void mpd_sendVolumeCommand(mpd_Connection * connection, int volumeChange) { char * string = malloc(strlen("volume")+25); sprintf(string,"volume \"%i\"\n",volumeChange); mpd_executeCommand(connection,string); free(string);}void mpd_sendCrossfadeCommand(mpd_Connection * connection, int seconds) { char * string = malloc(strlen("crossfade")+25); sprintf(string,"crossfade \"%i\"\n",seconds); mpd_executeCommand(connection,string); free(string);}void mpd_sendPasswordCommand(mpd_Connection * connection, const char * pass) { char * sPass = mpd_sanitizeArg(pass); char * string = malloc(strlen("password")+strlen(sPass)+5); sprintf(string,"password \"%s\"\n",sPass); mpd_executeCommand(connection,string); free(string); free(sPass);}void mpd_sendCommandListBegin(mpd_Connection * connection) { if(connection->commandList) { strcpy(connection->errorStr,"already in command list mode"); connection->error = 1; return; } connection->commandList = COMMAND_LIST; mpd_executeCommand(connection,"command_list_begin\n");}void mpd_sendCommandListOkBegin(mpd_Connection * connection) { if(connection->commandList) { strcpy(connection->errorStr,"already in command list mode"); connection->error = 1; return; } connection->commandList = COMMAND_LIST_OK; mpd_executeCommand(connection,"command_list_ok_begin\n"); connection->listOks = 0;}void mpd_sendCommandListEnd(mpd_Connection * connection) { if(!connection->commandList) { strcpy(connection->errorStr,"not in command list mode"); connection->error = 1; return; } connection->commandList = 0; mpd_executeCommand(connection,"command_list_end\n");}void mpd_sendOutputsCommand(mpd_Connection * connection) { mpd_executeCommand(connection,"outputs\n");}mpd_OutputEntity * mpd_getNextOutput(mpd_Connection * connection) { mpd_OutputEntity * output = NULL; if(connection->doneProcessing || (connection->listOks && connection->doneListOk)) { return NULL; } if(connection->error) return NULL; output = malloc(sizeof(mpd_OutputEntity)); output->id = -10; output->name = NULL; output->enabled = 0; if(!connection->returnElement) mpd_getNextReturnElement(connection); while(connection->returnElement) { mpd_ReturnElement * re = connection->returnElement; if(strcmp(re->name,"outputid")==0) { if(output!=NULL && output->id>=0) return output; output->id = atoi(re->value); } else if(strcmp(re->name,"outputname")==0) { output->name = strdup(re->value); } else if(strcmp(re->name,"outputenabled")==0) { output->enabled = atoi(re->value); } mpd_getNextReturnElement(connection); if(connection->error) { free(output); return NULL; } } return output;}void mpd_sendEnableOutputCommand(mpd_Connection * connection, int outputId) { char * string = malloc(strlen("enableoutput")+25); sprintf(string,"enableoutput \"%i\"\n",outputId); mpd_executeCommand(connection,string); free(string);}void mpd_sendDisableOutputCommand(mpd_Connection * connection, int outputId) { char * string = malloc(strlen("disableoutput")+25); sprintf(string,"disableoutput \"%i\"\n",outputId); mpd_executeCommand(connection,string); free(string);}void mpd_freeOutputElement(mpd_OutputEntity * output) { free(output->name); free(output);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -