~ubuntu-branches/ubuntu/gutsy/ogmtools/gutsy

« back to all changes in this revision

Viewing changes to dvdxchap.c

  • Committer: Bazaar Package Importer
  • Author(s): Marc Leeman
  • Date: 2005-03-07 09:31:25 UTC
  • mfrom: (2.1.1 hoary)
  • Revision ID: james.westby@ubuntu.com-20050307093125-sx176ww54zi0shin
Tags: 1:1.5-2
* When using -v and -s together, the verbose output is removed (Closes: #296741)
* Fix of wrong length reporting (Closes: #296739)
* depend on dpatch for patches
* Upload sponsored by Luigi Gangitano <luigi@debian.org>

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
    "ogmtools v" VERSION "\n"
24
24
    "Usage: dvdxchap [options] DVD-SOURCE\n\n"
25
25
    " options:\n"
26
 
    "   -t, --title num    Use title 'num'. Default is 1.\n"
27
 
    "   -v, --verbose      Increase verbosity\n"
28
 
    "   -V, --version      Show version information\n"
29
 
    "   -h, --help         Show this help\n");
 
26
    "   -t, --title num            Use title 'num'. Default is 1.\n"
 
27
    "   -c, --chapter start[-end]  Chapter to start at (to end at). Default 1.\n"
 
28
    "   -v, --verbose              Increase verbosity\n"
 
29
    "   -V, --version              Show version information\n"
 
30
    "   -h, --help                 Show this help\n");
30
31
}
31
32
 
32
 
void display_chapters(char *source, int title, int verbose) {
 
33
void display_chapters(char *source, int title, int start, int end, int verbose) {
33
34
  dvd_reader_t   *dvd;
34
35
  ifo_handle_t   *vmg;
35
36
  ifo_handle_t   *vts;
39
40
  pgc_t          *cur_pgc;
40
41
  dvd_time_t     *dt;
41
42
  double          fps;
42
 
  long            hour, minute, second, ms, overall_time, cur_time;
 
43
  long            hour, minute, second, ms, overall_time, start_time, cur_time;
43
44
  
44
45
  dvd = DVDOpen(source);
45
46
  if (dvd == NULL) {
63
64
            tt_srpt->nr_of_srpts);
64
65
    ifoClose(vmg);
65
66
    DVDClose(dvd);
 
67
    exit(1);
66
68
  }
67
69
  title--;
68
70
  if (verbose)
74
76
    fprintf(stderr, "(%s) Can't open VTS info.\n", __FILE__);
75
77
    ifoClose(vmg);
76
78
    DVDClose(dvd);
 
79
    exit(1);
 
80
  }
 
81
 
 
82
  if (end > 0) {
 
83
    if ((end <= start) || (end > tt_srpt->title[title].nr_of_ptts)) {
 
84
      fprintf(stderr, "(%s) Invalid end chapter.\n", __FILE__);
 
85
      ifoClose(vmg);
 
86
      DVDClose(dvd);
 
87
      exit(1);
 
88
    }
77
89
  }
78
90
  
79
91
  ttn = tt_srpt->title[title].vts_ttn;
80
92
  vts_ptt_srpt = vts->vts_ptt_srpt;
81
 
  overall_time = 0;
 
93
  start_time = overall_time = 0;
82
94
  for (i = 0; i < tt_srpt->title[title].nr_of_ptts - 1; i++) {
83
95
    pgc_id = vts_ptt_srpt->title[ttn - 1].ptt[i].pgcn;
84
96
    pgn = vts_ptt_srpt->title[ttn - 1].ptt[i].pgn;
104
116
      cur_time += (hour * 60 * 60 * 1000 + minute * 60 * 1000 + second * 1000 +
105
117
                   ms);
106
118
    }
107
 
    fprintf(stdout, "CHAPTER%02d=%02ld:%02ld:%02ld.%03ld\n", i + 1,
108
 
            overall_time / 60 / 60 / 1000,
109
 
            (overall_time / 60 / 1000) % 60,
110
 
            (overall_time / 1000) % 60,
111
 
            overall_time % 1000);
