mirror of
https://github.com/owntone/owntone-server.git
synced 2025-04-01 18:21:31 -04:00
More mp3 scanner adds
This commit is contained in:
parent
5a7b5c3f8d
commit
621d18135e
@ -165,8 +165,14 @@ int db_add(MP3FILE *mp3file) {
|
|||||||
|
|
||||||
g=(int) pnew->mp3file.path=strdup(mp3file->path);
|
g=(int) pnew->mp3file.path=strdup(mp3file->path);
|
||||||
g = g && (pnew->mp3file.fname=strdup(mp3file->fname));
|
g = g && (pnew->mp3file.fname=strdup(mp3file->fname));
|
||||||
|
|
||||||
|
if(mp3file->artist)
|
||||||
g = g && (pnew->mp3file.artist=strdup(mp3file->artist));
|
g = g && (pnew->mp3file.artist=strdup(mp3file->artist));
|
||||||
|
|
||||||
|
if(mp3file->album)
|
||||||
g = g && (pnew->mp3file.album=strdup(mp3file->album));
|
g = g && (pnew->mp3file.album=strdup(mp3file->album));
|
||||||
|
|
||||||
|
if(mp3file->genre)
|
||||||
g = g && (pnew->mp3file.genre=strdup(mp3file->genre));
|
g = g && (pnew->mp3file.genre=strdup(mp3file->genre));
|
||||||
|
|
||||||
if(!g) {
|
if(!g) {
|
||||||
|
@ -19,12 +19,21 @@
|
|||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <limits.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include "db-memory.h"
|
#include "db-memory.h"
|
||||||
#include "mp3-scanner.h"
|
#include "mp3-scanner.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Forwards
|
||||||
|
*/
|
||||||
|
int scan_foreground(char *path);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* scan_init
|
* scan_init
|
||||||
*
|
*
|
||||||
@ -39,18 +48,65 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
int scan_init(char *path) {
|
int scan_init(char *path) {
|
||||||
MP3FILE junk={
|
if(db_is_empty()) {
|
||||||
"/tmp/x.mp3",
|
if(db_start_initial_update())
|
||||||
"Some Title",
|
return -1;
|
||||||
"Some Artist",
|
|
||||||
"Some Album",
|
|
||||||
"Some Genre",
|
|
||||||
1
|
|
||||||
};
|
|
||||||
|
|
||||||
if(db_add(&junk)) {
|
scan_foreground(path);
|
||||||
perror("db_add");
|
|
||||||
exit(EXIT_FAILURE);
|
if(db_end_initial_update())
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
/* do deferred updating */
|
||||||
|
return ENOTIMPL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* scan_foreground
|
||||||
|
*
|
||||||
|
* Do a brute force scan of a path, finding all the MP3 files there
|
||||||
|
*/
|
||||||
|
int scan_foreground(char *path) {
|
||||||
|
MP3FILE mp3file;
|
||||||
|
DIR *current;
|
||||||
|
struct dirent de;
|
||||||
|
struct dirent *pde;
|
||||||
|
int err;
|
||||||
|
char mp3_path[PATH_MAX];
|
||||||
|
|
||||||
|
if((current_dir=opendir(path)) == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
while(1) {
|
||||||
|
err=readdir_r(current_dir,&de,&pde);
|
||||||
|
if(err == -1) {
|
||||||
|
err=errno;
|
||||||
|
closedir(current);
|
||||||
|
errno=err;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!pde)
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* process the file */
|
||||||
|
if(de.d_namelen > 4) {
|
||||||
|
if(strcasecmp(".mp3",de.d_name[de.d_namelen - 4]) == 0) {
|
||||||
|
/* we found an mp3 file */
|
||||||
|
sprintf(mp3_path,"%s/%s",path,de.d_name);
|
||||||
|
memset(mp3file,0,sizeof(mp3file));
|
||||||
|
mp3file->path=mp3_path;
|
||||||
|
mp3file->fname=de.d_name;
|
||||||
|
|
||||||
|
db_add(&mp3file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
closedir(current);
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user