Add .wmv to video-dummy.
[lms] / lightmediascanner / src / plugins / video-dummy / video-dummy.c
1 /**
2  * Copyright (C) 2007 by INdT
3  *
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.
8  *
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.
13  *
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.
17  *
18  * @author Gustavo Sverzut Barbieri <gustavo.barbieri@openbossa.org>
19  */
20
21 /**
22  * @brief
23  *
24  * Video Dummy plugin, just register matched extensions in videos DB.
25  */
26
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30
31 #define _XOPEN_SOURCE 600
32 #include <lightmediascanner_plugin.h>
33 #include <lightmediascanner_db.h>
34 #include <stdlib.h>
35 #include <stdio.h>
36 #include <string.h>
37
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(".rm"),
44     LMS_STATIC_STRING_SIZE(".3gp"),
45     LMS_STATIC_STRING_SIZE(".rm"),
46     LMS_STATIC_STRING_SIZE(".ram"),
47     LMS_STATIC_STRING_SIZE(".mp4"),
48     LMS_STATIC_STRING_SIZE(".ogm"),
49     LMS_STATIC_STRING_SIZE(".wmv")
50 };
51
52 struct plugin {
53     struct lms_plugin plugin;
54     lms_db_video_t *video_db;
55 };
56
57 static void *
58 _match(struct plugin *p, const char *path, int len, int base)
59 {
60     int i;
61
62     i = lms_which_extension(path, len, _exts, LMS_ARRAY_SIZE(_exts));
63     if (i < 0)
64         return NULL;
65     else
66         return (void*)(i + 1);
67 }
68
69 static int
70 _parse(struct plugin *plugin, struct lms_context *ctxt, const struct lms_file_info *finfo, void *match)
71 {
72     struct lms_video_info info = {0};
73     int r, ext_idx;
74
75     ext_idx = ((int)match) - 1;
76     info.title.len = finfo->path_len - finfo->base - _exts[ext_idx].len;
77     info.title.str = malloc((info.title.len + 1) * sizeof(char));
78     memcpy(info.title.str, finfo->path + finfo->base, info.title.len);
79     info.title.str[info.title.len] = '\0';
80     lms_charset_conv(ctxt->cs_conv, &info.title.str, &info.title.len);
81
82     info.id = finfo->id;
83     r = lms_db_video_add(plugin->video_db, &info);
84
85     free(info.title.str);
86
87     return r;
88 }
89
90 static int
91 _setup(struct plugin *plugin, struct lms_context *ctxt)
92 {
93     plugin->video_db = lms_db_video_new(ctxt->db);
94     if (!plugin->video_db)
95         return -1;
96
97     return 0;
98 }
99
100 static int
101 _start(struct plugin *plugin, struct lms_context *ctxt)
102 {
103     return lms_db_video_start(plugin->video_db);
104 }
105
106 static int
107 _finish(struct plugin *plugin, struct lms_context *ctxt)
108 {
109     if (plugin->video_db)
110         return lms_db_video_free(plugin->video_db);
111
112     return 0;
113 }
114
115
116 static int
117 _close(struct plugin *plugin)
118 {
119     free(plugin);
120     return 0;
121 }
122
123 API struct lms_plugin *
124 lms_plugin_open(void)
125 {
126     struct plugin *plugin;
127
128     plugin = malloc(sizeof(*plugin));
129     plugin->plugin.name = _name;
130     plugin->plugin.match = (lms_plugin_match_fn_t)_match;
131     plugin->plugin.parse = (lms_plugin_parse_fn_t)_parse;
132     plugin->plugin.close = (lms_plugin_close_fn_t)_close;
133     plugin->plugin.setup = (lms_plugin_setup_fn_t)_setup;
134     plugin->plugin.start = (lms_plugin_start_fn_t)_start;
135     plugin->plugin.finish = (lms_plugin_finish_fn_t)_finish;
136
137     return (struct lms_plugin *)plugin;
138 }