2006-11-14 00:29:32 -05:00
|
|
|
/*
|
2005-06-01 10:40:28 -04:00
|
|
|
* Copyright (C) 2003 Ron Pedde (ron@pedde.com)
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <fcntl.h>
|
2006-11-14 00:29:32 -05:00
|
|
|
#ifdef HAVE_STDINT_H
|
|
|
|
#include <stdint.h>
|
|
|
|
#endif
|
2005-06-01 10:40:28 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2005-06-01 10:55:10 -04:00
|
|
|
#include <string.h>
|
2005-06-01 10:40:28 -04:00
|
|
|
|
2007-01-16 20:06:16 -05:00
|
|
|
#include "daapd.h"
|
2005-06-01 10:40:28 -04:00
|
|
|
#include "err.h"
|
|
|
|
#include "mp3-scanner.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get info from a "url" file -- a media stream file.
|
|
|
|
* This should really get more metainfo, but I'll leave that
|
|
|
|
* to later.
|
2006-11-14 00:29:32 -05:00
|
|
|
*
|
2005-06-01 10:40:28 -04:00
|
|
|
* @param filename .url file to process
|
|
|
|
* @param pmp3 MP3FILE structure that must be filled
|
2005-06-01 22:26:04 -04:00
|
|
|
* @returns TRUE if file should be added to db, FALSE otherwise
|
2005-06-01 10:40:28 -04:00
|
|
|
*/
|
|
|
|
int scan_get_urlinfo(char *filename, MP3FILE *pmp3) {
|
2007-07-31 00:34:33 -04:00
|
|
|
IOHANDLE hfile;
|
2005-06-01 10:40:28 -04:00
|
|
|
char *head, *tail;
|
|
|
|
char linebuffer[256];
|
2007-07-31 00:34:33 -04:00
|
|
|
uint32_t len;
|
2005-06-01 10:40:28 -04:00
|
|
|
|
|
|
|
DPRINTF(E_DBG,L_SCAN,"Getting URL file info\n");
|
|
|
|
|
2007-07-31 00:34:33 -04:00
|
|
|
if(!(hfile = io_new())) {
|
|
|
|
DPRINTF(E_LOG,L_SCAN,"Can't create file handle\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-08-05 00:43:25 -04:00
|
|
|
if(!io_open(hfile,"file://%U?ascii=1",filename)) {
|
2007-07-31 00:34:33 -04:00
|
|
|
DPRINTF(E_WARN,L_SCAN,"Could not open %s for reading: %s\n",filename,
|
|
|
|
io_errstr(hfile));
|
|
|
|
io_dispose(hfile);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
io_buffer(hfile);
|
|
|
|
len = sizeof(linebuffer);
|
|
|
|
if(!io_readline(hfile,(unsigned char *)linebuffer,&len)) {
|
|
|
|
DPRINTF(E_WARN,L_SCAN,"Error reading from file %s: %s",filename,io_errstr(hfile));
|
|
|
|
io_close(hfile);
|
|
|
|
io_dispose(hfile);
|
2006-02-26 03:46:24 -05:00
|
|
|
return FALSE;
|
2005-06-01 10:40:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
while((linebuffer[strlen(linebuffer)-1] == '\n') ||
|
2006-02-26 03:46:24 -05:00
|
|
|
(linebuffer[strlen(linebuffer)-1] == '\r')) {
|
|
|
|
linebuffer[strlen(linebuffer)-1] = '\0';
|
2005-06-01 10:40:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
head=linebuffer;
|
|
|
|
tail=strchr(head,',');
|
|
|
|
if(!tail) {
|
2006-02-26 03:46:24 -05:00
|
|
|
DPRINTF(E_LOG,L_SCAN,"Badly formatted .url file - must be bitrate,descr,url\n");
|
2007-07-31 00:34:33 -04:00
|
|
|
io_close(hfile);
|
|
|
|
io_dispose(hfile);
|
2006-02-26 03:46:24 -05:00
|
|
|
return FALSE;
|
2005-06-01 10:40:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
pmp3->bitrate=atoi(head);
|
|
|
|
head=++tail;
|
|
|
|
tail=strchr(head,',');
|
|
|
|
if(!tail) {
|
2006-02-26 03:46:24 -05:00
|
|
|
DPRINTF(E_LOG,L_SCAN,"Badly formatted .url file - must be bitrate,descr,url\n");
|
2007-07-31 00:34:33 -04:00
|
|
|
io_close(hfile);
|
|
|
|
io_dispose(hfile);
|
2006-02-26 03:46:24 -05:00
|
|
|
return FALSE;
|
2005-06-01 10:40:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
*tail++='\0';
|
2006-11-14 00:29:32 -05:00
|
|
|
|
2005-06-01 10:40:28 -04:00
|
|
|
pmp3->title=strdup(head);
|
|
|
|
pmp3->url=strdup(tail);
|
2007-07-31 00:34:33 -04:00
|
|
|
|
|
|
|
io_close(hfile);
|
|
|
|
io_dispose(hfile);
|
2005-06-01 10:40:28 -04:00
|
|
|
|
|
|
|
DPRINTF(E_DBG,L_SCAN," Title: %s\n",pmp3->title);
|
|
|
|
DPRINTF(E_DBG,L_SCAN," Bitrate: %d\n",pmp3->bitrate);
|
|
|
|
DPRINTF(E_DBG,L_SCAN," URL: %s\n",pmp3->url);
|
|
|
|
|
2009-04-05 07:51:57 -04:00
|
|
|
pmp3->type = strdup("pls");
|
|
|
|
/* codectype = NULL */
|
|
|
|
pmp3->description = strdup("Playlist URL");
|
|
|
|
|
2005-06-01 22:26:04 -04:00
|
|
|
return TRUE;
|
2005-06-01 10:40:28 -04:00
|
|
|
}
|
|
|
|
|