Description: Decode raw octets (default to UTF-8) in Get_nice
Forwarded: not-needed
Author: Nick Morrott <knowledgejunkie@gmail.com>
Last-Update: 2015-07-01

--- a/grab/Get_nice.pm
+++ b/grab/Get_nice.pm
@@ -38,6 +38,7 @@
 
 use base 'Exporter';
 our @EXPORT = qw(get_nice get_nice_tree get_nice_xml get_nice_json error_msg);
+use Encode qw(decode);
 use LWP::UserAgent;
 use XMLTV;
 our $Delay = 5; # in seconds
@@ -78,9 +79,10 @@
     my $content = get_nice $uri;
     $content = $filter->($content) if $filter;
     if ($codepage) {
-      # (note: HTML::Parser->utf8_mode is only available Perl 5.8) 
-      require Encode; import Encode;
-      $content = decode($codepage, $content);
+        $content = decode($codepage, $content);
+    }
+    else {
+        $content = decode('UTF-8', $content);
     }
     my $t = HTML::TreeBuilder->new();
 		$t->ignore_unknown(!$IncludeUnknownTags);
@@ -101,9 +103,11 @@
     my $content = get_nice $uri;
     $content = $filter->($content) if $filter;
     if ($codepage) {
-      require Encode; import Encode;
       $content = decode($codepage, $content);
     }
+    else {
+      $content = decode('UTF-8', $content);
+    }
     my $t = XML::Parser->new(Style => 'Tree')->parse($content) or die "cannot parse content of $uri\n";
     return $t;
 }
--- a/grab/uk_tvguide/tv_grab_uk_tvguide
+++ b/grab/uk_tvguide/tv_grab_uk_tvguide
@@ -198,7 +198,7 @@
 				if (defined(&map_channel_id)) { $xmlchannel_id = map_channel_id($channel_id); }
 				
 				# Fetch the page
-				my $tree = XMLTV::Get_nice::get_nice_tree($url, \&utf8);
+				my $tree = XMLTV::Get_nice::get_nice_tree($url);
 				# $tree->dump; exit;
 
 				# Scrub the page
@@ -253,7 +253,7 @@
 							#debug "Fetching: $url";
 
 							# Fetch the page
-							my $treedetail = XMLTV::Get_nice::get_nice_tree($url, \&utf8);
+							my $treedetail = XMLTV::Get_nice::get_nice_tree($url);
 							
 							# 	<table border="0" cellpadding="0" style="background:black;border-collapse: collapse;background-image: url(http://i.g8.tv/logobackgrounds/857.jpg); background-repeat: no-repeat;" width="677" height="258px" id="table3" >		
 					
@@ -760,7 +760,7 @@
   }) unless ($opt->{quiet} || $opt->{debug});
 
   # Get the page containing the list of channels 
-  my $tree = XMLTV::Get_nice::get_nice_tree($channel_list, \&utf8);
+  my $tree = XMLTV::Get_nice::get_nice_tree($channel_list);
 	#		$tree->dump;
   my $_channels = $tree->look_down('_tag' => 'select', 'name' => 'ch');
 	my @channels = $_channels->look_down('_tag' => 'option');
@@ -869,15 +869,6 @@
     }
 }
 
-sub utf8 {
-		# Catch the error:
-		#    "Parsing of undecoded UTF-8 will give garbage when decoding entities at /usr/lib/perl5/site_perl/5.8.8/XMLTV/Get_nice.pm line 57."
-		# (e.g. http://eli.thegreenplace.net/2007/07/20/parsing-of-undecoded-utf-8-will-give-garbage-when-decoding-entities/ )
-		#
-		my ($html) = @_;
-		return decode('UTF-8', $html); 
-}
-
 sub debug ( $$ ) {
     my( $message, $nonewline ) = @_;
     print STDERR $message if $opt->{debug};
