1# $Id: SrtxFile.pm 2187 2006-08-16 19:34:38Z joern $ 2 3#----------------------------------------------------------------------- 4# Copyright (C) 2001-2006 J�rn Reder <joern AT zyn.de>. 5# All Rights Reserved. See file COPYRIGHT for details. 6# 7# This module is part of Video::DVDRip, which is free software; you can 8# redistribute it and/or modify it under the same terms as Perl itself. 9#----------------------------------------------------------------------- 10 11package Video::DVDRip::SrtxFile; 12use Locale::TextDomain qw (video.dvdrip); 13 14use base Video::DVDRip::Base; 15 16use Carp; 17use strict; 18 19use FileHandle; 20 21sub get_filename { shift->{filename} } 22sub get_fh { shift->{fh} } 23 24sub set_filename { shift->{filename} = $_[1] } 25sub set_fh { shift->{fh} = $_[1] } 26 27sub new { 28 my $class = shift; 29 my %par = @_; 30 my ($filename) = @par{'filename'}; 31 32 my $self = bless { 33 filename => $filename, 34 fh => FileHandle->new, 35 }, $class; 36 37 return $self; 38} 39 40sub set_filename_from_dir { 41 my $self = shift; 42 my ($dir) = @_; 43 my $filename = ( glob("$dir/{*.srtx,.*srtx}") )[0]; 44 return $self->set_filename($filename); 45} 46 47sub open { 48 my $self = shift; 49 50 my $fh = $self->get_fh; 51 my $filename = $self->get_filename; 52 53 open( $fh, $filename ) or die "can't read $filename"; 54 55 1; 56} 57 58sub close { 59 my $self = shift; 60 61 close( $self->get_fh ); 62 63 1; 64} 65 66sub read_entry { 67 my $self = shift; 68 69 my $fh = $self->get_fh; 70 71 chomp( my $nr = <$fh> ); 72 chomp( my $time = <$fh> ); 73 chomp( my $image_file = <$fh> ); 74 <$fh>; 75 76 return 77 unless defined $nr 78 and defined $time 79 and defined $image_file; 80 81 $image_file =~ s/\.pgm\.txt$//; 82 83 if ( -f "$image_file.pgm" ) { 84 $image_file .= ".pgm"; 85 } 86 elsif ( -f "$image_file.png" ) { 87 $image_file .= ".png"; 88 } 89 else { 90 $image_file = undef; 91 } 92 93 return Video::DVDRip::SrtxFileEntry->new( 94 nr => $nr, 95 time => $time, 96 image_file => $image_file, 97 ); 98} 99 100package Video::DVDRip::SrtxFileEntry; 101 102sub get_nr { shift->{nr} } 103sub get_time { shift->{time} } 104sub get_time_sec { shift->{time_sec} } 105sub get_image_file { shift->{image_file} } 106 107sub set_nr { shift->{nr} = $_[1] } 108sub set_time { shift->{time} = $_[1] } 109sub set_time_sec { shift->{time_sec} = $_[1] } 110sub set_image_file { shift->{image_file} = $_[1] } 111 112sub new { 113 my $class = shift; 114 my %par = @_; 115 my ( $nr, $time, $image_file ) = @par{ 'nr', 'time', 'image_file' }; 116 117 ($time) = $time =~ /^(\d\d:\d\d:\d\d)/; 118 $time =~ /^(\d\d):(\d\d):(\d\d)/; 119 120 my $time_sec = $3 + $2 * 60 + $1 * 3600; 121 122 my $self = bless { 123 nr => $nr, 124 time => $time, 125 time_sec => $time_sec, 126 image_file => $image_file, 127 }, $class; 128 129 return $self; 130} 131 1321; 133