mirror of
				https://github.com/SuperBFG7/ympd
				synced 2025-10-31 13:53:00 +00:00 
			
		
		
		
	Fix: central search backend - MPD_API_DATABASE_SEARCH
removed: MPD_API_DATABASE_SEARCH_ADD_PLAYLIST removed: MPD_API_DATABASE_SEARCH_ADD_QUEUE
This commit is contained in:
		| @@ -135,10 +135,10 @@ | ||||
|                 </button> | ||||
|                 <div class="dropdown-menu bg-dark dropdown-menu-right px-2" id="searchqueuetag"> | ||||
|                   <h6 class="dropdown-header text-light">Search in Tag</h6> | ||||
|                   <button type="button" class="btn btn-secondary btn-block active">Any Tag</button> | ||||
|                   <button type="button" class="btn btn-secondary btn-block">Title</button> | ||||
|                   <button type="button" class="btn btn-secondary btn-block">Artist</button> | ||||
|                   <button type="button" class="btn btn-secondary btn-block">Album</button> | ||||
|                   <button type="button" class="btn btn-secondary btn-block active" data-tag="any">Any Tag</button> | ||||
|                   <button type="button" class="btn btn-secondary btn-block" data-tag="Title">Title</button> | ||||
|                   <button type="button" class="btn btn-secondary btn-block" data-tag="Artist">Artist</button> | ||||
|                   <button type="button" class="btn btn-secondary btn-block" data-tag="Album">Album</button> | ||||
|                 </div> | ||||
|               </div> | ||||
|             </div> | ||||
| @@ -438,10 +438,10 @@ | ||||
|                 </button> | ||||
|                 <div class="dropdown-menu bg-dark dropdown-menu-right px-2" id="searchtags"> | ||||
|                   <h6 class="dropdown-header text-light">Search in Tag</h6> | ||||
|                   <button type="button" class="btn btn-secondary active btn-block">Any Tag</button> | ||||
|                   <button type="button" class="btn btn-secondary btn-block">Title</button> | ||||
|                   <button type="button" class="btn btn-secondary btn-block">Artist</button> | ||||
|                   <button type="button" class="btn btn-secondary btn-block">Album</button> | ||||
|                   <button type="button" class="btn btn-secondary active btn-block" data-tag="any">Any Tag</button> | ||||
|                   <button type="button" class="btn btn-secondary btn-block" data-tag="Title">Title</button> | ||||
|                   <button type="button" class="btn btn-secondary btn-block" data-tag="Artist">Artist</button> | ||||
|                   <button type="button" class="btn btn-secondary btn-block" data-tag="Album">Album</button> | ||||
|                 </div> | ||||
|               </div> | ||||
|             </div> | ||||
|   | ||||
| @@ -36,7 +36,7 @@ var dragEl; | ||||
|  | ||||
| var app = {}; | ||||
| app.apps = { "Playback": { "state": "0/-/", "scrollPos": 0 }, | ||||
|              "Queue": 	 { "state": "0/Any Tag/", "scrollPos": 0 }, | ||||
|              "Queue": 	 { "state": "0/any/", "scrollPos": 0 }, | ||||
|              "Browse":   {  | ||||
|                   "active": "Database",  | ||||
|                   "tabs":  { "Filesystem": { "state": "0/-/", "scrollPos": 0 }, | ||||
| @@ -54,7 +54,7 @@ app.apps = { "Playback": { "state": "0/-/", "scrollPos": 0 }, | ||||
|                              } | ||||
|                   } | ||||
|              }, | ||||
|              "Search": { "state": "0/Any Tag/", "scrollPos": 0 } | ||||
|              "Search": { "state": "0/any/", "scrollPos": 0 } | ||||
|            }; | ||||
|             | ||||
| app.current = { "app": "Playback", "tab": undefined, "view": undefined, "page": 0, "filter": "", "search": "", "scrollPos": 0 }; | ||||
| @@ -197,7 +197,7 @@ function appRoute() { | ||||
|         var btnsLen = btns.length; | ||||
|         for (var i = 0; i < btnsLen; i++) { | ||||
|             btns[i].classList.remove('active'); | ||||
|             if (btns[i].innerText == app.current.filter) {  | ||||
|             if (btns[i].getAttribute('data-tag') == app.current.filter) {  | ||||
|                 btns[i].classList.add('active');  | ||||
|                 document.getElementById('searchqueuetagdesc').innerText = btns[i].innerText; | ||||
|             } | ||||
| @@ -266,7 +266,7 @@ function appRoute() { | ||||
|         } | ||||
|  | ||||
|         if (app.current.search.length >= 2) { | ||||
|             sendAPI({"cmd": "MPD_API_DATABASE_SEARCH", "data": { "mpdtag": app.current.filter, "offset": app.current.page, "searchstr": app.current.search}}, parseSearch); | ||||
|             sendAPI({"cmd": "MPD_API_DATABASE_SEARCH", "data": { "plist": "", "offset": app.current.page, "filter": app.current.filter, "searchstr": app.current.search}}, parseSearch); | ||||
|         } else { | ||||
|             document.getElementById('SearchList').getElementsByTagName('tbody')[0].innerHTML = ''; | ||||
|             document.getElementById('searchAddAllSongs').setAttribute('disabled', 'disabled'); | ||||
| @@ -280,7 +280,7 @@ function appRoute() { | ||||
|         var btnsLen = btns.length; | ||||
|         for (var i = 0; i < btnsLen; i++) { | ||||
|             btns[i].classList.remove('active'); | ||||
|             if (btns[i].innerText == app.current.filter) {  | ||||
|             if (btns[i].getAttribute('data-tag') == app.current.filter) {  | ||||
|                 btns[i].classList.add('active');  | ||||
|                 document.getElementById('searchtagsdesc').innerText = btns[i].innerText; | ||||
|             } | ||||
| @@ -486,7 +486,7 @@ function appInit() { | ||||
|  | ||||
|     document.getElementById('searchtags').addEventListener('click', function(event) { | ||||
|         if (event.target.nodeName == 'BUTTON') | ||||
|             appGoto(app.current.app, app.current.tab, app.current.view, '0/' + event.target.innerText + '/' + app.current.search);             | ||||
|             appGoto(app.current.app, app.current.tab, app.current.view, '0/' + event.target.getAttribute('data-tag') + '/' + app.current.search);             | ||||
|     }, false); | ||||
|  | ||||
|     document.getElementById('searchqueuestr').addEventListener('keyup', function(event) { | ||||
| @@ -495,7 +495,7 @@ function appInit() { | ||||
|  | ||||
|     document.getElementById('searchqueuetag').addEventListener('click', function (event) { | ||||
|         if (event.target.nodeName == 'BUTTON') | ||||
|             appGoto(app.current.app, app.current.tab, app.current.view, app.current.page + '/' + event.target.innerText + '/' + app.current.search); | ||||
|             appGoto(app.current.app, app.current.tab, app.current.view, app.current.page + '/' + event.target.getAttribute('data-tag') + '/' + app.current.search); | ||||
|     }, false); | ||||
|  | ||||
|     document.getElementById('search').addEventListener('submit', function () { | ||||
| @@ -980,7 +980,7 @@ function parseState(obj) { | ||||
|  | ||||
| function getQueue() { | ||||
|     if (app.current.search.length >= 2)  | ||||
|         sendAPI({"cmd": "MPD_API_QUEUE_SEARCH", "data": {"mpdtag": app.current.filter, "offset": app.current.page, "searchstr": app.current.search}}, parseQueue); | ||||
|         sendAPI({"cmd": "MPD_API_QUEUE_SEARCH", "data": {"filter": app.current.filter, "offset": app.current.page, "searchstr": app.current.search}}, parseQueue); | ||||
|     else { | ||||
|         sendAPI({"cmd": "MPD_API_QUEUE_LIST", "data": {"offset": app.current.page}}, parseQueue); | ||||
|     } | ||||
| @@ -1890,18 +1890,14 @@ function addAllFromBrowse() { | ||||
|  | ||||
| function addAllFromSearch() { | ||||
|     if (app.current.search.length >= 2) { | ||||
|         sendAPI({"cmd": "MPD_API_DATABASE_SEARCH_ADD_QUEUE", "data":{"filter": app.current.filter, "searchstr": app.current.search}}); | ||||
|         sendAPI({"cmd": "MPD_API_DATABASE_SEARCH", "data": {"plist": "queue", "filter": app.current.filter, "searchstr": app.current.search, "offset": 0}}); | ||||
|         showNotification('Added '+ parseInt(document.getElementById('panel-heading-search').innerText) +' songs from search', '', '', 'success'); | ||||
|     } | ||||
| } | ||||
|  | ||||
| function addAllFromSearchPlist(plist) { | ||||
|     if (app.current.search.length >= 2) { | ||||
|         var filter = app.current.filter; | ||||
|         if (filter == 'Any Tag') | ||||
|             filter = 'any'; | ||||
|              | ||||
|         sendAPI({"cmd": "MPD_API_DATABASE_SEARCH_ADD_PLAYLIST", "data":{"plist": plist, "filter": filter, "searchstr": app.current.search}}); | ||||
|         sendAPI({"cmd": "MPD_API_DATABASE_SEARCH", "data": {"plist": plist, "filter": app.current.filter, "searchstr": app.current.search, "offset": 0}}); | ||||
|         showNotification('Added '+ parseInt(document.getElementById('panel-heading-search').innerText) +' songs from search to ' + plist, '', '', 'success'); | ||||
|     } | ||||
| } | ||||
|   | ||||
							
								
								
									
										144
									
								
								src/mpd_client.c
									
									
									
									
									
								
							
							
						
						
									
										144
									
								
								src/mpd_client.c
									
									
									
									
									
								
							| @@ -431,38 +431,17 @@ void callback_mympd(struct mg_connection *nc, const struct mg_str msg) { | ||||
|             } | ||||
|             break; | ||||
|         case MPD_API_QUEUE_SEARCH: | ||||
|             je = json_scanf(msg.p, msg.len, "{data: {offset:%u, mpdtag:%Q, searchstr:%Q}}", &uint_buf1, &p_charbuf1, &p_charbuf2); | ||||
|             je = json_scanf(msg.p, msg.len, "{data: {offset:%u, filter:%Q, searchstr:%Q}}", &uint_buf1, &p_charbuf1, &p_charbuf2); | ||||
|             if (je == 3) { | ||||
|                 n = mympd_search_queue(mpd.buf, p_charbuf1, uint_buf1, p_charbuf2); | ||||
|                 free(p_charbuf1); | ||||
|                 free(p_charbuf2); | ||||
|             } | ||||
|             break;             | ||||
|         case MPD_API_DATABASE_SEARCH_ADD_QUEUE: | ||||
|             je = json_scanf(msg.p, msg.len, "{data: {filter:%Q, searchstr:%Q}}", &p_charbuf1, &p_charbuf2); | ||||
|             if (je == 2) { | ||||
|                 n = mympd_search_add(mpd.buf, p_charbuf1, p_charbuf2); | ||||
|                 free(p_charbuf1); | ||||
|                 free(p_charbuf2); | ||||
|                 if (n == 0) | ||||
|                     n = snprintf(mpd.buf, MAX_SIZE, "{\"type\": \"result\", \"data\": \"ok\"}"); | ||||
|             } | ||||
|             break; | ||||
|         case MPD_API_DATABASE_SEARCH_ADD_PLAYLIST: | ||||
|             je = json_scanf(msg.p, msg.len, "{data: {plist:%Q, filter:%Q, searchstr:%Q}}", &p_charbuf1, &p_charbuf2, &p_charbuf3); | ||||
|             if (je == 3) { | ||||
|                 n = mympd_search_add_plist(p_charbuf1, p_charbuf2, p_charbuf3); | ||||
|                 free(p_charbuf1); | ||||
|                 free(p_charbuf2); | ||||
|                 free(p_charbuf3); | ||||
|                 if (n == 0) | ||||
|                     n = snprintf(mpd.buf, MAX_SIZE, "{\"type\": \"result\", \"data\": \"ok\"}"); | ||||
|             } | ||||
|             break;             | ||||
|         case MPD_API_DATABASE_SEARCH: | ||||
|             je = json_scanf(msg.p, msg.len, "{data: {offset:%u, mpdtag:%Q, searchstr:%Q}}", &uint_buf1, &p_charbuf1, &p_charbuf2); | ||||
|             if (je == 3) { | ||||
|                 n = mympd_search(mpd.buf, p_charbuf1, uint_buf1, p_charbuf2); | ||||
|             je = json_scanf(msg.p, msg.len, "{data: {searchstr:%Q, filter:%Q, plist:%Q, offset:%u}}", &p_charbuf1, &p_charbuf2, &p_charbuf3, &uint_buf1); | ||||
|             if (je == 4) { | ||||
|                 n = mympd_search(mpd.buf, p_charbuf1, p_charbuf2, p_charbuf3, uint_buf1); | ||||
|                 free(p_charbuf1); | ||||
|                 free(p_charbuf2); | ||||
|             } | ||||
| @@ -1503,31 +1482,29 @@ int mympd_put_playlist_list(char *buffer, char *uri, unsigned int offset, char * | ||||
|     return len; | ||||
| } | ||||
|  | ||||
| int mympd_search(char *buffer, char *mpdtagtype, unsigned int offset, char *searchstr) { | ||||
| int mympd_search(char *buffer, char *searchstr, char *filter, char *plist, unsigned int offset) { | ||||
|     struct mpd_song *song; | ||||
|     unsigned long entity_count = 0; | ||||
|     unsigned long entities_returned = 0; | ||||
|     int len; | ||||
|     struct json_out out = JSON_OUT_BUF(buffer, MAX_SIZE); | ||||
|  | ||||
|     if (mpd_search_db_songs(mpd.conn, false) == false) | ||||
|         RETURN_ERROR_AND_RECOVER("mpd_search_db_songs"); | ||||
|      | ||||
|     if (mpd_tag_name_parse(mpdtagtype) != MPD_TAG_UNKNOWN) { | ||||
|        if (mpd_search_add_tag_constraint(mpd.conn, MPD_OPERATOR_DEFAULT, mpd_tag_name_parse(mpdtagtype), searchstr) == false) | ||||
|             RETURN_ERROR_AND_RECOVER("mpd_search_add_tag_constraint"); | ||||
|     if (strcmp(plist, "") == 0) { | ||||
|         if (mpd_send_command(mpd.conn, "search", filter, searchstr, NULL) == false) | ||||
|             RETURN_ERROR_AND_RECOVER("mpd_search"); | ||||
|         len = json_printf(&out, "{type: search, data: ["); | ||||
|     } | ||||
|     else if (strcmp(plist, "queue") == 0) { | ||||
|         if (mpd_send_command(mpd.conn, "searchadd", filter, searchstr, NULL) == false) | ||||
|             RETURN_ERROR_AND_RECOVER("mpd_searchadd"); | ||||
|     } | ||||
|     else { | ||||
|         if (mpd_search_add_any_tag_constraint(mpd.conn, MPD_OPERATOR_DEFAULT, searchstr) == false) | ||||
|             RETURN_ERROR_AND_RECOVER("mpd_search_add_any_tag_constraint");         | ||||
|     }     | ||||
|          | ||||
|     if (mpd_search_commit(mpd.conn) == false) | ||||
|         RETURN_ERROR_AND_RECOVER("mpd_search_commit"); | ||||
|     else { | ||||
|         len = json_printf(&out, "{type: search, data: ["); | ||||
|         if (mpd_send_command(mpd.conn, "searchaddpl", plist, filter, searchstr, NULL) == false) | ||||
|             RETURN_ERROR_AND_RECOVER("mpd_searchaddpl"); | ||||
|     } | ||||
|  | ||||
|         while((song = mpd_recv_song(mpd.conn)) != NULL) { | ||||
|     if (strcmp(plist, "") == 0) { | ||||
|         while ((song = mpd_recv_song(mpd.conn)) != NULL) { | ||||
|             entity_count ++; | ||||
|             if (entity_count > offset && entity_count <= offset + MAX_ELEMENTS_PER_PAGE) { | ||||
|                 if (entities_returned ++)  | ||||
| @@ -1543,59 +1520,20 @@ int mympd_search(char *buffer, char *mpdtagtype, unsigned int offset, char *sear | ||||
|             } | ||||
|             mpd_song_free(song); | ||||
|         } | ||||
|     } | ||||
|     else | ||||
|         mpd_response_finish(mpd.conn); | ||||
|  | ||||
|         len += json_printf(&out, "], totalEntities: %d, offset: %d, returnedEntities: %d, mpdtagtype: %Q}", | ||||
|     if (strcmp(plist, "") == 0) { | ||||
|         len += json_printf(&out, "], totalEntities: %d, offset: %d, returnedEntities: %d, searchstr: %Q}", | ||||
|             entity_count, | ||||
|             offset, | ||||
|             entities_returned, | ||||
|             mpdtagtype | ||||
|             searchstr | ||||
|         ); | ||||
|     } | ||||
|  | ||||
|     if (len > MAX_SIZE) | ||||
|         printf("Buffer truncated\n"); | ||||
|     return len; | ||||
| } | ||||
|  | ||||
| int mympd_search_add(char *buffer, char *mpdtagtype, char *searchstr) { | ||||
|     int len = 0; | ||||
|     struct mpd_song *song; | ||||
|     struct json_out out = JSON_OUT_BUF(buffer, MAX_SIZE); | ||||
|  | ||||
|     if (mpd_search_add_db_songs(mpd.conn, false) == false) { | ||||
|         RETURN_ERROR_AND_RECOVER("mpd_search_add_db_songs"); | ||||
|     } | ||||
|      | ||||
|     if (mpd_tag_name_parse(mpdtagtype) != MPD_TAG_UNKNOWN) { | ||||
|        if (mpd_search_add_tag_constraint(mpd.conn, MPD_OPERATOR_DEFAULT, mpd_tag_name_parse(mpdtagtype), searchstr) == false) | ||||
|             RETURN_ERROR_AND_RECOVER("mpd_search_add_tag_constraint"); | ||||
|     } | ||||
|     else { | ||||
|         if (mpd_search_add_any_tag_constraint(mpd.conn, MPD_OPERATOR_DEFAULT, searchstr) == false) | ||||
|             RETURN_ERROR_AND_RECOVER("mpd_search_add_any_tag_constraint");         | ||||
|     }     | ||||
|          | ||||
|     if (mpd_search_commit(mpd.conn) == false) | ||||
|         RETURN_ERROR_AND_RECOVER("mpd_search_commit"); | ||||
|      | ||||
|     while((song = mpd_recv_song(mpd.conn)) != NULL) { | ||||
|         mpd_song_free(song); | ||||
|     } | ||||
|          | ||||
|     if (len > MAX_SIZE) | ||||
|         printf("Buffer truncated\n"); | ||||
|     return len; | ||||
| } | ||||
|  | ||||
| int mympd_search_add_plist(char *plist, char *mpdtagtype, char *searchstr) { | ||||
|     int len = 0; | ||||
|     struct mpd_pair *pair;     | ||||
|  | ||||
|     mpd_send_command(mpd.conn, "searchaddpl", plist, mpdtagtype, searchstr, NULL); | ||||
|  | ||||
|     while ((pair = mpd_recv_pair(mpd.conn)) != NULL) { | ||||
|         mpd_return_pair(mpd.conn, pair); | ||||
|     }     | ||||
|     }  | ||||
|     else | ||||
|         len = json_printf(&out, "{type: result, data: ok}"); | ||||
|  | ||||
|     if (len > MAX_SIZE) | ||||
|         printf("Buffer truncated\n"); | ||||
| @@ -1657,20 +1595,20 @@ int mympd_search_queue(char *buffer, char *mpdtagtype, unsigned int offset, char | ||||
|         len = json_printf(&out, "{type: queuesearch, data: ["); | ||||
|  | ||||
|         while((song = mpd_recv_song(mpd.conn)) != NULL) { | ||||
|           entity_count ++; | ||||
|           if (entity_count > offset && entity_count <= offset + MAX_ELEMENTS_PER_PAGE) { | ||||
|             if (entities_returned ++) | ||||
|                 len += json_printf(&out, ", "); | ||||
|             len += json_printf(&out, "{type: song, id: %d, pos: %d, album: %Q, artist: %Q, duration: %d, title: %Q}", | ||||
|                 mpd_song_get_id(song), | ||||
|                 mpd_song_get_pos(song), | ||||
|                 mympd_get_tag(song, MPD_TAG_ALBUM), | ||||
|                 mympd_get_tag(song, MPD_TAG_ARTIST), | ||||
|                 mpd_song_get_duration(song), | ||||
|                 mympd_get_tag(song, MPD_TAG_TITLE) | ||||
|             ); | ||||
|             mpd_song_free(song); | ||||
|           } | ||||
|             entity_count ++; | ||||
|             if (entity_count > offset && entity_count <= offset + MAX_ELEMENTS_PER_PAGE) { | ||||
|                 if (entities_returned ++) | ||||
|                     len += json_printf(&out, ", "); | ||||
|                 len += json_printf(&out, "{type: song, id: %d, pos: %d, album: %Q, artist: %Q, duration: %d, title: %Q}", | ||||
|                     mpd_song_get_id(song), | ||||
|                     mpd_song_get_pos(song), | ||||
|                     mympd_get_tag(song, MPD_TAG_ALBUM), | ||||
|                     mympd_get_tag(song, MPD_TAG_ARTIST), | ||||
|                     mpd_song_get_duration(song), | ||||
|                     mympd_get_tag(song, MPD_TAG_TITLE) | ||||
|                 ); | ||||
|                 mpd_song_free(song); | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         len += json_printf(&out, "], totalEntities: %d, offset: %d, returnedEntities: %d, mpdtagtype: %Q}", | ||||
|   | ||||
| @@ -72,8 +72,6 @@ | ||||
|     X(MPD_API_PLAYLIST_RM_TRACK) \ | ||||
|     X(MPD_API_PLAYLIST_LIST) \ | ||||
|     X(MPD_API_PLAYLIST_CONTENT_LIST) \ | ||||
|     X(MPD_API_DATABASE_SEARCH_ADD_PLAYLIST) \ | ||||
|     X(MPD_API_DATABASE_SEARCH_ADD_QUEUE) \ | ||||
|     X(MPD_API_DATABASE_SEARCH) \ | ||||
|     X(MPD_API_DATABASE_UPDATE) \ | ||||
|     X(MPD_API_DATABASE_FILESYSTEM_LIST) \ | ||||
| @@ -177,9 +175,7 @@ int mympd_put_outputs(char *buffer); | ||||
| int mympd_put_current_song(char *buffer); | ||||
| int mympd_put_queue(char *buffer, unsigned int offset, unsigned *queue_version, unsigned *queue_length); | ||||
| int mympd_put_browse(char *buffer, char *path, unsigned int offset, char *filter); | ||||
| int mympd_search(char *buffer, char *mpdtagtype, unsigned int offset, char *searchstr); | ||||
| int mympd_search_add(char *buffer, char *mpdtagtype, char *searchstr); | ||||
| int mympd_search_add_plist(char *plist, char *mpdtagtype, char *searchstr); | ||||
| int mympd_search(char *buffer, char *searchstr, char *filter, char *plist, unsigned int offset); | ||||
| int mympd_search_queue(char *buffer, char *mpdtagtype, unsigned int offset, char *searchstr); | ||||
| int mympd_put_welcome(char *buffer); | ||||
| int mympd_put_stats(char *buffer); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 jcorporation
					jcorporation