xmltv/lib Augment.pm,1.1,1.2

Geoff <[email protected]> Thu, 10 Dec 2015 08:46:37 +0000
Newsgroups gmane.comp.tv.xmltv.cvs
Message-ID <[email protected]>
Update of /cvsroot/xmltv/xmltv/lib
In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv1552

Modified Files:
	Augment.pm 
Log Message:
Add processing rule #15 - Add specified categories to all programmes on a channel

Index: Augment.pm
===================================================================
RCS file: /cvsroot/xmltv/xmltv/lib/Augment.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Augment.pm	12 Jul 2015 16:38:33 -0000	1.1
--- Augment.pm	10 Dec 2015 08:46:35 -0000	1.2
***************
*** 1192,1195 ****
--- 1192,1196 ----
  				 '_desc' 			=> (defined $prog->{'desc'} ? $prog->{'desc'}[0][0] : undef),
  				 '_genres'			=> (defined $prog->{'category'} ? $prog->{'category'} : undef),
+ 				 '_channel'			=> (defined $prog->{'channel'} ? $prog->{'channel'} : undef),
  				 '_series_num' 		=> $episode_num->{'season'},
  				 '_series_total' 	=> $episode_num->{'season_total'},
***************
*** 1264,1267 ****
--- 1265,1271 ----
  	$self->process_translate_genres($_prog);		    # (type=14)
  	
+ 	# Add specified categories to all progs on a channel
+ 	$self->process_add_genres_to_channel($_prog);       # (type=15)
+ 	
  	
  	_d(4,'_Prog, after title fixups:',dd(4,$_prog));
***************
*** 2332,2336 ****
  		#_d(4,dd(4,$prog->{'_genres'}));	
  				
! 		# To esnure the replacements are NOT iterative, we'll store the new values separate for now
  		$prog->{'_newgenres'} = undef;
  		my $storenewgenres = 0;
--- 2336,2340 ----
  		#_d(4,dd(4,$prog->{'_genres'}));	
  				
! 		# To ensure the replacements are NOT iterative, we'll store the new values separate for now
  		$prog->{'_newgenres'} = undef;
  		my $storenewgenres = 0;
***************
*** 2380,2383 ****
--- 2384,2477 ----
  
  
+ =item B<process_add_genres_to_channel>
+ 
+ Rule #15
+ 
+ Add a category to all programmes on a specified channel.
+ 
+   If channel matches this prog, the add the supplied category(-ies) to the programme
+   (note any other categories are left alone)
+ 
+   rule: 15|travelchannel.co.uk~Travel
+   in : "World's Greatest Motorcycle Rides" category "Motoring"
+   out: "World's Greatest Motorcycle Rides" category "Motoring" + "Travel"
+   
+   rule: 15|cnbc.com~News~Business
+   in : "Investing in India" category ""
+   out: "Investing in India" category "News" + "Business"
+ 
+ You should be very careful with this one as it will add the category you specify 
+ to EVERY programme broadcast on that channel. This may not be what you always
+ want (e.g. Teleshopping isn't really "music" even if it is on MTV!)
+ 
+ =cut
+ 
+ # Rule 15
+ #
+ # Add a genre to all programmes on a specified channel.. The addition may be a single or multiple genres.
+ #
+ # Data type 15
+ #     The content contains a channel value followed by 
+ #     category(-ies) separated by a tilde (~).
+ #     Use case: can add a category if data from your supplier is always missing; e.g. add "News" to a news channel, or "Music" to a music vid channel.
+ #
+ sub process_add_genres_to_channel () {
+ 	my ($self, $prog) = @_;
+ 	my $me = self();
+ 	if ( ! $self->{'options_all'} && ! $self->{'options'}{$me} ) { return 0; }
+ 	_d(3,self());
+ 	
+ 	my $ruletype = 15;
+ 	if (!defined $self->{'rules'}->{$ruletype}) { return 0; }
+ 	
+ 	if ( defined $prog->{'_title'} && defined $prog->{'_channel'} ) {
+ 		#_d(4,dd(4,$prog->{'_channel'}));	
+ 		
+         my $idx = lc(substr $prog->{'_channel'}, 0, 2);
+ 
+ 		LOOP:
+ 		foreach (@{ $self->{'rules'}->{$ruletype}->{$idx} }) {
+ 			my ( $line, $key, $value ) = ( $_->{'line'}, $_->{'key'}, $_->{'value'} );
+ 			_d(4,"\t $line, $key, $value");
+ 			
+ 			if ($prog->{'_channel'} eq $key) {
+ 				#_d(4,dd(4,$prog->{'_genres'}));
+ 				
+ 				my %h_old = ();
+ 				my $old = '';
+ 				if (defined $prog->{'_genres'}) {
+ 					foreach my $genre (@{ $prog->{'_genres'} }) {
+ 						$old .= $genre->[0] . ',';
+ 						$h_old{$genre->[0]} = 1;
+ 					}
+ 					chop $old;
+ 				}
+ 				my $new = $value; $new =~ s/~/, /g;
+ 				
+ 				# allow multiple genres separated by tilde
+ 				my @values = split /~/, $value;
+ 				
+ 				my $i = defined $prog->{'_genres'} ? scalar( @{ $prog->{'_genres'} } ) : 0;
+ 				my $msgdone = 0;
+ 				foreach (@values) {	
+ 				    if ( ! exists( $h_old{$_} ) ) {
+ 						$prog->{'_genres'}[$i++] = [ $_, $self->{'language_code'} ];
+ 						l(sprintf("\t Added genre(s) '%s' to '%s' (#%s.%s)",
+ 								$new, $old, $ruletype, $line))  if !$msgdone; $msgdone = 1;
+ 						#(we could mod many progs with this one rule so let's report all of them)
+ 						#$self->add_to_audit ($me, $key, $prog);
+ 						$self->add_to_audit ($me, $key.'~'.$prog->{'_title'}, $prog);
+ 					}
+ 				}
+ 				
+ 				last LOOP;
+             }
+ 		}
+ 		
+ 	}
+ }
+ 
+ 
+ 
  # Store a variety of title debugging information for later analysis
  # and debug output
***************
*** 3160,3163 ****
--- 3254,3258 ----
  			[ 'process_replacement_film_genres' , ': Replace \'Film\'/\'Films\' <category> with supplied value(s) (#12)' ],
  			[ 'process_translate_genres', ': Replace <category> with supplied value(s) (#14)' ],
+ 			[ 'process_add_genres_to_channel', ': Add category to all programmes on <channel> (#15)' ],
  			);
  		


------------------------------------------------------------------------------