std::string Mpd::getTag(const char *_album, mpd_tag_type type) { std::string tagRet = ""; mpd_song *song; if (!mpd_search_db_songs(conn, false)) { err(); return NULL; } if (!mpd_search_add_tag_constraint(conn, MPD_OPERATOR_DEFAULT, MPD_TAG_ALBUM, _album)) { err(); return NULL; } if (!mpd_search_commit(conn)) { err(); return NULL; } if (type == MPD_TAG_UNKNOWN) { if ((song = mpd_recv_song(conn)) != NULL) { if (mpd_song_get_uri(song) != NULL) tagRet = mpd_song_get_uri(song); else tagRet = ""; } } else if ((song = mpd_recv_song(conn)) != NULL) { if (mpd_song_get_tag(song, type, 0) != NULL) tagRet = mpd_song_get_tag(song, type, 0); else tagRet = ""; } mpd_song_free(song); if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS) { err(); return NULL; } if (!mpd_response_finish(conn)) { err(); return NULL; } return tagRet; }
/* mpd functions */ bool Mpd::update(mpd_tag_type type, const char *value) { mpd_pair *pair; album.clear(); if (!mpd_search_db_tags(conn, MPD_TAG_ALBUM)) { err(); return false; } if (strcmp(value, "") != 0) if (!mpd_search_add_tag_constraint(conn, MPD_OPERATOR_DEFAULT, type, value)) { err(); return false; } if (!mpd_search_commit(conn)) { err(); return false; } while ((pair = mpd_recv_pair_tag(conn, MPD_TAG_ALBUM)) != NULL) { album.push_back(Album(pair->value)); mpd_return_pair(conn, pair); } if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS) { err(); return false; } if (!mpd_response_finish(conn)) { err(); return false; } cout << "Successful Update" << endl; for (std::vector<Album>::iterator i = album.begin(); i != album.end(); ++i) i->buildTags(); sys->sortAlbums(MPD_TAG_UNKNOWN); for (std::vector<Album>::iterator i = album.begin(); i != album.end(); ++i) i->build(); return true; }
static int fetch_items(MENU_SEARCH *menu,char *str,CLIENT_OBJECT *cli,DB_OBJECT *db) { if (!(str && strlen(str))) return 1; /* send query */ if (!mpd_search_db_songs(cli->conn,false)) clear_or_exit_on_error(cli->conn); if (!mpd_search_add_tag_constraint(cli->conn,MPD_OPERATOR_DEFAULT,MPD_TAG_TITLE,str)) clear_or_exit_on_error(cli->conn); if (!mpd_search_commit(cli->conn)) clear_or_exit_on_error(cli->conn); /* process response */ int block = 1024; menu->items = (MENU_SEARCH_ITEM*)calloc(block,sizeof(MENU_SEARCH_ITEM)); struct mpd_song *song; int i = 0; while ((song = mpd_recv_song(cli->conn))) { /* realloc if memory not enough */ if (i >= block) { block *= 2; menu->items = (MENU_SEARCH_ITEM*)realloc(menu->items,block*sizeof(MENU_SEARCH_ITEM)); } unsigned id = mpd_song_get_id(song); const char *uri = mpd_song_get_uri(song); const char *title = mpd_song_get_tag(song,MPD_TAG_TITLE,0); menu->items[i].id = id; menu->items[i].title = (char *)malloc((strlen(title)+1)*sizeof(char)); strcpy(menu->items[i].title,title); menu->items[i++].node = get_node_by_uri(db,uri); mpd_song_free(song); } if (mpd_connection_get_error(cli->conn) == MPD_ERROR_SUCCESS) mpd_response_finish(cli->conn); else clear_or_exit_on_error(cli->conn); menu->num = i; return 0; }
static void add_constraint(struct mpd_connection *conn, const struct constraint *constraint) { if (constraint->type == (enum mpd_tag_type)SEARCH_TAG_ANY) mpd_search_add_any_tag_constraint(conn, MPD_OPERATOR_DEFAULT, charset_to_utf8(constraint->query)); else if (constraint->type == (enum mpd_tag_type)SEARCH_TAG_URI) mpd_search_add_uri_constraint(conn, MPD_OPERATOR_DEFAULT, charset_to_utf8(constraint->query)); #if LIBMPDCLIENT_CHECK_VERSION(2,9,0) else if (constraint->type == (enum mpd_tag_type)SEARCH_TAG_BASE) mpd_search_add_base_constraint(conn, MPD_OPERATOR_DEFAULT, charset_to_utf8(constraint->query)); #endif else mpd_search_add_tag_constraint(conn, MPD_OPERATOR_DEFAULT, constraint->type, charset_to_utf8(constraint->query)); }
void TopWidget::updateAlbumList() { albumList.clear(); albumList << "(Any)"; mpdconfirm(mpd_search_db_tags(mpd, MPD_TAG_ALBUM)); if (selectedArtist != "(Any)") mpd_search_add_tag_constraint(mpd, MPD_OPERATOR_DEFAULT, MPD_TAG_ARTIST, selectedArtist.toUtf8().constData()); mpd_search_commit(mpd); mpd_pair * mp; while((mp = mpd_recv_pair_tag(mpd, MPD_TAG_ALBUM)) != NULL) { const QString album = mp->value; if (album != "") albumList << album; mpd_return_pair(mpd, mp); } albumListWidget->setModel(albumModel); albumModel->setStringList(albumList); parent->setTracks(Track::searchByArtist(selectedArtist)); parent->playlistChanged = true; parent->trackView->update(); parent->trackView->resetScroll(); }
int main(int argc, char *argv[]) { int opts; const char *short_opts = "t:r:b:a:p:s:h"; struct option long_opts[] = { { "title", required_argument, 0, 't' }, { "artist", required_argument, 0, 'r' }, { "album", required_argument, 0, 'b' }, { "addr", required_argument, 0, 'a' }, { "port", required_argument, 0, 'p' }, { "secret", required_argument, 0, 's' }, { "help", no_argument, 0, 'h' }, { 0, 0, 0, 0 } }; unsigned int id = 0; struct mpd_song *song = NULL; struct mpd_connection *mpd = NULL; char *mpd_addr = getenv("MPD_HOST"); int mpd_port = getenv("MPD_PORT") ? atoi(getenv("MPD_PORT")) : 0; char *mpd_pass = NULL; char *title = NULL; char *artist = NULL; char *album = NULL; if (argc == 1) { help(); return -1; } while ((opts = getopt_long(argc, argv, short_opts, long_opts, 0)) != -1) { switch (opts) { case 't': { title = optarg; break; } case 'r': { artist = optarg; break; } case 'b': { album = optarg; break; } case 'a': { mpd_addr = optarg; break; } case 'p': { mpd_port = atoi(optarg); break; } case 's': { mpd_pass = optarg; break; } default : case 'h': { help(); return -1; } } } mpd = mpd_connection_new(mpd_addr, mpd_port, 30000); CHECK_MPD_CONN(mpd); if (mpd_pass != NULL) { mpd_run_password(mpd, mpd_pass); CHECK_MPD_CONN(mpd); } mpd_search_queue_songs(mpd, false); if (title) { mpd_search_add_tag_constraint( mpd, MPD_OPERATOR_DEFAULT, MPD_TAG_TITLE, title ); } if (artist) { mpd_search_add_tag_constraint( mpd, MPD_OPERATOR_DEFAULT, MPD_TAG_ARTIST, artist ); } if (album) { mpd_search_add_tag_constraint( mpd, MPD_OPERATOR_DEFAULT, MPD_TAG_ALBUM, album ); } mpd_search_commit(mpd); song = mpd_recv_song(mpd); mpd_response_finish(mpd); if (song) { id = mpd_song_get_id(song); mpd_song_free(song); mpd_run_play_id(mpd, id); CHECK_MPD_CONN(mpd); } mpd_connection_free(mpd); return 0; }
void Connection::AddSearch(mpd_tag_type item, const std::string &str) const { checkConnection(); mpd_search_add_tag_constraint(m_connection.get(), MPD_OPERATOR_DEFAULT, item, str.c_str()); }