xmltv/grab/uk_atlas tv_grab_uk_atlas,1.21,1.22

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

Modified Files:
	tv_grab_uk_atlas 
Log Message:
add duplicate programme deletion / clump creation

Index: tv_grab_uk_atlas
===================================================================
RCS file: /cvsroot/xmltv/xmltv/grab/uk_atlas/tv_grab_uk_atlas,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** tv_grab_uk_atlas	14 Mar 2014 17:55:38 -0000	1.21
--- tv_grab_uk_atlas	22 May 2014 08:14:49 -0000	1.22
***************
*** 35,38 ****
--- 35,39 ----
  use XMLTV::Ask;
  use XMLTV::Get_nice 0.005065;
+ use XMLTV::Date 0.005066;
  
  use File::Path;
***************
*** 171,174 ****
--- 172,190 ----
  
  # ------------------------------------------------------------------------------------------------------------------------------------- #
+ # Progress Bar :)
+ $bar = new XMLTV::ProgressBar({
+   name => "Filtering duplicates",
+   count => scalar @{$programmes}
+ }) unless ($opt->{quiet} || $opt->{debug});
+ 
+ # Remove any duplicate programmes and set clumps where necessary
+ filter_listings();
+ 
+ # Progress Bar
+ $bar->finish() && undef $bar if defined $bar;
+ 
+ 
+ 
+ # ------------------------------------------------------------------------------------------------------------------------------------- #
  # Generate the XML
  my $encoding = 'UTF-8';
***************
*** 627,630 ****
--- 643,727 ----
  }
  						
+ # ------------------------------------------------------------------------------------------------------------------------------------- #
+ 
+ sub filter_listings {
+ 		# Given a hash ready to be fed into XMLTV writer, perform some last minute work on the programmes:
+ 		#   1) Remove any duplicate programmes
+ 		#   2) Create clumps where necessary (i.e. where programmes overlap)
+ 		#
+ 		
+ 		# Test scenarios (list of prog times) for clumpidx generation
+ 		#   1800-1830  1820-1830  1830-1900
+ 		#   1800-1830  1830-1835  1830-1900
+ 		#   1800-1830  1800-1805  1830-1900
+ 		#   1800-1830  1810-1815  1830-1900
+ 		#   1800-1830  1825-1835  1830-1900
+ 		#	
+ 		## For author's testing purposes:
+ 		##       require './filter_test.pl';   ($channels, $programmes) = set_test_data();
+ 		
+ 			
+ 		# Walk the array (note: this assumes, (i) the programmes are stored in channel+starttime order, (ii) they have stop times )
+ 		my ($clumpidx, $clumptot, @curr_clumps) = (0, 2, ());
+ 		for (my $i=0; $i<scalar @{$programmes}; $i++) {
+ 			my ($this, $next) = ($i, $i+1);			
+ 			
+ 			FILTER:
+ 			
+ 			# any more progs after this one?
+ 			last  if ($next >= scalar @{$programmes} );
+ 						
+ 			# get programme's times as epoch seconds
+ 			my $this_start = time_xmltv_to_epoch( @$programmes[$this]->{'start'} );
+ 			my $this_stop  = time_xmltv_to_epoch( @$programmes[$this]->{'stop'} );
+ 			my $next_start = time_xmltv_to_epoch( @$programmes[$next]->{'start'} );
+ 			my $next_stop  = time_xmltv_to_epoch( @$programmes[$next]->{'stop'} );
+ 			
+ 			
+ 			# (Task #1)
+ 			# Is prog a duplicate with next
+ 			#   (duplicate = same channel + same start & stop times + same title
+ 			if ( @$programmes[$next]->{'channel'}     eq @$programmes[$this]->{'channel'}
+ 			 &&  @$programmes[$next]->{'start'}       eq @$programmes[$this]->{'start'}
+ 			 &&  @$programmes[$next]->{'stop'}        eq @$programmes[$this]->{'stop'}
+ 			 &&  @$programmes[$next]->{'title'}[0][0] eq @$programmes[$this]->{'title'}[0][0] ) {
+ 					# delete the duplicate
+ 					splice(@{$programmes}, $next, 1);
+ 					goto FILTER;
+ 			}
+ 			
+ 			
+ 			# (Task #2) 
+ 			# Check times of next prog on this channel; is there an overlap?
+ 			if ( @$programmes[$next]->{'channel'} eq @$programmes[$this]->{'channel'}
+ 			 &&  $next_start < $this_stop ) {
+ 			 
+ 			  if ( !scalar @curr_clumps ) {
+ 					@$programmes[$this]->{'clumpidx'} = $clumpidx++ .'/'. $clumptot;
+ 					@$programmes[$next]->{'clumpidx'} = $clumpidx .'/'. $clumptot;
+ 					push @curr_clumps, $this;		# remember the current array index
+ 					
+ 				} else {   # current prog is already part of a clump :(   
+ 					# adjust rest of current clump
+ 					$clumptot++;
+ 					$clumpidx = 0;
+ 					foreach (@curr_clumps) {
+ 						@$programmes[$_]->{'clumpidx'} = $clumpidx++ .'/'. $clumptot;
+ 					}
+ 					@$programmes[$this]->{'clumpidx'} = $clumpidx++ .'/'. $clumptot;
+ 					@$programmes[$next]->{'clumpidx'} = $clumpidx .'/'. $clumptot;
+ 					push @curr_clumps, $this;		# remember the current array index
+ 				}
+ 						
+ 				
+ 			} else {
+ 				# reset vars ready for next pass
+ 			  ($clumpidx, $clumptot, @curr_clumps) = (0, 2, ());
+ 			}
+ 			
+ 			$bar->update if defined $bar;
+ 		}
+ }
+ # ------------------------------------------------------------------------------------------------------------------------------------- #
  						
  									


------------------------------------------------------------------------------
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos.
Get unparalleled scalability from the best Selenium testing platform available
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs
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.