subtitles: accept smi in addition to srt

This commit is contained in:
Justin Maggard 2014-04-21 15:44:39 -07:00
parent 0721528bcd
commit 381c4805e6
4 changed files with 36 additions and 26 deletions

View File

@ -297,7 +297,7 @@ inotify_insert_file(char * name, const char * path)
/* Is it cover art for another file? */
if( is_image(path) )
update_if_album_art(path);
else if( ends_with(path, ".srt") )
else if( is_caption(path) )
check_for_captions(path, 0);
/* Check if we're supposed to be scanning for this file type in this directory */
@ -538,7 +538,7 @@ inotify_remove_file(const char * path)
int64_t detailID;
int rows, playlist;
if( ends_with(path, ".srt") )
if( is_caption(path) )
{
return sql_exec(db, "DELETE from CAPTIONS where PATH = '%q'", path);
}

View File

@ -157,41 +157,42 @@ dlna_timestamp_is_present(const char *filename, int *raw_packet_size)
void
check_for_captions(const char *path, int64_t detailID)
{
char *file = malloc(MAXPATHLEN);
char *id = NULL;
char file[MAXPATHLEN];
char *p;
int ret;
sprintf(file, "%s", path);
strip_ext(file);
strncpyt(file, path, sizeof(file));
p = strip_ext(file);
if (!p)
p = strrchr(file, '\0');
/* If we weren't given a detail ID, look for one. */
if( !detailID )
if (!detailID)
{
id = sql_get_text_field(db, "SELECT ID from DETAILS where (PATH > '%q.' and PATH <= '%q.z')"
detailID = sql_get_int64_field(db, "SELECT ID from DETAILS where (PATH > '%q.' and PATH <= '%q.z')"
" and MIME glob 'video/*' limit 1", file, file);
if( id )
{
//DPRINTF(E_MAXDEBUG, L_METADATA, "New file %s looks like a caption file.\n", path);
detailID = strtoll(id, NULL, 10);
}
else
if (detailID <= 0)
{
//DPRINTF(E_MAXDEBUG, L_METADATA, "No file found for caption %s.\n", path);
goto no_source_video;
return;
}
}
strcat(file, ".srt");
if( access(file, R_OK) == 0 )
strcpy(p, ".srt");
ret = access(file, R_OK);
if (ret != 0)
{
strcpy(p, ".smi");
ret = access(file, R_OK);
}
if (ret == 0)
{
sql_exec(db, "INSERT into CAPTIONS"
" (ID, PATH) "
"VALUES"
" (%lld, %Q)", detailID, file);
}
no_source_video:
if( id )
sqlite3_free(id);
free(file);
}
void

16
utils.c
View File

@ -227,14 +227,16 @@ escape_tag(const char *tag, int force_alloc)
return esc_tag;
}
void
strip_ext(char * name)
char *
strip_ext(char *name)
{
char * period;
char *period;
period = strrchr(name, '.');
if( period )
if (period)
*period = '\0';
return period;
}
/* Code basically stolen from busybox */
@ -408,6 +410,12 @@ is_playlist(const char * file)
return (ends_with(file, ".m3u") || ends_with(file, ".pls"));
}
int
is_caption(const char * file)
{
return (ends_with(file, ".srt") || ends_with(file, ".smi"));
}
int
is_album_art(const char * name)
{

View File

@ -63,13 +63,14 @@ char *strcasestrc(const char *s, const char *p, const char t);
char *modifyString(char *string, const char *before, const char *after, int noalloc);
char *escape_tag(const char *tag, int force_alloc);
char *unescape_tag(const char *tag, int force_alloc);
void strip_ext(char * name);
char *strip_ext(char *name);
/* Metadata functions */
int is_video(const char * file);
int is_audio(const char * file);
int is_image(const char * file);
int is_playlist(const char * file);
int is_caption(const char * file);
int is_album_art(const char * name);
int resolve_unknown_type(const char * path, media_types dir_type);
const char *mime_to_ext(const char * mime);