aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/test-vlc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/test-vlc.c')
-rw-r--r--src/plugins/test-vlc.c216
1 files changed, 216 insertions, 0 deletions
diff --git a/src/plugins/test-vlc.c b/src/plugins/test-vlc.c
new file mode 100644
index 0000000..c80f6b6
--- /dev/null
+++ b/src/plugins/test-vlc.c
@@ -0,0 +1,216 @@
1/*
2 This file is part of libextractor.
3 Copyright (C) 2021 Christian Grothoff
4
5 libextractor is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 libextractor is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with libextractor; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19
20NOTE: This plugin is not yet working. Somehow libvlc never calls any of the IO callbacks.
21
22*/
23/**
24 * @file plugins/vlc_extractor.c
25 * @brief plugin to extract metadata using libvlc
26 * @author Christian Grothoff
27 */
28#include <vlc/vlc.h>
29#include <signal.h>
30#include <stdlib.h>
31#include <stdio.h>
32#include <errno.h>
33#include <sys/types.h>
34#include <sys/stat.h>
35#include <fcntl.h>
36#include <string.h>
37#include <unistd.h>
38
39
40static void
41extract (void *ptr,
42 libvlc_media_t *media)
43{
44 struct
45 {
46 enum libvlc_meta_t vt;
47 } map[] = {
48 { libvlc_meta_Title, },
49 { libvlc_meta_Artist, },
50 { libvlc_meta_Genre, },
51 { libvlc_meta_Copyright, },
52 { libvlc_meta_Album, },
53 { libvlc_meta_TrackNumber, },
54 { libvlc_meta_Description, },
55 { libvlc_meta_Rating, },
56 { libvlc_meta_Date, },
57 { libvlc_meta_Setting, },
58 { libvlc_meta_URL, },
59 { libvlc_meta_Language, },
60 { libvlc_meta_NowPlaying, },
61 { libvlc_meta_Publisher, },
62 { libvlc_meta_EncodedBy, },
63 { libvlc_meta_ArtworkURL, },
64 { libvlc_meta_TrackID, },
65 { libvlc_meta_TrackTotal, },
66 { libvlc_meta_Director, },
67 { libvlc_meta_Season, },
68 { libvlc_meta_Episode, },
69 { libvlc_meta_ShowName, },
70 { libvlc_meta_Actors, },
71 { libvlc_meta_AlbumArtist, },
72 { libvlc_meta_DiscNumber, },
73 { libvlc_meta_DiscTotal, },
74 { -1 }
75 };
76
77 for (unsigned int i = 0;
78 -1 != map[i].vt;
79 i++)
80 {
81 char *meta;
82
83 fprintf (stderr,
84 ".");
85 meta = libvlc_media_get_meta (media,
86 map[i].vt);
87 if (NULL == meta)
88 continue;
89 fprintf (stderr,
90 "Found %d: %s\n",
91 map[i].vt,
92 meta);
93 free (meta);
94 }
95}
96
97
98static void
99media_ready (const struct libvlc_event_t *p_event,
100 void *p_data)
101{
102 fprintf (stderr,
103 "media status: %d, %d\n",
104 p_event->type == libvlc_MediaParsedChanged,
105 p_event->u.media_parsed_changed.new_status);
106 if (p_event->u.media_parsed_changed.new_status ==
107 libvlc_media_parsed_status_done)
108 {
109 fprintf (stderr,
110 "media ready\n");
111 }
112}
113
114
115static void
116my_logger (void *data,
117 int level,
118 const libvlc_log_t *ctx,
119 const char *fmt,
120 va_list args)
121{
122 vfprintf (stderr,
123 fmt,
124 args);
125 fprintf (stderr, "\n");
126}
127
128
129/**
130 * Extract information using libvlc
131 *
132 * @param ec extraction context
133 */
134void
135main(int argc,
136 char **argv)
137{
138 libvlc_instance_t *vlc;
139 libvlc_media_t *media;
140 libvlc_event_manager_t *em;
141
142 {
143 sigset_t set;
144
145 signal (SIGCHLD, SIG_DFL);
146 sigemptyset (&set);
147 sigaddset (&set, SIGPIPE);
148 pthread_sigmask (SIG_BLOCK, &set, NULL);
149 }
150
151 {
152 const char *argv[] = {
153 "-v",
154 "3",
155 NULL
156 };
157 vlc = libvlc_new (2, argv);
158 }
159 if (NULL == vlc)
160 return;
161 libvlc_log_set (vlc,
162 &my_logger,
163 NULL);
164 fprintf (stderr,
165 "Opening file `%s'\n",
166 argv[1]);
167 {
168 int fd = open (argv[1],
169 O_RDONLY);
170 if (-1 == fd)
171 {
172 fprintf (stderr,
173 "Open failed: %s\n",
174 strerror (errno));
175 libvlc_release (vlc);
176 return;
177 }
178 media = libvlc_media_new_fd (vlc,
179 fd);
180 }
181 if (NULL == media)
182 {
183 libvlc_release (vlc);
184 return;
185 }
186
187 em = libvlc_media_event_manager (media);
188 libvlc_event_attach (em,
189 libvlc_MediaParsedChanged,
190 &media_ready,
191 NULL);
192 fprintf (stderr,
193 "Triggering parser\n");
194 {
195 int status;
196
197 status = libvlc_media_parse_with_options (media,
198 libvlc_media_fetch_local
199 | libvlc_media_parse_network
200 | libvlc_media_fetch_network,
201 30000); /* 30s timeout */
202 fprintf (stderr,
203 "Status: %d\n",
204 status);
205 }
206 fprintf (stderr,
207 "Sleeping\n");
208 sleep (1);
209 extract (NULL,
210 media);
211 libvlc_media_release (media);
212 libvlc_release (vlc);
213}
214
215
216/* end of vlc_extractor.c */