#!/usr/bin/perl

# $Id: dvdrip,v 1.16 2002/12/27 00:16:08 joern Exp $

#-----------------------------------------------------------------------
# Copyright (C) 2001-2002 Jrn Reder <joern@zyn.de> All Rights Reserved
# 
# This program is part of Video::DVDRip, which is free software; you can
# redistribute it and/or modify it under the same terms as Perl itself.
#-----------------------------------------------------------------------

package Video::DVDRip;

use strict;
use lib 'lib';
use Getopt::Std;

# That's Perl! The job classes derive from this class,
# which is decided at *runtime* - this way standard and
# cluster mode can share the same job execution system
# by inserting the cluster logic dynamically into the
# inheritence line... great stuff!

my $has_dvdrip_rc;

BEGIN {
	if ( $] >= 5.008 and not defined $ENV{PERLIO} ) {
		$ENV{PERLIO} = "stdio";
		require Config;
		print STDERR "\nYou're using Perl 5.8.0 without PERLIO set to 'stdio'.\n";
		print STDERR "Most Perl 5.008 installations currently have a bug.\n";
		print STDERR "dvd::rip doesn't work with them if PERLIO isn't set.\n\n";
		print STDERR "I will set PERLIO=stdio for you and restart dvd::rip...\n\n";
		print STDERR "You can get rid of this messages, by setting PERLIO=stdio\n";
		print STDERR "in your ~/.profile, or whatever your shell uses.\n\n";
		exec $Config::Config{perlpath}, $0, @ARGV;
	}

	$Video::DVDRip::JobClass = "Video::DVDRip::Job";
	$has_dvdrip_rc = -f "$ENV{HOME}/.dvdriprc";
}

use Video::DVDRip;
use Video::DVDRip::GUI::Main;

my $USAGE = <<'_USAGE';

usage: dvdrip [-c] [-d level] [-f function [-t title-nr]] [filename]
       dvdrip --version | -version | -v

       -c open cluster control window

       -d set debugging level

       -f execute one of the following functions (needs filename)
          transcode         transcode the selected title
	  transcode_split   transcode and split the selected title

       -t title-nr to which the function above should apply
          (Default: last selected title)

_USAGE

main: {
	if ( $ARGV[0] =~ /^-(v|-?version)$/ ) {
		print $Video::DVDRip::VERSION,"\n";
		exit 0;
	}

	# get options
	my %opt;
	my $opt_ok = getopts ('cd:f:t:', \%opt);
	usage() if not $opt_ok;

	my $open_cluster_control = $opt{c};
	my $function = $opt{f};
	my $title_nr = $opt{t};

	usage() if $function and $function !~ /^(transcode|transcode_split)$/;

	# fetch filename paramter
	my $filename = shift @ARGV;

	# no more args allowed
	usage() if @ARGV;

	# set requested debugging level
	Video::DVDRip::GUI::Main->set_debug_level( $opt{d} || 0 );

	# create GUI object
	my $gui = Video::DVDRip::GUI::Main->new;

	# open preferences window on first startup?
	if ( not $has_dvdrip_rc ) {
		$function = "preferences";
	}

	# start GUI
	$gui->start (
		filename	     => $filename,
		open_cluster_control => $opt{c},
		function             => $function,
		select_title         => $title_nr,
	);


	END { Gtk->exit(0) }
}

sub usage {
	print $USAGE;
	exit 1;
}

__END__

=head1 NAME

dvd::rip - GUI for copying DVDs

=head1 SYNOPSIS

  dvdrip [-c] [-d level] [-f function [-t title-nr]] [filename]
  dvdrip --version | -version | -v

      -c open cluster control window

      -d set debugging level

      -f execute one of the following functions (needs filename)
	 transcode         transcode the selected title
	 transcode_split   transcode and split the selected title

      -t title-nr to which the function above should apply
	 (Default: last selected title)

=head1 DESCRIPTION

dvd::rip is an easy to use but nevertheless feature rich
DVD copy program for Linux and other Unices. It's written
in Perl and uses Gtk for the GUI part. Internally the Linux
video processing tool transcode is used for the most DVD and
generally video / audio related purposes.

You'll find all information regarding installation and usage of
dvd::rip in the README file shipped with the distribution or
on the dvd::rip homepage:

  http://www.exit1.org/dvdrip/

=head1 COPYRIGHT

Copyright (C) 2001-2002 by Joern Reder, All Rights Reserved.

This library is free software; you can redistribute it
and/or modify it under the same terms as Perl itself.

=head1 SEE ALSO

perl(1).

=cut
