From 304ae35a96866a0fabaa71a4c6a5933ca0892486 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Thu, 1 Mar 2012 22:48:04 +0100 Subject: iconv --- videoadd.pl | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'videoadd.pl') diff --git a/videoadd.pl b/videoadd.pl index 5ad6462..589670f 100755 --- a/videoadd.pl +++ b/videoadd.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl -CAL +#!/usr/bin/perl -CADS # This program is free software. It comes without any warranty, to the # extent permitted by applicable law. You can redistribute it and/or @@ -12,6 +12,7 @@ $VERSION = "0.3, 01 March 2012"; use warnings; use strict; use utf8; +use feature "unicode_strings"; use Getopt::Long qw/:config noauto_abbrev no_ignore_case gnu_compat bundling permute nogetopt_compat @@ -25,6 +26,7 @@ use File::Spec::Functions; use File::Copy qw /move/; use Env qw /HOME/; use Switch qw /Perl6/; +use Encode; ################################################################################ @@ -299,7 +301,7 @@ if ( defined ($imdb{crit}) and &runIMDb() ) { or die "Can't print: $!"; my @options; foreach ( @matches ) { - print $_->{id}. ' - ' .$_->{title}. "\n" + print &iconv($_->{id}. ' - ' .$_->{title}. "\n") or die "Can't print: $!"; push @options, $_->{id}; } @@ -307,7 +309,7 @@ if ( defined ($imdb{crit}) and &runIMDb() ) { print "\n" or die "Can't print: $!"; $imdb{crit} = &question ( \@options, - "Choose an IMDb ID above, to retrieve data from:", + "Choose an IMDb ID above, to retrieve data for:", $options[0] ); } else { @@ -410,7 +412,7 @@ unless ( defined $ignoredb_flag ) { or die "Can't select: $!\n"; foreach my $c (@$customs) { if (grep {lc $_ eq lc $c->[1]} (keys %{$new{customs}})) { - $new{$c->[0]} = $new{customs}->{lc $c->[1]}; + $new{$c->[0]} = &iconv($new{customs}->{lc $c->[1]}); } } delete $new{customs}; @@ -428,6 +430,7 @@ unless ( defined $ignoredb_flag ) { my $sth_insgenre = $dbh->prepare( "INSERT INTO $config{prefix}genres SET name = ?" ) or die "Error: " .$dbh->errstr; foreach my $g (@{$new{genres}}) { + $g = &iconv($g); $sth_selgenre->execute ($g); my @gids = $sth_selgenre->fetchrow_array; die $sth_selgenre->errstr if $sth_selgenre->err; @@ -446,6 +449,10 @@ unless ( defined $ignoredb_flag ) { } delete $new{genres}; + foreach my $k (keys %new) { + $new{$k} = &iconv($new{$k}); + } + my @SET; if (&include('filedate') && defined $new{filedate}) { push @SET, "filedate = FROM_UNIXTIME($new{filedate})"; @@ -521,6 +528,7 @@ unless ( defined $ignoredb_flag ) { $sth_insgenre->finish; } + print "\b" or die "Can't print: $!"; print LOG "Check it out! ", $config{url}. "/show.php?id=" .$id, "\n" or die "Can't print: $!"; } @@ -628,7 +636,8 @@ sub code2lang { sub mkcast { no warnings 'uninitialized'; - return $_->{name}. '::' .$_->{role}. '::imdb:' .$_->{id}; + my $s = $_->{name}. '::' .$_->{role}. '::imdb:' .$_->{id}; + return $s; } # Try to find a matching entry in the database. @@ -664,7 +673,7 @@ sub getfile { my @options; foreach my $id (keys $res) { printf "%04d - ", $res->{$id}->{id} or die "Can't printf: $!"; - print $res->{$id}->{title}. " (" .$res->{$id}->{year}. ")\n" + print &iconv($res->{$id}->{title}. " (" .$res->{$id}->{year}. ")\n") or die "Can't print: $!"; push @options, sprintf ("%04d", $res->{$id}->{id}); } @@ -788,3 +797,18 @@ sub YNquestion { return &question ( ['y','n'], $question, $default, $pdefault ); } + +# Convert to UTF-8 +sub iconv { + my $string = $_[0]; + return unless defined $string; + + unless (Encode::is_utf8($string)) { + $string = Encode::decode( 'latin1', my $copy = $string, 1 ); + } + + # The UTF-8 flag should be on now + warn "Warning: Not a valid Unicode string: \"$string\"\n" + unless utf8::valid($string); + return $string; +} -- cgit v1.2.3