Skip to content

Commit

Permalink
Cue the beeping noises and back this truck up, Nuvexport -> Mythextras.
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert McNamara committed Mar 23, 2010
1 parent 5c9c0f3 commit 3172afa
Show file tree
Hide file tree
Showing 34 changed files with 6,806 additions and 0 deletions.
3 changes: 3 additions & 0 deletions nuvexport/COPYING
@@ -0,0 +1,3 @@
This program is distributed under the terms of the GPL, version 2 only.
If you don't have a copy of the GPL, get one at:
http://www.gnu.org/licenses/gpl.txt
93 changes: 93 additions & 0 deletions nuvexport/Makefile
@@ -0,0 +1,93 @@
#
# Makefile for installing nuvexport
#

BINS = nuvexport nuvinfo

CONF = nuvexportrc

EXPORT_MODULES = export/generic.pm \
export/ffmpeg.pm \
export/transcode.pm \
export/mencoder.pm \
export/NUV_SQL.pm \
export/transcode/DVCD.pm \
export/transcode/DVD.pm \
export/transcode/SVCD.pm \
export/transcode/VCD.pm \
export/transcode/XviD.pm \
export/ffmpeg/XviD.pm \
export/ffmpeg/DivX.pm \
export/ffmpeg/MP3.pm \
export/ffmpeg/ASF.pm \
export/ffmpeg/SVCD.pm \
export/ffmpeg/DVCD.pm \
export/ffmpeg/DVD.pm \
export/ffmpeg/VCD.pm \
export/ffmpeg/PSP.pm \
export/ffmpeg/MP4.pm \
export/mencoder/XviD.pm
MODULE_SUBDIRS = transcode \
ffmpeg \
mencoder
MYTHTV_MODULES = mythtv/nuvinfo.pm \
mythtv/recordings.pm
NUVEXPORT_MODULES = nuv_export/help.pm \
nuv_export/shared_utils.pm \
nuv_export/task.pm \
nuv_export/cli.pm \
nuv_export/ui.pm
MODULES = ${EXPORT_MODULES} ${MYTHTV_MODULES} ${NUVEXPORT_MODULES}

NUVEXPORT_LINKS = divx dvcd dvd mp3 nuvsql svcd vcd asf xvid

OWNER =

INSTALL = /usr/bin/install

prefix=/usr/local
bindir=${prefix}/bin
datadir=${prefix}/share
sysconfdir=/etc

MODDIR=${datadir}/nuvexport

default:
@echo "Use \"make install\" to install the new version and \"make uninstall\" to remove this version"

install:
# First the binaries
@for i in ${BINS} ; do \
${INSTALL} -Dv ${OWNER} -m 0755 $$i ${bindir}/$$i; \
done
# Then the config file(s)
@for i in ${CONF} ; do \
if [ -e "${sysconfdir}"/"$$i" ]; then \
${INSTALL} -Dv ${OWNER} -m 0755 $$i ${sysconfdir}/$$i.dist; \
else \
${INSTALL} -Dv ${OWNER} -m 0755 $$i ${sysconfdir}/$$i; \
fi \
done
# Install the mode symlinks
@for i in ${NUVEXPORT_LINKS} ; do \
ln -fs nuvexport ${bindir}/nuvexport-$$i; \
done
# Install the modules
@for i in ${MODULES} ; do \
${INSTALL} -Dv ${OWNER} -m 0755 $$i ${MODDIR}/$$i; \
done

uninstall:
# First the binaries
@for i in ${BINS} ; do \
rm -f ${bindir}/$$i; \
done
# Remove the mode symlinks
@for i in ${NUVEXPORT_LINKS} ; do \
rm -f ${bindir}/nuvexport-$$i; \
done
# Remove the modules
@for i in ${MODULES} ; do \
rm -f ${MODDIR}/$$i; \
done

171 changes: 171 additions & 0 deletions nuvexport/export/NUV_SQL.pm
@@ -0,0 +1,171 @@
#
# $Date$
# $Revision$
# $Author$
#
# export::NUV_SQL
# Maintained by Chris Petersen <mythtv@forevermore.net>
#

package export::NUV_SQL;
use base 'export::generic';

use File::Copy;
use File::Basename;
use DBI;
use Term::ANSIColor;
use MythTV;

# Load the myth and nuv utilities, and make sure we're connected to the database
use nuv_export::shared_utils;
use nuv_export::cli;
use nuv_export::ui;
use mythtv::recordings;

sub new {
my $class = shift;
my $self = {
'cli' => qr/\bnuv[\-_]?sql\b/i,
'name' => 'Export to .nuv and .sql',
'enabled' => 1,
'errors' => [],
# Delete original files?
'delete' => 0,
'create_dir' => 1,
};
bless($self, $class);

# Any errors? disable this function
$self->{'enabled'} = 0 if ($self->{'errors'} && @{$self->{'errors'}} > 0);
# Return
return $self;
}

