Skip to content

Commit 3a4c71b

Browse files
committed
split nuvexport out into multiple files
created an install.sh it's still a mess, needs a lot of cleaning
1 parent d8f76c3 commit 3a4c71b

File tree

9 files changed

+1397
-1322
lines changed

9 files changed

+1397
-1322
lines changed

trunk/export_DivX.pm

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
package export_DivX;
2+
3+
# Load the nuv utilities
4+
use nuv_utils;
5+
6+
# Make sure we have pointers to the main:: namespace for certain variables
7+
*Prog = *main::Prog;
8+
*gui = *main::gui;
9+
10+
sub new {
11+
my $class = shift;
12+
my $self = {
13+
'name' => 'Export DivX',
14+
'enabled' => 1,
15+
'errors' => undef,
16+
'episode' => undef,
17+
'savepath' => '.',
18+
'outfile' => 'out.avi',
19+
'use_cutlist' => 0,
20+
'a_bitrate' => 64,
21+
'v_bitrate' => 256,
22+
'h_res' => 320,
23+
'v_res' => 240,
24+
'sql_file' => undef,
25+
@_ #allows user-specified attributes to override the defaults
26+
};
27+
bless($self, $class);
28+
# Return
29+
return $self;
30+
}
31+
32+
sub gather_data {
33+
my $self = shift;
34+
my $default_filename;
35+
# Get the save path
36+
$self->{savepath} = $gui->query_savepath();
37+
# Ask the user for the filename
38+
if($self->{episode}->{show_name} ne 'Untitled' and $self->{episode}->{title} ne 'Untitled')
39+
{
40+
$default_filename = $self->{episode}->{show_name}.' - '.$self->{episode}->{title};
41+
}
42+
elsif($self->{episode}->{show_name} ne 'Untitled')
43+
{
44+
$default_filename = $self->{episode}->{show_name};
45+
}
46+
elsif($self->{episode}->{title} ne 'Untitled')
47+
{
48+
$default_filename = $self->{episode}->{title};
49+
}
50+
51+
$self->{outfile} = $gui->query_filename($default_filename, 'avi', $self->{savepath});
52+
# Ask the user if he/she wants to use the cutlist
53+
if ($self->{episode}->{cutlist} && $self->{episode}->{cutlist} =~ /\d/) {
54+
$self->{use_cutlist} = $gui->query_text('Enable Myth cutlist?',
55+
'yesno',
56+
$self->{use_cutlist} ? 'Yes' : 'No');
57+
}
58+
else {
59+
$gui->notify('No cutlist found. Hopefully this means that you already removed the commercials.');
60+
}
61+
# Ask the user what audio bitrate he/she wants
62+
my $a_bitrate = $gui->query_text('Audio bitrate?',
63+
'int',
64+
$self->{a_bitrate});
65+
$self->{a_bitrate} = $a_bitrate;
66+
# Ask the user what video bitrate he/she wants
67+
my $v_bitrate = $gui->query_text('Video bitrate?',
68+
'int',
69+
$self->{v_bitrate});
70+
$self->{v_bitrate} = $v_bitrate;
71+
# Ask the user what horiz res he/she wants
72+
my $h_res = $gui->query_text('Horizontal resolution?', 'int', $self->{h_res});
73+
$self->{h_res} = $h_res;
74+
# Ask the user what vert res he/she wants
75+
my $v_res = $gui->query_text('Vertical resolution?', 'int', $self->{v_res});
76+
$self->{v_res} = $v_res;
77+
}
78+
79+
sub execute {
80+
my $self = shift;
81+
# make sure that the fifo dir is clean
82+
if (-e 'fifodir/vidout' || -e 'fifodir/audout') {
83+
die "Possibly stale mythtranscode fifo's in fifodir.\nPlease remove them before running nuvexport.\n\n";
84+
}
85+
# Gather any necessary data
86+
$self->{episode} = shift;
87+
$self->gather_data;
88+
# Load nuv info
89+
my %nuv_info = nuv_info($self->{episode}->{filename});
90+
# Set this to true so that the cleanup routine actually runs
91+
$self->{started} = 1;
92+
# Create a directory for mythtranscode's fifo's
93+
unless (-d 'fifodir') {
94+
mkdir('fifodir', 0755) or die "Can't create fifodir: $!\n\n";
95+
}
96+
# Here, we have to fork off a copy of mythtranscode
97+
my $command = "nice -n 19 mythtranscode -p autodetect -c $self->{episode}->{channel} -s $self->{episode}->{start_time_sep} -f fifodir";
98+
$command .= ' --honorcutlist' if ($self->{use_cutlist});
99+
push @{$self->{children}}, fork_command($command);
100+
# Sleep a bit to let mythtranscode start up
101+
my $overload = 0;
102+
while (++$overload < 30 && !(-e 'fifodir/audout' && -e 'fifodir/vidout')) {
103+
sleep 1;
104+
print "Waiting for mythtranscode to set up the fifos.\n";
105+
}
106+
unless (-e 'fifodir/audout' && -e 'fifodir/vidout') {
107+
die "Waited too long for mythtranscode to create its fifos. Please try again.\n\n";
108+
}
109+
# Now we fork off a process to encode everything
110+
$safe_outfile = shell_escape($self->{outfile});
111+
$command = "nice -n 19 ffmpeg -y -f s16le -ar $nuv_info{audio_sample_rate} -ac 2 -i fifodir/audout -f rawvideo -s $nuv_info{width}x$nuv_info{height} -r $nuv_info{fps} -i fifodir/vidout -b $self->{v_bitrate} -ab $self->{a_bitrate} -s $self->{h_res}x$self->{v_res} $safe_outfile";
112+
push @{$self->{children}}, fork_command($command);
113+
# Wait for child processes to finish
114+
1 while (wait > 0);
115+
$self->{children} = undef;
116+
}
117+
118+
sub cleanup {
119+
my $self = shift;
120+
return unless ($self->{started});
121+
# Make sure any child processes also go away
122+
if ($self->{children} && @{$self->{children}}) {
123+
foreach my $child (@{$self->{children}}) {
124+
kill('INT', $child);
125+
}
126+
1 while (wait > 0);
127+
}
128+
# Remove any temporary files
129+
foreach my $file ('fifodir/audout', 'fifodir/vidout') {
130+
unlink $file if (-e $file);
131+
}
132+
rmdir 'fifodir' if (-e 'fifodir');
133+
}
134+
135+
1; #return true

