Skip to content

Commit

Permalink
Add --save_info parameter to save a mythvideo-friendly descriptive .t…
Browse files Browse the repository at this point in the history
…xt file, and clean out a previous version of the command, which shouldn't have been committed (got lost during the move to the mythtv svn repo).

This also moves name formatting over to the perl bindings' name formatting routine rather than something specific to nuvexport.
  • Loading branch information
ex-nerd committed Dec 7, 2006
1 parent 366bb97 commit faf7a13
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 104 deletions.
35 changes: 16 additions & 19 deletions nuvexport/export/NUV_SQL.pm
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,24 @@ package export::NUV_SQL;
# Gather settings from the user
sub gather_settings {
my $self = shift;
# Only ask for data if we're actually extracting a file
if (!arg('only_save_info')) {
# 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?",
# 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',
$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');
'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'));
}
Expand Down
100 changes: 16 additions & 84 deletions nuvexport/export/generic.pm
Original file line number Diff line number Diff line change
Expand Up @@ -196,68 +196,23 @@ package export::generic;
my $self = shift;
my $episode = shift;
my $suffix = ($self->{'suffix'} or shift);
# Build a clean filename
my $outfile;
if ($episode->{'outfile'}{$suffix}) {
$outfile = $episode->{'outfile'}{$suffix};
}
else {
# Specified a name format
if ($outfile = $self->val('filename')) {
# Generate a list
my %field;
($field{'c'} = ($episode->{'chanid'} or '')) =~ s/%/%%/g;
($field{'a'} = ($episode->{'showtime'} or '')) =~ s/%/%%/g;
($field{'b'} = ($episode->{'endtime'} or '')) =~ s/%/%%/g;
($field{'t'} = ($episode->{'title'} or '')) =~ s/%/%%/g; # title
($field{'s'} = ($episode->{'subtitle'} or '')) =~ s/%/%%/g; # subtitle/episode
($field{'h'} = ($episode->{'host'} or '')) =~ s/%/%%/g;
($field{'m'} = ($episode->{'showtime'} or '')) =~ s/%/%%/g;
($field{'d'} = ($episode->{'description'} or '')) =~ s/%/%%/g;
# Make the substitution
my $keys = join('', sort keys %field);
$outfile =~ s/(?<!%)(?:%([$keys]))/$field{$1}/g;
$outfile =~ s/%%/%/g;
# Specified a name format
my $outfile = $self->val('filename');
$outfile ||= '%T - %S';
# Format
$outfile = $episode->format_name($outfile, '-', '-', 0, $self->val('underscores'));
# Avoid some "untitled" messiness
$outfile =~ s/\s+-\s+Untitled//sg;
# Make sure we don't have a duplicate filename
if (-e $self->{'path'}.'/'.$outfile.$suffix) {
my $count = 1;
my $out = $outfile;
while (-e $self->{'path'}.'/'.$out.$suffix) {
$count++;
$out = "$outfile.$count";
}
# Default format
else {
if ($episode->{'title'} ne 'Untitled' and $episode->{'subtitle'} ne 'Untitled') {
$outfile = $episode->{'title'}.' - '.$episode->{'subtitle'};
}
elsif($episode->{'title'} ne 'Untitled') {
$outfile = $episode->{'title'};
}
elsif($episode ne 'Untitled') {
$outfile = $episode->{'subtitle'};
}
else {
$outfile = 'Untitled';
}
}
# Some basic cleanup for illegal (windows) filename characters, etc.
$outfile =~ tr/\ \t\r\n/ /s;
$outfile =~ tr/"/'/s;
$outfile =~ s/(?:[\-\/\\:*?<>|]+\s*)+(?=[^\d\s])/- /sg;
$outfile =~ tr/\/\\:*?<>|/-/;
$outfile =~ s/^[\-\ ]+//s;
$outfile =~ s/[\-\ ]+$//s;
# add underscores?
if ($self->val('underscores')) {
$outfile =~ tr/ /_/s;
}
# Make sure we don't have a duplicate filename
if (-e $self->{'path'}.'/'.$outfile.$suffix) {
my $count = 1;
my $out = $outfile;
while (-e $self->{'path'}.'/'.$out.$suffix) {
$count++;
$out = "$outfile.$count";
}
$outfile = $out;
}
# Store it so we don't have to recalculate this next time
$episode->{'outfile'}{$suffix} = $outfile;
}
$outfile = $out;
}
# return
return $self->{'path'}.'/'.$outfile.$suffix;
}
Expand Down Expand Up @@ -308,29 +263,6 @@ package export::generic;
}
}

# Save program details
sub save_txt_details {
my $self = shift;
my $episode = shift;
my $outfile = $self->get_outfile($episode, '.txt');
# Some clean versions of the various fields
my $clean_desc = $episode->{'description'};
$clean_desc =~ tr/\n/ /;
my $clean_subtitle = $episode->{'subtitle'};
$clean_subtitle = '' if ($clean_subtitle eq 'Untitled');
# Save the file
print "Saving details to: $outfile\n";
open(DATA, ">$outfile") or die "Can't create $outfile: $!\n";
print DATA <<EOF;
title: $episode->{'title'}
subtitle: $clean_subtitle
description: $clean_desc
channel: $episode->{'callsign'}, $episode->{'channame'}
airdate: $episode->{'showtime'}
EOF
close DATA;
}

# This subroutine forks and executes one system command - nothing fancy
sub fork_command {
my $command = shift;
Expand Down
23 changes: 22 additions & 1 deletion nuvexport/nuvexport
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
our $Myth = new MythTV();

# Load the myth and nuv utilities, and connect to the database
use Date::Manip;
use nuv_export::shared_utils;
use nuv_export::cli;
use nuv_export::ui;
Expand Down Expand Up @@ -146,7 +147,27 @@
foreach my $episode (@episodes) {
# Save the info?
if (arg('save_info') || arg('only_save_info')) {
$exporter->save_txt_details($episode);
my $outfile = $exporter->get_outfile($episode, '.txt');
open(DATA, ">$outfile") or die "Can't create $outfile: $!\n";
print DATA join("\n", 'title: '.$episode->{'title'},
'subtitle: '.($episode->{'subtitle'} eq 'Untitled' ? '' : $episode->{'subtitle'}),
'description: '.($episode->{'description'} eq 'No Description' ? '' : $episode->{'description'}),
'starttime: '.UnixDate("epoch $episode->{'starttime'}", '%O'),
'endtime: '.UnixDate("epoch $episode->{'endtime'}", '%O'),
'category: '.$episode->{'category'},
'chanid: '.$episode->{'chanid'},
'channum: '.$episode->{'channum'},
'callsign: '.$episode->{'callsign'},
'channame: '.$episode->{'channame'},
'airdate: '.UnixDate("epoch $episode->{'airdate'}", '%O'),
'stars: '.(4 * $episode->{'stars'}),
'recgroup: '.$episode->{'recgroup'},
'seriesid: '.$episode->{'seriesid'},
'programid: '.$episode->{'programid'},
''
);
close DATA;
# Skip ahead if we're not supposed to actually export recordings
next if (arg('only_save_info'));
}
# Keep track of when we started
Expand Down
6 changes: 6 additions & 0 deletions nuvexport/nuvexportrc
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@
# crop_bottom = 2
# crop_left = 2

#
# Export a matching .txt file, which mythvideo can use to import information
# about your exports, since it likely can't look them up in imdb.
#
save_info = yes

</nuvexport>

#
Expand Down

0 comments on commit faf7a13

Please sign in to comment.