• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 The WebM project authors. All Rights Reserved.
2 //
3 // Use of this source code is governed by a BSD-style license
4 // that can be found in the LICENSE file in the root of the source
5 // tree. An additional intellectual property rights grant can be found
6 // in the file PATENTS.  All contributing project authors may
7 // be found in the AUTHORS file in the root of the source tree.
8 
9 #include <cstdio>
10 #include <cstdlib>
11 #include "webvtt/vttreader.h"
12 #include "webvtt/webvttparser.h"
13 
main(int argc,const char * argv[])14 int main(int argc, const char* argv[]) {
15   if (argc != 2) {
16     fprintf(stdout, "usage: dumpvtt <vtt file>\n");
17     return EXIT_SUCCESS;
18   }
19 
20   libwebvtt::VttReader reader;
21   const char* const filename = argv[1];
22 
23   if (int e = reader.Open(filename)) {
24     (void)e;
25     fprintf(stderr, "open failed\n");
26     return EXIT_FAILURE;
27   }
28 
29   libwebvtt::Parser parser(&reader);
30 
31   if (int e = parser.Init()) {
32     (void)e;
33     fprintf(stderr, "parser init failed\n");
34     return EXIT_FAILURE;
35   }
36 
37   for (libwebvtt::Cue cue;;) {
38     const int e = parser.Parse(&cue);
39 
40     if (e < 0) {  // error
41       fprintf(stderr, "error parsing cue\n");
42       return EXIT_FAILURE;
43     }
44 
45     if (e > 0)  // EOF
46       return EXIT_SUCCESS;
47 
48     fprintf(stdout, "cue identifier: \"%s\"\n", cue.identifier.c_str());
49 
50     const libwebvtt::Time& st = cue.start_time;
51     fprintf(stdout, "cue start time: \"HH=%i MM=%i SS=%i SSS=%i\"\n", st.hours,
52             st.minutes, st.seconds, st.milliseconds);
53 
54     const libwebvtt::Time& sp = cue.stop_time;
55     fprintf(stdout, "cue stop time: \"HH=%i MM=%i SS=%i SSS=%i\"\n", sp.hours,
56             sp.minutes, sp.seconds, sp.milliseconds);
57 
58     {
59       typedef libwebvtt::Cue::settings_t::const_iterator iter_t;
60       iter_t i = cue.settings.begin();
61       const iter_t j = cue.settings.end();
62 
63       if (i == j) {
64         fprintf(stdout, "cue setting: <no settings present>\n");
65       } else {
66         while (i != j) {
67           const libwebvtt::Setting& setting = *i++;
68           fprintf(stdout, "cue setting: name=%s value=%s\n",
69                   setting.name.c_str(), setting.value.c_str());
70         }
71       }
72     }
73 
74     {
75       typedef libwebvtt::Cue::payload_t::const_iterator iter_t;
76       iter_t i = cue.payload.begin();
77       const iter_t j = cue.payload.end();
78 
79       int idx = 1;
80       while (i != j) {
81         const std::string& payload = *i++;
82         const char* const payload_str = payload.c_str();
83         fprintf(stdout, "cue payload[%i]: \"%s\"\n", idx, payload_str);
84         ++idx;
85       }
86     }
87 
88     fprintf(stdout, "\n");
89     fflush(stdout);
90   }
91 }
92