112
 
    fprintf(stdout, "CHAPTER%02dNAME=Chapter %02d\n", i + 1, i + 1);
 
119
    if (start == i)
 
120
      start_time = overall_time;
 
121
    if (i >= start && (i < end || end <= 0))
 
122
    {
 
123
      fprintf(stdout, "CHAPTER%02d=%02ld:%02ld:%02ld.%03ld\n", i + 1 - start,
 
124
              (overall_time - start_time) / 60 / 60 / 1000,
 
125
              ((overall_time - start_time) / 60 / 1000) % 60,
 
126
              ((overall_time - start_time) / 1000) % 60,
 
127
              (overall_time - start_time) % 1000);
 
128
      fprintf(stdout, "CHAPTER%02dNAME=Chapter %02d\n", i + 1 - start,
 
129
              i + 1 - start);
 
130
    }
113
131
    overall_time += cur_time;
114
132
  }
115
 
  fprintf(stdout, "CHAPTER%02d=%02ld:%02ld:%02ld.%03ld\n", i + 1,
116
 
          overall_time / 60 / 60 / 1000,
117
 
          (overall_time / 60 / 1000) % 60,
118
 
          (overall_time / 1000) % 60,
119
 
          overall_time % 1000);
120
 
  fprintf(stdout, "CHAPTER%02dNAME=Chapter %02d\n", i + 1, i + 1);
 
133
  if (end <= 0 || i == end)
 
134
  {
 
135
    fprintf(stdout, "CHAPTER%02d=%02ld:%02ld:%02ld.%03ld\n", i + 1 - start,
 
136
            (overall_time - start_time) / 60 / 60 / 1000,
 
137
            ((overall_time - start_time) / 60 / 1000) % 60,
 
138
            ((overall_time - start_time) / 1000) % 60,
 
139
            (overall_time - start_time) % 1000);
 
140
    fprintf(stdout, "CHAPTER%02dNAME=Chapter %02d\n", i + 1 - start, i + 1 - start);
 
141
  }
121
142
  
122
143
  ifoClose(vts);
123
144
  ifoClose(vmg);
126
147
 
127
148
int main(int argc, char *argv[]) {
128
149
  int  title = 1;
 
150
  int  start = 0, end = 0;
129
151
  int  i;
130
152
  char *source = NULL;
131
153
  int  verbose = 0;
155
177
        exit(1);
156
178
      }
157
179
      i++;
 
180
    } else if (!strcmp(argv[i], "-c") || !strcmp(argv[i], "--chapter")) {
 
181
      if ((i + 1) >= argc) {
 
182
        fprintf(stderr, "(%s) Error: -c lacks a chapter number.\n", __FILE__);
 
183
        exit(1);
 
184
      }
 
185
      if (sscanf(argv[i + 1], "%d-%d", &start, &end) < 1) {
 
186
        fprintf(stderr, "(%s) Error: '%s' is not a valid chapter range.\n", 
 
187
                __FILE__, argv[i + 1]);
 
188
        exit(1);
 
189
      }
 
190
      if (start < 0) {
 
191
        end = -start;
 
192
        start = 0;
 
193
      }
 
194
      if ((start > end) && (end > 0)) {
 
195
        int tmp;
 
196
        tmp = start;
 
197
        start = end;
 
198
        end = tmp;
 
199
      }
 
200
      if (start > 0)
 
201
        start--;
 
202
      i++;
158
203
    } else {
159
204
      if (source != NULL) {
160
205
        fprintf(stderr, "(%s) Error: more than one source given.\n", __FILE__);
167
212
    fprintf(stderr, "(%s) Error: No source given.\n", __FILE__);
168
213
    exit(1);
169
214
  }
170
 
 
171
 
  display_chapters(source, title, verbose);
172
 
  
 
215
 
 
216
  display_chapters(source, title, start, end, verbose);
 
217
 
173
218
  return 0;
174
219
}