/** * @param mi A #MpdObj * @param path an Path to a file * * Grabs the song info for a single file. Make sure you pass an url to a song * and not a directory, that might result in strange behauviour. * * @returns a #mpd_Song */ mpd_Song * mpd_database_get_fileinfo(MpdObj *mi,const char *path) { mpd_Song *song = NULL; mpd_InfoEntity *ent = NULL; /* * Check path for availibility and length */ if(path == NULL || path[0] == '\0') { debug_printf(DEBUG_ERROR, "path == NULL || strlen(path) == 0"); return NULL; } if(!mpd_check_connected(mi)) { debug_printf(DEBUG_ERROR, "Not Connected\n"); return NULL; } /* lock, so we can work on mi->connection */ if(mpd_lock_conn(mi) != MPD_OK) { debug_printf(DEBUG_ERROR, "Failed to lock connection"); return NULL; } /* send the request */ mpd_sendListallInfoCommand(mi->connection, path); /* get the first (and only) result */ ent = mpd_getNextInfoEntity(mi->connection); /* finish and clean up libmpdclient */ mpd_finishCommand(mi->connection); /* unlock again */ if(mpd_unlock_conn(mi)) { if(ent) mpd_freeInfoEntity(ent); debug_printf(DEBUG_ERROR, "Failed to unlock"); return NULL; } if(ent == NULL) { debug_printf(DEBUG_ERROR, "Failed to grab song from mpd\n"); return NULL; } if(ent->type != MPD_INFO_ENTITY_TYPE_SONG) { mpd_freeInfoEntity(ent); debug_printf(DEBUG_ERROR, "Failed to grab correct song type from mpd, path might not be a file\n"); return NULL; } /* get the song */ song = ent->info.song; /* remove reference to song from the entity */ ent->info.song = NULL; /* free the entity */ mpd_freeInfoEntity(ent); return song; }
MpdData * mpd_database_get_directory_recursive(MpdObj *mi, const char *path) { MpdData *data = NULL; mpd_InfoEntity *ent = NULL; if(!mpd_check_connected(mi)) { debug_printf(DEBUG_WARNING,"not connected\n"); return NULL; } if(path == '\0' || path[0] == '\0') { debug_printf(DEBUG_ERROR, "argumant invalid\n"); return NULL; } if(mpd_lock_conn(mi)) { debug_printf(DEBUG_ERROR,"lock failed\n"); return NULL; } mpd_sendListallInfoCommand(mi->connection,path); while (( ent = mpd_getNextInfoEntity(mi->connection)) != NULL) { if (ent->type == MPD_INFO_ENTITY_TYPE_SONG) { data = mpd_new_data_struct_append(data); data->type = MPD_DATA_TYPE_SONG; data->song = ent->info.song; ent->info.song = NULL; } mpd_freeInfoEntity(ent); } mpd_finishCommand(mi->connection); /* unlock */ mpd_unlock_conn(mi); if(data == NULL) { return NULL; } return mpd_data_get_first(data); }
static void queue_dir(const char *path) { mpd_InfoEntity entity; struct ll { char *path; struct ll *next; } *head = 0; if (mpdc_tickle() < 0) return; mpd_sendListallInfoCommand(mpdz, path); if (mpdz->error) { mpdc_tickle(); return; } while ((mpd_getNextInfoEntity_st(&entity, mpdz))) { if (entity.type == MPD_INFO_ENTITY_TYPE_SONG) { struct ll *it, *ll = calloc(1, sizeof(struct ll)); mpd_Song *song = entity.info.song; if ((it = head)) { while (it->next) it = it->next; it->next = ll; } else head = ll; ll->path = strdup(song->file); } } mpd_finishCommand(mpdz); if (mpdz->error) mpdc_tickle(); while (head) { struct ll *o; queue_song(head->path); free(head->path); o = head->next; free(head); head = o; } }
MpdData *mpd_database_token_find(MpdObj *mi , char *string) { MpdData *data = NULL; mpd_InfoEntity *ent = NULL; regex_t ** strdata = NULL; if(!mpd_check_connected(mi)) { debug_printf(DEBUG_WARNING,"not connected\n"); return NULL; } if(mpd_lock_conn(mi)) { debug_printf(DEBUG_ERROR,"lock failed\n"); return NULL; } if(string == NULL || !strlen(string) ) { debug_printf(DEBUG_INFO, "no string found"); mpd_unlock_conn(mi); return NULL; } else{ strdata = mpd_misc_tokenize(string); } if(strdata == NULL) { mpd_unlock_conn(mi); debug_printf(DEBUG_INFO, "no split string found"); return NULL; } mpd_sendListallInfoCommand(mi->connection, "/"); while (( ent = mpd_getNextInfoEntity(mi->connection)) != NULL) { if (ent->type == MPD_INFO_ENTITY_TYPE_SONG) { int i = 0; int match = 0; int loop = 1; for(i=0; strdata[i] != NULL && loop; i++) { match = 0; if(ent->info.song->file && !regexec(strdata[i],ent->info.song->file, 0, NULL, 0)) { match = 1; } else if(ent->info.song->artist && !regexec(strdata[i],ent->info.song->artist, 0, NULL, 0)) { match = 1; } else if(ent->info.song->title && !regexec(strdata[i],ent->info.song->title, 0, NULL, 0)) { match = 1; } else if(ent->info.song->album && !regexec(strdata[i],ent->info.song->album, 0, NULL, 0)) { match = 1; } if(!match) { loop = 0; } } if(match) { data = mpd_new_data_struct_append(data); data->type = MPD_DATA_TYPE_SONG; /* data->song = mpd_songDup(ent->info.song); */ data->song = ent->info.song; ent->info.song = NULL; } } mpd_freeInfoEntity(ent); } mpd_finishCommand(mi->connection); mpd_misc_tokens_free(strdata); mpd_unlock_conn(mi); if(data == NULL) { return NULL; } return mpd_data_get_first(data); }