| 1 | # $Id: Content.pm 2269 2007-03-10 09:51:32Z 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 | |||
| 11 | package Video::DVDRip::Content; | ||
| 12 | use Locale::TextDomain qw (video.dvdrip); | ||
| 13 | |||
| 14 | use base Video::DVDRip::Base; | ||
| 15 | |||
| 16 | use Video::DVDRip::Title; | ||
| 17 | |||
| 18 | use Carp; | ||
| 19 | use strict; | ||
| 20 | |||
| 21 | sub project { shift->{project} } | ||
| 22 | sub titles { shift->{titles} } | ||
| 23 | sub selected_titles { shift->{selected_titles} } | ||
| 24 | |||
| 25 | sub set_titles { shift->{titles} = $_[1] } | ||
| 26 | sub set_selected_titles { shift->{selected_titles} = $_[1] } | ||
| 27 | |||
| 28 | sub set_project { | ||
| 29 | my $self = shift; | ||
| 30 | my ($project) = @_; | ||
| 31 | |||
| 32 | $self->{project} = $project; | ||
| 33 | |||
| 34 | return if not $self->titles; | ||
| 35 | |||
| 36 | foreach my $title ( values %{ $self->titles } ) { | ||
| 37 | $title->set_project($project); | ||
| 38 | next if not $title->subtitles; | ||
| 39 | foreach my $subtitle ( values %{ $title->subtitles } ) { | ||
| 40 | $subtitle->set_title($title); | ||
| 41 | } | ||
| 42 | foreach my $audio_track ( @{ $title->audio_tracks } ) { | ||
| 43 | $audio_track->set_title($title); | ||
| 44 | } | ||
| 45 | } | ||
| 46 | |||
| 47 | return $project; | ||
| 48 | } | ||
| 49 | |||
| 50 | sub new { | ||
| 51 | my $class = shift; | ||
| 52 | my %par = @_; | ||
| 53 | my ($project) = @par{'project'}; | ||
| 54 | |||
| 55 | my $self = { | ||
| 56 | project => $project, | ||
| 57 | titles => undef, | ||
| 58 | selected_titles => [], | ||
| 59 | }; | ||
| 60 | |||
| 61 | return bless $self, $class; | ||
| 62 | } | ||
| 63 | |||
| 64 | sub get_titles_by_nr { | ||
| 65 | my $self = shift; | ||
| 66 | |||
| 67 | $self->read_title_listing if not $self->titles; | ||
| 68 | |||
| 69 | my @titles = sort { $a->nr <=> $b->nr } values %{ $self->titles }; | ||
| 70 | |||
| 71 | return \@titles; | ||
| 72 | } | ||
| 73 | |||
| 74 | sub set_selected_title_nr { | ||
| 75 | my $self = shift; | ||
| 76 | my ($nr) = @_; | ||
| 77 | die "msg: " . __x( "Illegal title number {nr}", nr => $nr ) | ||
| 78 | unless exists $self->titles->{$nr}; | ||
| 79 | $self->set_selected_titles( [ $nr - 1 ] ); | ||
| 80 | return $nr; | ||
| 81 | } | ||
| 82 | |||
| 83 | sub selected_title_nr { | ||
| 84 | my $self = shift; | ||
| 85 | my $selected_titles = $self->selected_titles; | ||
| 86 | return if not $selected_titles; | ||
| 87 | return if @{$selected_titles} == 0; | ||
| 88 | return $self->titles->{ $selected_titles->[0] + 1 }->nr; | ||
| 89 | } | ||
| 90 | |||
| 91 | sub selected_title { | ||
| 92 | my $self = shift; | ||
| 93 | my $selected_titles = $self->selected_titles; | ||
| 94 | return if not $selected_titles; | ||
| 95 | return if @{$selected_titles} == 0; | ||
| 96 | return $self->titles->{ $selected_titles->[0] + 1 }; | ||
| 97 | } | ||
| 98 | |||
| 99 | sub select_longest_title { | ||
| 100 | my $self = shift; | ||
| 101 | |||
| 102 | my $selected_title; | ||
| 103 | foreach my $title ( values %{ $self->titles } ) { | ||
| 104 | $selected_title ||= $title; | ||
| 105 | if ( $title->runtime > $selected_title->runtime ) { | ||
| 106 | $selected_title = $title; | ||
| 107 | } | ||
| 108 | } | ||
| 109 | |||
| 110 | $self->set_selected_title_nr($selected_title->nr) | ||
| 111 | if $selected_title; | ||
| 112 | |||
| 113 | 1; | ||
| 114 | } | ||
| 115 | |||
| 116 | #--------------------------------------------------------------------- | ||
| 117 | # Methods for TOC reading | ||
| 118 | #--------------------------------------------------------------------- | ||
| 119 | |||
| 120 | sub get_probe_title_cnt_command { | ||
| 121 | my $self = shift; | ||
| 122 | |||
| 123 | my $data_source = $self->project->rip_data_source; | ||
| 124 | |||
| 125 | $data_source = quotemeta($data_source); | ||
| 126 | |||
| 127 | return "execflow tcprobe -H 10 -i $data_source && echo EXECFLOW_OK"; | ||
| 128 | } | ||
| 129 | |||
| 130 | sub get_read_toc_lsdvd_command { | ||
| 131 | my $self = shift; | ||
| 132 | |||
| 133 | my $data_source = $self->project->rip_data_source; | ||
| 134 | |||
| 135 | $data_source = quotemeta($data_source); | ||
| 136 | |||
| 137 | my $command | ||
| 138 | = "execflow lsdvd -a -n -c -s -v -Op $data_source 2>/dev/null"; | ||
| 139 | |||
| 140 | return $command; | ||
| 141 | } | ||
| 142 | |||
| 143 | 1; |