trunk/export_NUV_SQL.pm

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
package export_NUV_SQL;
2+
3+
use File::Copy;
4+
5+
# Load the nuv utilities
6+
use nuv_utils;
7+
8+
# Make sure we have pointers to the main:: namespace for certain variables
9+
*Prog = *main::Prog;
10+
*gui = *main::gui;
11+
12+
sub new {
13+
my $class = shift;
14+
my $self = {
15+
'name' => 'Extract .nuv and .sql',
16+
'enabled' => 1,
17+
'errors' => undef,
18+
'episode' => undef,
19+
'savepath' => '.',
20+
'sql_file' => undef,
21+
'copy' => undef,
22+
@_ #allows user-specified attributes to override the defaults
23+
};
24+
bless($self, $class);
25+
# Return
26+
return $self;
27+
}
28+
29+
sub gather_data {
30+
my $self = shift;
31+
# Make sure the user knows what he/she is doing
32+
my $copy = 0;
33+
34+
if($gui->query_text("\nYou have chosen to extract the .nuv.\n"
35+
."This will extract it from the MythTV database into .nuv and .sql \n"
36+
."files to import into another MythTV installation.\n"
37+
# Make sure the user made the correct choice
38+
."Do you want to removed it from this server when finished?",
39+
'yesno',
40+
'Yes'))
41+
{
42+
if($gui->query_text("\nAre you sure you want to remove it from this server?",
43+
'yesno',
44+
'Yes'))
45+
{
46+
$self->{copy}=0;
47+
}
48+
else
49+
{
50+
$self->{copy}=1;
51+
}
52+
}
53+
else
54+
{
55+
$self->{copy}=1;
56+
}
57+
58+
# Get the savepath
59+
$self->{savepath} = $gui->query_savepath();
60+
}
61+
62+
sub execute {
63+
my $self = shift;
64+
# Gather any necessary data
65+
$self->{episode} = shift;
66+
$self->gather_data;
67+
# Start saving
68+
($self->{sql_file} = $self->{episode}->{filename}) =~ s/\.nuv$/.sql/si;
69+
open(DATA, ">$self->{savepath}/$self->{sql_file}") or die "Can't create $self->{savepath}/$self->{sql_file}: $!\n\n";
70+
# Define some query-related variables
71+
my ($q, $sh);
72+
# Load and save the related database info
73+
print DATA "USE mythconverg;\n\n";
74+
foreach $table ('recorded', 'oldrecorded', 'recordedmarkup') {
75+
$q = "SELECT * FROM $table WHERE chanid=? AND starttime=?";
76+
$sh = $dbh->prepare($q);
77+
$sh->execute($self->{episode}->{channel}, $self->{episode}->{start_time})
78+
or die "Count not execute ($q): $!\n\n";
79+
my $count = 0;
80+
my @keys = undef;
81+
while (my $row = $sh->fetchrow_hashref) {
82+
# First row - let's add the insert statement;
83+
if ($count++ == 0) {
84+
@keys = keys(%$row);
85+
print DATA "INSERT INTO $table (", join(', ', @keys), ") VALUES\n\t(";
86+
}
87+
else {
88+
print DATA ",\n\t(";
89+
}
90+
# Print the data
91+
my $count2 = 0;
92+
foreach $key (@keys) {
93+
print DATA ', ' if ($count2++);
94+
print DATA mysql_escape($row->{$key});
95+
}
96+
print DATA ')';
97+
}
98+
print DATA ";\n\n";
99+
}
100+
# Done savig the database info
101+
close DATA;
102+
# Rename/move the file
103+
print "copy=$self->{copy}\n";
104+
if($self->{copy}==1)
105+
{
106+
$gui->notify("\nCopying $video_dir/$self->{episode}->{filename} to $self->{savepath}/$self->{episode}->{filename}\n");
107+
copy("$video_dir/$self->{episode}->{filename}", "$self->{savepath}/$self->{episode}->{filename}")
108+
or die "Couldn't copy specified .nuv file: $!\n\n";
109+
}
110+
else
111+
{
112+
$gui->notify("\nMoving $video_dir/$self->{episode}->{filename} to $self->{savepath}/$self->{episode}->{filename}\n");
113+
move("$video_dir/$self->{episode}->{filename}", "$self->{savepath}/$self->{episode}->{filename}")
114+
or die "Couldn't move specified .nuv file: $!\n\n";
115+
# Remove the entry from recordedmarkup
116+
$q = 'DELETE FROM recordedmarkup WHERE chanid=? AND starttime=?';
117+
$sh = $dbh->prepare($q);
118+
$sh->execute($self->{episode}->{channel}, $self->{episode}->{start_time})
119+
or die "Could not execute ($q): $!\n\n";
120+
# Remove this entry from the database
121+
$q = 'DELETE FROM recorded WHERE chanid=? AND starttime=? AND endtime=?';
122+
$sh = $dbh->prepare($q);
123+
$sh->execute($self->{episode}->{channel}, $self->{episode}->{start_time}, $self->{episode}->{end_time})
124+
or die "Could not execute ($q): $!\n\n";
125+
# Tell the other nodes that changes have been made
126+
$q = 'UPDATE settings SET data="yes" WHERE value="RecordChanged"';
127+
$sh = $dbh->prepare($q);
128+
$sh->execute()
129+
or die "Could not execute ($q): $!\n\n";
130+
}
131+
}
132+
133+
sub cleanup {
134+
# Nothing to do here
135+
}
136+
137+
1; #return true

0 commit comments

Comments
 (0)