Adds support for URLs (streaming) in m3u playlist files.

Also added a few file types that the filescanner should ignore.
This commit is contained in:
ejurgensen 2013-08-14 23:40:55 +02:00
parent f6f3057930
commit 4552acba7e
4 changed files with 46 additions and 15 deletions

View File

@ -66,6 +66,7 @@
struct deferred_pl { struct deferred_pl {
char *path; char *path;
time_t mtime;
struct deferred_pl *next; struct deferred_pl *next;
}; };
@ -294,8 +295,8 @@ fixup_tags(struct media_file_info *mfi)
} }
static void void
process_media_file(char *file, time_t mtime, off_t size, int compilation) process_media_file(char *file, time_t mtime, off_t size, int compilation, int url)
{ {
struct media_file_info mfi; struct media_file_info mfi;
char *filename; char *filename;
@ -364,13 +365,28 @@ process_media_file(char *file, time_t mtime, off_t size, int compilation)
/* Artwork - don't scan */ /* Artwork - don't scan */
goto out; goto out;
} }
else if ((strcmp(ext, ".db") == 0)
|| (strcmp(ext, ".ini") == 0))
{
/* System files - don't scan */
goto out;
}
else if ((filename[1] == '_')
|| (filename[1] == '.'))
{
/* Hidden files - don't scan */
goto out;
}
} }
/* General case */ /* General case */
if (ret < 0) if (ret < 0)
{ {
ret = scan_metadata_ffmpeg(file, &mfi); ret = scan_metadata_ffmpeg(file, &mfi);
mfi.data_kind = 0; /* real file */ if (url == 0)
mfi.data_kind = 0; /* real file */
if (url == 1)
mfi.data_kind = 1; /* url/stream */
} }
if (ret < 0) if (ret < 0)
@ -401,7 +417,7 @@ process_media_file(char *file, time_t mtime, off_t size, int compilation)
} }
static void static void
process_playlist(char *file) process_playlist(char *file, time_t mtime)
{ {
char *ext; char *ext;
@ -409,7 +425,7 @@ process_playlist(char *file)
if (ext) if (ext)
{ {
if (strcmp(ext, ".m3u") == 0) if (strcmp(ext, ".m3u") == 0)
scan_m3u_playlist(file); scan_m3u_playlist(file, mtime);
#ifdef ITUNES #ifdef ITUNES
else if (strcmp(ext, ".xml") == 0) else if (strcmp(ext, ".xml") == 0)
scan_itunes_itml(file); scan_itunes_itml(file);
@ -419,7 +435,7 @@ process_playlist(char *file)
/* Thread: scan */ /* Thread: scan */
static void static void
defer_playlist(char *path) defer_playlist(char *path, time_t mtime)
{ {
struct deferred_pl *pl; struct deferred_pl *pl;
@ -442,6 +458,7 @@ defer_playlist(char *path)
return; return;
} }
pl->mtime = mtime;
pl->next = playlists; pl->next = playlists;
playlists = pl; playlists = pl;
@ -458,7 +475,7 @@ process_deferred_playlists(void)
{ {
playlists = pl->next; playlists = pl->next;
process_playlist(pl->path); process_playlist(pl->path, pl->mtime);
free(pl->path); free(pl->path);
free(pl); free(pl);
@ -487,9 +504,9 @@ process_file(char *file, time_t mtime, off_t size, int compilation, int flags)
) )
{ {
if (flags & F_SCAN_BULK) if (flags & F_SCAN_BULK)
defer_playlist(file); defer_playlist(file, mtime);
else else
process_playlist(file); process_playlist(file, mtime);
return; return;
} }
@ -502,7 +519,7 @@ process_file(char *file, time_t mtime, off_t size, int compilation, int flags)
} }
/* Not any kind of special file, so let's see if it's a media file */ /* Not any kind of special file, so let's see if it's a media file */
process_media_file(file, mtime, size, compilation); process_media_file(file, mtime, size, compilation, 0);
} }

View File

@ -10,15 +10,15 @@ filescanner_init(void);
void void
filescanner_deinit(void); filescanner_deinit(void);
void
process_media_file(char *file, time_t mtime, off_t size, int compilation, int url);
/* Actual scanners */ /* Actual scanners */
int int
scan_metadata_ffmpeg(char *file, struct media_file_info *mfi); scan_metadata_ffmpeg(char *file, struct media_file_info *mfi);
int
scan_url_file(char *file, struct media_file_info *mfi);
void void
scan_m3u_playlist(char *file); scan_m3u_playlist(char *file, time_t mtime);
#ifdef ITUNES #ifdef ITUNES
void void

View File

@ -41,7 +41,7 @@
void void
scan_m3u_playlist(char *file) scan_m3u_playlist(char *file, time_t mtime)
{ {
FILE *fp; FILE *fp;
struct playlist_info *pli; struct playlist_info *pli;
@ -165,6 +165,17 @@ scan_m3u_playlist(char *file)
buf[len] = '\0'; buf[len] = '\0';
} }
/* Check if line is an URL */
if (strcmp(buf, "http://") > 0)
{
DPRINTF(E_DBG, L_SCAN, "Playlist contains URL entry\n");
filename = strdup(buf);
process_media_file(filename, mtime, 0, 0, 1);
goto urlexit;
}
/* Absolute vs. relative path */ /* Absolute vs. relative path */
if (buf[0] == '/') if (buf[0] == '/')
{ {
@ -191,6 +202,7 @@ scan_m3u_playlist(char *file)
continue; continue;
} }
urlexit:
ret = db_pl_add_item_bypath(pl_id, filename); ret = db_pl_add_item_bypath(pl_id, filename);
if (ret < 0) if (ret < 0)
DPRINTF(E_WARN, L_SCAN, "Could not add %s to playlist\n", filename); DPRINTF(E_WARN, L_SCAN, "Could not add %s to playlist\n", filename);

View File

@ -579,6 +579,7 @@ main(int argc, char **argv)
} }
av_register_all(); av_register_all();
avformat_network_init();
av_log_set_callback(logger_ffmpeg); av_log_set_callback(logger_ffmpeg);
#if LIBAVFORMAT_VERSION_MAJOR < 53 #if LIBAVFORMAT_VERSION_MAJOR < 53
register_ffmpeg_evbuffer_url_protocol(); register_ffmpeg_evbuffer_url_protocol();
@ -814,6 +815,7 @@ main(int argc, char **argv)
signal_block_fail: signal_block_fail:
gcrypt_init_fail: gcrypt_init_fail:
avformat_network_deinit();
av_lockmgr_register(NULL); av_lockmgr_register(NULL);
ffmpeg_init_fail: ffmpeg_init_fail: