xmltv/grab/pt tv_grab_pt,1.50,1.51

Geoff <[email protected]>
Newsgroups gmane.comp.tv.xmltv.cvs
Message-ID <[email protected]>
Update of /cvsroot/xmltv/xmltv/grab/pt
In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv2637

Modified Files:
	tv_grab_pt 
Log Message:
(minor) fix badutf8 error

Index: tv_grab_pt
===================================================================
RCS file: /cvsroot/xmltv/xmltv/grab/pt/tv_grab_pt,v
retrieving revision 1.50
retrieving revision 1.51
diff -C2 -d -r1.50 -r1.51
*** tv_grab_pt	7 May 2014 16:24:33 -0000	1.50
--- tv_grab_pt	8 May 2014 12:39:52 -0000	1.51
***************
*** 163,166 ****
--- 163,167 ----
      Verbose  => $opt_debug,
  } );
+ ##$XMLTV::Get_nice::Delay = 0 if $opt_debug;
  
  XMLTV::Ask::init($opt_gui);
***************
*** 376,383 ****
          my $uref = new Unicode::UTF8simple; 
       
!         *toUTF8 = sub { return $uref->toUTF8(@_); } 
      } else { 
          #   *toUTF8 = sub { my $str = $_[1]; Encode::from_to($str, $_[0], "utf-8"); return $str; } 
!         *toUTF8 = sub { return Encode::encode("utf-8", $_[0]); } 
      }
  }
--- 377,384 ----
          my $uref = new Unicode::UTF8simple; 
       
!         *toUTF8 = sub { return fix_utf8( $uref->toUTF8(@_) ); } 
      } else { 
          #   *toUTF8 = sub { my $str = $_[1]; Encode::from_to($str, $_[0], "utf-8"); return $str; } 
!         *toUTF8 = sub { return fix_utf8( Encode::encode("utf-8", $_[0]) ); } 
      }
  }
***************
*** 403,406 ****
--- 404,424 ----
  }
  
+ # UTF-8 fixups.
+ sub fix_utf8( $ ) {
+     #  The details page claims to be utf-8 but there are some invalid characters in the incoming data
+     #  e.g. it claims en-dash as C2 96 (which is a control code in utf-8!)
+     #  Looks like an improper conversion from Windows-1252 in the source data
+     #
+     return $_[0] if !defined $_[0];
+     $_[0] =~ s/\xC2\x96/\xE2\x80\x93/og;      # replace invalid en-dash with correct value
+     $_[0] =~ s/\xC2\x80/\xE2\x82\xAC/og;      # euro
+     $_[0] =~ s/\xC2\x85/\xE2\x80\xA6/og;      # ellipsis
+     $_[0] =~ s/\xC2\x92/\xE2\x80\x99/og;      # apostrophe
+     $_[0] =~ s/\xC2\x93/\xE2\x80\x9C/og;      # open double quote
+     $_[0] =~ s/\xC2\x94/\xE2\x80\x9D/og;      # close double quote
+     $_[0] =~ s/\xC2[\x80-\x9F]//og;           # dump the rest
+     return $_[0];
+ }
+ 
  # Remove leading & trailing spaces
  sub trim( $ ) {
***************
*** 639,643 ****
  	# We could check the title matches what we already have but why not just trust the 'id' is correct ;-)
  	
! 	$$prog{'desc'} = $data[1];		# store the description in our prog hash
  	$$prog{'icon'} = "http://images.$DOMAIN/" . $data[2];		# [2] is a uri to the programme image
  
--- 657,661 ----
  	# We could check the title matches what we already have but why not just trust the 'id' is correct ;-)
  	
! 	$$prog{'desc'} = tidy $data[1];		# store the description in our prog hash
  	$$prog{'icon'} = "http://images.$DOMAIN/" . $data[2];		# [2] is a uri to the programme image
  


------------------------------------------------------------------------------
Is your legacy SCM system holding you back? Join Perforce May 7 to find out:
&#149; 3 signs your SCM is hindering your productivity
&#149; Requirements for releasing software faster
&#149; Expert tips and advice for migrating your SCM now
http://p.sf.net/sfu/perforce
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.