2 * Copyright (C) 2007 by INdT
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 * @author Gustavo Sverzut Barbieri <gustavo.barbieri@openbossa.org>
24 * Video Dummy plugin, just register matched extensions in videos DB.
31 #define _XOPEN_SOURCE 600
32 #include <lightmediascanner_plugin.h>
33 #include <lightmediascanner_db.h>
38 static const char _name[] = "video-dummy";
39 static const struct lms_string_size _exts[] = {
40 LMS_STATIC_STRING_SIZE(".avi"),
41 LMS_STATIC_STRING_SIZE(".mpg"),
42 LMS_STATIC_STRING_SIZE(".mpeg"),
43 LMS_STATIC_STRING_SIZE(".3gp"),
44 LMS_STATIC_STRING_SIZE(".ram"),
45 LMS_STATIC_STRING_SIZE(".mp4"),
46 LMS_STATIC_STRING_SIZE(".ogm"),
50 struct lms_plugin plugin;
51 lms_db_video_t *video_db;
55 _match(struct plugin *p, const char *path, int len, int base)
59 i = lms_which_extension(path, len, _exts, LMS_ARRAY_SIZE(_exts));
63 return (void*)(i + 1);
67 _parse(struct plugin *plugin, struct lms_context *ctxt, const struct lms_file_info *finfo, void *match)
69 struct lms_video_info info = {0};
72 ext_idx = ((int)match) - 1;
73 info.title.len = finfo->path_len - finfo->base - _exts[ext_idx].len;
74 info.title.str = malloc((info.title.len + 1) * sizeof(char));
75 memcpy(info.title.str, finfo->path + finfo->base, info.title.len);
76 info.title.str[info.title.len] = '\0';
77 lms_charset_conv(ctxt->cs_conv, &info.title.str, &info.title.len);
80 r = lms_db_video_add(plugin->video_db, &info);
88 _setup(struct plugin *plugin, struct lms_context *ctxt)
90 plugin->video_db = lms_db_video_new(ctxt->db);
91 if (!plugin->video_db)
98 _start(struct plugin *plugin, struct lms_context *ctxt)
100 return lms_db_video_start(plugin->video_db);
104 _finish(struct plugin *plugin, struct lms_context *ctxt)
106 if (plugin->video_db)
107 return lms_db_video_free(plugin->video_db);
114 _close(struct plugin *plugin)
120 API struct lms_plugin *
121 lms_plugin_open(void)
123 struct plugin *plugin;
125 plugin = malloc(sizeof(*plugin));
126 plugin->plugin.name = _name;
127 plugin->plugin.match = (lms_plugin_match_fn_t)_match;
128 plugin->plugin.parse = (lms_plugin_parse_fn_t)_parse;
129 plugin->plugin.close = (lms_plugin_close_fn_t)_close;
130 plugin->plugin.setup = (lms_plugin_setup_fn_t)_setup;
131 plugin->plugin.start = (lms_plugin_start_fn_t)_start;
132 plugin->plugin.finish = (lms_plugin_finish_fn_t)_finish;
134 return (struct lms_plugin *)plugin;