# Load default settings
sub load_defaults {
my $self = shift;
# Load the parent module's settings
$self->SUPER::gather_settings();
# Not really anything to add
}

# Gather settings from the user
sub gather_settings {
my $self = shift;
# Let the user know what's going on
print "\nYou have chosen to extract the .nuv.\n"
."This will extract it from the MythTV database into .nuv and .sql \n"
."files to import into another MythTV installation.\n\n";
# Make sure the user knows what he/she is doing
$self->{'delete'} = query_text("Do you want to remove it from this server when finished?",
'yesno',
$self->{'delete'} ? 'Yes' : 'No');
# Make EXTRA sure
if ($self->{'delete'}) {
$self->{'delete'} = query_text("\nAre you ".colored('sure', 'bold').' you want to remove it from this server?',
'yesno',
'No');
}
# Create a directory with the show name
$self->{'create_dir'} = query_text('Store exported files in a directory with the show name?',
'yesno',
$self->{'create_dir'} ? 'Yes' : 'No');
# Load the save path, if requested
$self->{'path'} = query_savepath($self->val('path'));
}

sub export {
my $self = shift;
my $episode = shift;
# Create a show-name directory?
if ($self->{'create_dir'}) {
$self->{'export_path'} = $self->get_outfile($episode, '');
mkdir($self->{'export_path'}, 0755) or die "Can't create $self->{'export_path'}: $!\n\n";
}
else {
$self->{'export_path'} = $self->{'path'};
}
# Load the three files we'll be using
my $txt_file = basename($episode->{'local_path'}, '.nuv') . '.txt';
my $sql_file = basename($episode->{'local_path'}, '.nuv') . '.sql';
my $nuv_file = basename($episode->{'local_path'});
# Create a txt file with descriptive info in it
open(DATA, ">$self->{'export_path'}/$txt_file") or die "Can't create $self->{'export_path'}/$txt_file: $!\n\n";
print DATA ' Show: ', $episode->{'title'}, "\n",
' Episode: ', $episode->{'subtitle'}, "\n",
' Recorded: ', $episode->{'showtime'}, "\n",
'Description: ', wrap($episode->{'description'}, 64,'', '', "\n "), "\n",
"\n",
' Orig. File: ', $episode->{'local_path'}, "\n",
' Type: ', $episode->{'finfo'}{'video_type'}, "\n",
' Dimensions: ', $episode->{'finfo'}{'width'}.'x'.$episode->{'finfo'}{'height'}, "\n",
;
close DATA;
# Start saving the SQL
open(DATA, ">$self->{'export_path'}/$sql_file") or die "Can't create $self->{'export_path'}/$sql_file: $!\n\n";
# Define some query-related variables
my ($q, $sh);
# Load and save the related database info
print DATA "USE mythconverg;\n\n";
foreach $table ('recorded', 'oldrecorded', 'recordedmarkup', 'recordedseek') {
$q = "SELECT * FROM $table WHERE chanid=? AND starttime=FROM_UNIXTIME(?)";
$sh = $Main::Myth->{'dbh'}->prepare($q);
$sh->execute($episode->{'chanid'}, $episode->{'recstartts'})
or die "Count not execute ($q): $!\n\n";
my $count = 0;
my @keys = undef;
while (my $row = $sh->fetchrow_hashref) {
# First row - let's add the insert statement;
if ($count++ == 0) {
@keys = keys(%$row);
print DATA "INSERT INTO $table (", join(', ', @keys), ") VALUES\n\t(";
}
else {
print DATA ",\n\t(";
}
# Print the data
my $count2 = 0;
foreach $key (@keys) {
print DATA ', ' if ($count2++);
print DATA mysql_escape($row->{$key});
}
print DATA ')';
}
print DATA ";\n\n";
}
# Done saving the database info
close DATA;
# Copy/link the file into place
print "\nCopying $episode->{'local_path'} to $self->{'export_path'}/$nuv_file\n";
# Use hard links when copying within a filesystem
if ((stat($episode->{'local_path'}))[0] == (stat($self->{'path'}))[0]) {
link($episode->{'local_path'}, "$self->{'export_path'}/$nuv_file")
or die "Couldn't hard link specified .nuv file: $!\n\n";
}
else {
copy($episode->{'local_path'}, "$self->{'export_path'}/$nuv_file")
or die "Couldn't copy specified .nuv file: $!\n\n";
}
# Delete the record?
if ($self->{'delete'}) {
print "Deleting from MythTV\n";
$Main::Myth->backend_command(['FORCE_DELETE_RECORDING', $episode->to_string()], '0');
}
}

sub cleanup {
# Nothing to do here
}

# Escape a string for MySQL
sub mysql_escape {
$string = shift;
return 'NULL' unless (defined $string);
$string =~ s/'/\\'/sg;
return "'$string'";
}


1; #return true

# vim:ts=4:sw=4:ai:et:si:sts=4

0 comments on commit 3172afa

Please sign in to comment.