Make script-based transcoding work on rsp

This commit is contained in:
Ron Pedde 2006-05-19 04:50:45 +00:00
parent 430b0ef9a4
commit aca2f7701f
7 changed files with 88 additions and 15 deletions

View File

@ -409,47 +409,47 @@ int db_sqlite2_insert_id(void) {
char *db_sqlite2_initial1 = char *db_sqlite2_initial1 =
"create table songs (\n" "create table songs (\n"
" id INTEGER PRIMARY KEY NOT NULL,\n" " id INTEGER PRIMARY KEY NOT NULL,\n" /* 0 */
" path VARCHAR(4096) UNIQUE NOT NULL,\n" " path VARCHAR(4096) UNIQUE NOT NULL,\n"
" fname VARCHAR(255) NOT NULL,\n" " fname VARCHAR(255) NOT NULL,\n"
" title VARCHAR(1024) DEFAULT NULL,\n" " title VARCHAR(1024) DEFAULT NULL,\n"
" artist VARCHAR(1024) DEFAULT NULL,\n" " artist VARCHAR(1024) DEFAULT NULL,\n"
" album VARCHAR(1024) DEFAULT NULL,\n" " album VARCHAR(1024) DEFAULT NULL,\n" /* 5 */
" genre VARCHAR(255) DEFAULT NULL,\n" " genre VARCHAR(255) DEFAULT NULL,\n"
" comment VARCHAR(4096) DEFAULT NULL,\n" " comment VARCHAR(4096) DEFAULT NULL,\n"
" type VARCHAR(255) DEFAULT NULL,\n" " type VARCHAR(255) DEFAULT NULL,\n"
" composer VARCHAR(1024) DEFAULT NULL,\n" " composer VARCHAR(1024) DEFAULT NULL,\n"
" orchestra VARCHAR(1024) DEFAULT NULL,\n" " orchestra VARCHAR(1024) DEFAULT NULL,\n" /* 10 */
" conductor VARCHAR(1024) DEFAULT NULL,\n" " conductor VARCHAR(1024) DEFAULT NULL,\n"
" grouping VARCHAR(1024) DEFAULT NULL,\n" " grouping VARCHAR(1024) DEFAULT NULL,\n"
" url VARCHAR(1024) DEFAULT NULL,\n" " url VARCHAR(1024) DEFAULT NULL,\n"
" bitrate INTEGER DEFAULT 0,\n" " bitrate INTEGER DEFAULT 0,\n"
" samplerate INTEGER DEFAULT 0,\n" " samplerate INTEGER DEFAULT 0,\n" /* 15 */
" song_length INTEGER DEFAULT 0,\n" " song_length INTEGER DEFAULT 0,\n"
" file_size INTEGER DEFAULT 0,\n" " file_size INTEGER DEFAULT 0,\n"
" year INTEGER DEFAULT 0,\n" " year INTEGER DEFAULT 0,\n"
" track INTEGER DEFAULT 0,\n" " track INTEGER DEFAULT 0,\n"
" total_tracks INTEGER DEFAULT 0,\n" " total_tracks INTEGER DEFAULT 0,\n" /* 20 */
" disc INTEGER DEFAULT 0,\n" " disc INTEGER DEFAULT 0,\n"
" total_discs INTEGER DEFAULT 0,\n" " total_discs INTEGER DEFAULT 0,\n"
" bpm INTEGER DEFAULT 0,\n" " bpm INTEGER DEFAULT 0,\n"
" compilation INTEGER DEFAULT 0,\n" " compilation INTEGER DEFAULT 0,\n"
" rating INTEGER DEFAULT 0,\n" " rating INTEGER DEFAULT 0,\n" /* 25 */
" play_count INTEGER DEFAULT 0,\n" " play_count INTEGER DEFAULT 0,\n"
" data_kind INTEGER DEFAULT 0,\n" " data_kind INTEGER DEFAULT 0,\n"
" item_kind INTEGER DEFAULT 0,\n" " item_kind INTEGER DEFAULT 0,\n"
" description INTEGER DEFAULT 0,\n" " description INTEGER DEFAULT 0,\n"
" time_added INTEGER DEFAULT 0,\n" " time_added INTEGER DEFAULT 0,\n" /* 30 */
" time_modified INTEGER DEFAULT 0,\n" " time_modified INTEGER DEFAULT 0,\n"
" time_played INTEGER DEFAULT 0,\n" " time_played INTEGER DEFAULT 0,\n"
" db_timestamp INTEGER DEFAULT 0,\n" " db_timestamp INTEGER DEFAULT 0,\n"
" disabled INTEGER DEFAULT 0,\n" " disabled INTEGER DEFAULT 0,\n"
" sample_count INTEGER DEFAULT 0,\n" " sample_count INTEGER DEFAULT 0,\n" /* 35 */
" force_update INTEGER DEFAULT 0,\n" " force_update INTEGER DEFAULT 0,\n"
" codectype VARCHAR(5) DEFAULT NULL,\n" " codectype VARCHAR(5) DEFAULT NULL,\n"
" idx INTEGER NOT NULL,\n" " idx INTEGER NOT NULL,\n"
" has_video INTEGER DEFAULT 0,\n" " has_video INTEGER DEFAULT 0,\n"
" contentrating INTEGER DEFAULT 0\n" " contentrating INTEGER DEFAULT 0\n" /* 40 */
");\n" ");\n"
"create table playlistitems (\n" "create table playlistitems (\n"
" id INTEGER PRIMARY KEY NOT NULL,\n" " id INTEGER PRIMARY KEY NOT NULL,\n"

View File

@ -91,7 +91,7 @@ int pi_db_enum_start(char **pe, DBQUERYINFO *pinfo);
int pi_db_enum_fetch_row(char **pe, char ***row, DBQUERYINFO *pinfo); int pi_db_enum_fetch_row(char **pe, char ***row, DBQUERYINFO *pinfo);
int pi_db_enum_end(char **pe); int pi_db_enum_end(char **pe);
void pi_stream(WS_CONNINFO *pwsc, DBQUERYINFO *pqi, char *id); void pi_stream(WS_CONNINFO *pwsc, DBQUERYINFO *pqi, char *id);
void pi_conf_dispose_string(char *str);
int pi_sp_parse(PARSETREE tree, char *term); int pi_sp_parse(PARSETREE tree, char *term);
PLUGIN_INPUT_FN pi = { PLUGIN_INPUT_FN pi = {
@ -119,9 +119,13 @@ PLUGIN_INPUT_FN pi = {
sp_init, sp_init,
pi_sp_parse, pi_sp_parse,
sp_dispose, sp_dispose,
sp_get_error sp_get_error,
conf_alloc_string,
pi_conf_dispose_string
}; };
/** /**
* initialize stuff for plugins * initialize stuff for plugins
* *
@ -582,3 +586,7 @@ void pi_stream(WS_CONNINFO *pwsc, DBQUERYINFO *pqi, char *id) {
int pi_sp_parse(PARSETREE tree, char *term) { int pi_sp_parse(PARSETREE tree, char *term) {
return sp_parse(tree, term, 0); return sp_parse(tree, term, 0);
} }
void pi_conf_dispose_string(char *str) {
free(str);
}

View File

@ -115,6 +115,9 @@ typedef struct tag_plugin_input_fn {
int (*sp_parse)(PARSETREE tree, char *term); int (*sp_parse)(PARSETREE tree, char *term);
int (*sp_dispose)(PARSETREE tree); int (*sp_dispose)(PARSETREE tree);
char* (*sp_get_error)(PARSETREE tree); char* (*sp_get_error)(PARSETREE tree);
char *(*conf_alloc_string)(char *section, char *key, char *dflt);
void (*conf_dispose_string)(char *str);
} PLUGIN_INPUT_FN; } PLUGIN_INPUT_FN;
#endif /* _PLUGIN_H_ */ #endif /* _PLUGIN_H_ */

View File

@ -191,6 +191,9 @@ typedef struct tag_plugin_input_fn {
int (*sp_parse)(PARSETREE tree, char *term); int (*sp_parse)(PARSETREE tree, char *term);
int (*sp_dispose)(PARSETREE tree); int (*sp_dispose)(PARSETREE tree);
char* (*sp_get_error)(PARSETREE tree); char* (*sp_get_error)(PARSETREE tree);
char *(*conf_alloc_string)(char *, char *, char *);
void (*conf_dispose_string)(char *);
} PLUGIN_INPUT_FN; } PLUGIN_INPUT_FN;

View File

@ -323,6 +323,23 @@ void rsp_playlist(WS_CONNINFO *pwsc, DBQUERYINFO *pqi) {
int type; int type;
char *query; char *query;
char *estr = NULL; char *estr = NULL;
char *transcode_codecs;
int transcode;
int samplerate;
// char *user_agent;
/*
user_agent = infn->ws_getrequestheader(pwsc,"user-agent");
if(user_agent) {
if(strncmp(user_agent,"iTunes",6)==0) {
trancode_codecs = "wma,ogg,flac,mpc";
} else if(strncmp(user_agent,"Roku",4)==0) {
transcode_codecs = "ogg,flac,mpc,alac";
} else {
transcode_codecs = "wma,ogg,flac,mpc,alac";
}
}
*/
query = infn->ws_getvar(pwsc,"query"); query = infn->ws_getvar(pwsc,"query");
if(query) { if(query) {
@ -381,6 +398,8 @@ void rsp_playlist(WS_CONNINFO *pwsc, DBQUERYINFO *pqi) {
returned = pqi->specifiedtotalcount - pqi->index_low; returned = pqi->specifiedtotalcount - pqi->index_low;
} }
transcode_codecs = infn->conf_alloc_string("general","ssc_codectypes","");
xml_push(pxml,"response"); xml_push(pxml,"response");
xml_push(pxml,"status"); xml_push(pxml,"status");
xml_output(pxml,"errorcode","0"); xml_output(pxml,"errorcode","0");
@ -394,11 +413,43 @@ void rsp_playlist(WS_CONNINFO *pwsc, DBQUERYINFO *pqi) {
while((infn->db_enum_fetch_row(NULL,&row,pqi) == 0) && (row)) { while((infn->db_enum_fetch_row(NULL,&row,pqi) == 0) && (row)) {
xml_push(pxml,"item"); xml_push(pxml,"item");
rowindex=0; rowindex=0;
transcode = 0;
if(strstr(transcode_codecs,row[37])) /* FIXME: ticket #21 */
transcode = 1;
while(rsp_fields[rowindex].name) { while(rsp_fields[rowindex].name) {
if((rsp_fields[rowindex].flags & type) && if((rsp_fields[rowindex].flags & type) &&
(row[rowindex] && strlen(row[rowindex]))) { (row[rowindex] && strlen(row[rowindex]))) {
if(transcode) {
switch(rowindex) {
case 8:
xml_output(pxml,rsp_fields[rowindex].name,"%s","wav");
break;
case 29:
xml_output(pxml,rsp_fields[rowindex].name,"%s",
"wav audio file");
break;
case 15:
samplerate = atoi(row[15]);
if(samplerate) {
samplerate = (samplerate * 4 * 8)/1000;
}
xml_output(pxml,rsp_fields[rowindex].name,"%d",
samplerate);
break;
case 37:
xml_output(pxml,rsp_fields[rowindex].name,"%s","wav");
break;
default:
xml_output(pxml,rsp_fields[rowindex].name,"%s", xml_output(pxml,rsp_fields[rowindex].name,"%s",
row[rowindex]); row[rowindex]);
break;
}
} else {
xml_output(pxml,rsp_fields[rowindex].name,"%s",
row[rowindex]);
}
} }
rowindex++; rowindex++;
} }
@ -406,6 +457,7 @@ void rsp_playlist(WS_CONNINFO *pwsc, DBQUERYINFO *pqi) {
} }
infn->db_enum_end(NULL); infn->db_enum_end(NULL);
infn->conf_dispose_string(transcode_codecs);
xml_pop(pxml); /* items */ xml_pop(pxml); /* items */
xml_pop(pxml); /* response */ xml_pop(pxml); /* response */

View File

@ -102,8 +102,10 @@ void dump_mp3(MP3FILE *pmp3) {
printf("orchestra.....: %s\n",pmp3->orchestra); printf("orchestra.....: %s\n",pmp3->orchestra);
printf("conductor.....: %s\n",pmp3->conductor); printf("conductor.....: %s\n",pmp3->conductor);
printf("grouping......: %s\n",pmp3->grouping); printf("grouping......: %s\n",pmp3->grouping);
printf("year..........: %d\n",pmp3->year);
printf("url...........: %s\n",pmp3->url); printf("url...........: %s\n",pmp3->url);
printf("description...: %s\n",pmp3->description);
printf("codectype.....: %s\n",pmp3->codectype);
printf("year..........: %d\n",pmp3->year);
printf("bitrate.......: %dkb\n",pmp3->bitrate); printf("bitrate.......: %dkb\n",pmp3->bitrate);
printf("samplerate....: %d\n",pmp3->samplerate); printf("samplerate....: %d\n",pmp3->samplerate);
@ -114,6 +116,11 @@ void dump_mp3(MP3FILE *pmp3) {
printf("disc..........: %d of %d\n",pmp3->disc,pmp3->total_discs); printf("disc..........: %d of %d\n",pmp3->disc,pmp3->total_discs);
printf("compilation...: %d\n",pmp3->compilation); printf("compilation...: %d\n",pmp3->compilation);
printf("rating........: %d\n",pmp3->rating);
printf("disabled......: %d\n",pmp3->disabled);
printf("bpm...........: %d\n",pmp3->bpm);
printf("has_video.....: %d\n",pmp3->has_video);
} }