Skip to content

Commit bf07159

Browse files
committed
added code to calculate the duration of an encode.
1 parent 12b3f53 commit bf07159

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

trunk/gui_text.pm

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ package gui_text;
1313
'query_stage' => 'show',
1414
'show_choice' => '',
1515
'episode_choice' => undef,
16+
'start_time' => 0,
17+
'end_time' => 0,
1618
@_ #allows user-specified attributes to override the defaults
1719
};
1820
return bless($self, $class);
@@ -25,7 +27,27 @@ package gui_text;
2527
# Clear the screen
2628
system('clear');
2729
# Stage "quit" means, well, quit...
28-
last if ($self->stage eq 'quit');
30+
if ($self->stage eq 'quit') {
31+
# Report the duration
32+
if ($self->{start_time} && $self->{end_time}) {
33+
my $seconds = $self->{end_time} - $self->{start_time};
34+
my $timestr = '';
35+
# How many hours?
36+
my $hours = int($seconds / 3600);
37+
$timestr .= $hours.'h ' if ($hours > 0);
38+
$seconds = $seconds % 3600;
39+
# Minutes
40+
my $minutes = int($seconds / 60);
41+
$timestr .= $minutes.'m ' if ($minutes > 0);
42+
$seconds = $seconds % 60;
43+
# Generate a nice
44+
$timestr .= $seconds.'s' if ($seconds > 0);
45+
# Notify the user
46+
$self->notify("Encode lasted: $timestr");
47+
}
48+
# Leave the loop so we can quit
49+
last;
50+
}
2951
# Are we asking the user which show to encode?
3052
if (!$self->{show_choice} || $self->stage eq 'show') {
3153
$self->query_shows;
@@ -146,7 +168,9 @@ package gui_text;
146168
<STDIN>;
147169
}
148170
elsif ($Functions[$choice-1]->{enabled}) {
171+
$self->{start_time} = time();
149172
$Functions[$choice-1]->execute($self->{episode_choice});
173+
$self->{end_time} = time();
150174
$self->stage('quit');
151175
}
152176
}

0 commit comments

Comments
 (0)