xmltv/grab/sd_json tv_grab_sd_json,1.15,1.16

Kevin Groeneveld <[email protected]> Fri, 08 Jul 2016 21:05:49 +0000
Newsgroups gmane.comp.tv.xmltv.cvs
Message-ID <[email protected]>
Update of /cvsroot/xmltv/xmltv/grab/sd_json
In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv16523

Modified Files:
	tv_grab_sd_json 
Log Message:
tv_grab_sd_json: Add support for lineup search by transmitter.
    
Currently SD only supports this for country code GBR. This commit also
includes some small changes to the formatting of the configure messages.


Index: tv_grab_sd_json
===================================================================
RCS file: /cvsroot/xmltv/xmltv/grab/sd_json/tv_grab_sd_json,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** tv_grab_sd_json	3 Jul 2016 17:18:37 -0000	1.15
--- tv_grab_sd_json	8 Jul 2016 21:05:47 -0000	1.16
***************
*** 285,288 ****
--- 285,293 ----
  }
  
+ sub sd_json_get_transmitters {
+ 	my ($country) = @_;
+ 	return sd_json_request('get', "transmitters/$country");
+ }
+ 
  sub sd_json_add_lineup {
  	my ($lineup) = @_;
***************
*** 353,369 ****
  	my ($lineup) = @_;
  
! 	my $location = $lineup->{'location'}  // 'unknown';
! 	my $type     = $lineup->{'transport'} // 'unknown';
! 	my $name     = $lineup->{'name'}      // 'unknown';
! 	my ($id)     = $lineup->{'uri'} =~ m{.*/(.*)};
  
! 	if($type eq 'QAM') {
! 		return "$type | $id";
  	}
  	else {
! 		return "$location | $type | $name | $id";
  	}
  }
  
  sub config_stage {
  	my ($stage, $conf) = @_;
--- 358,390 ----
  	my ($lineup) = @_;
  
! 	my $location  = $lineup->{'location'}  // 'unknown';
! 	my $transport = $lineup->{'transport'} // 'unknown';
! 	my $name      = $lineup->{'name'}      // 'unknown';
! 	my ($id)      = $lineup->{'uri'} =~ m{.*/(.*)};
  
! 	if($transport eq 'QAM') {
! 		return "$id | $transport";
  	}
  	else {
! 		return "$id | $name | $location | $transport";
  	}
  }
  
+ sub ask_search_by_transmitter {
+ 	my ($country) = @_;
+ 
+ 	if($country eq 'GBR') {
+ 		my @options;
+ 		push(@options, 'transmitter');
+ 		push(@options, 'postal' );
+ 
+ 		if(ask_choice('Search by Transmitter or Postal Code:', $options[0], @options) eq $options[0]) {
+ 			return 1;
+ 		}
+ 	}
+ 
+ 	return 0;
+ }
+ 
  sub config_stage {
  	my ($stage, $conf) = @_;
***************
*** 446,449 ****
--- 467,471 ----
  			);
  
+ 			say('#. Lineup ID | Name | Location | Transport');
  			for my $lineup (@{$lineups}) {
  				$count++;
***************
*** 459,487 ****
  			push(@options, 'add' ) if($count < $max);
  			push(@options, 'delete') if $count;
! 			$edit = ask_choice('Edit account lineups', $options[0], @options);
  
  			try
  			{
  				if($edit eq 'add') {
! 					my $country = ask('Lineup or Country (ISO-3166-1 alpha 3 such as USA or CAN):');
  					if(length($country) > 3) {
  						sd_json_add_lineup("lineups/$country");
  					}
  					else {
- 						my $postalcode = ask(($country eq 'USA') ? 'Zip Code:' : 'Postal Code:');
- 						my $headends = sd_json_get_headends($country, $postalcode);
  						my $count = 0;
  						my @uri;
  
! 						for my $headend (@{$headends}) {
! 							for my $lineup (@{$headend->{'lineups'}}) {
  								$count++;
! 								push(@uri, $lineup->{'uri'});
! 								my ($id) = $lineup->{'uri'} =~ m{.*/(.*)};
! 								say("$count. $headend->{'location'} | $headend->{'transport'} | $lineup->{'name'} | $id");
  							}
  						}
  
! 						my $add = ask_choice('Add lineup (0 = none)', 0, (0 .. $count));
  						if($add) {
  							sd_json_add_lineup($uri[$add - 1]);
--- 481,524 ----
  			push(@options, 'add' ) if($count < $max);
  			push(@options, 'delete') if $count;
! 			$edit = ask_choice('Edit account lineups:', $options[0], @options);
  
  			try
  			{
  				if($edit eq 'add') {
! 					my $country = uc(ask('Lineup ID or Country (ISO-3166-1 alpha 3 such as USA or CAN):'));
  					if(length($country) > 3) {
  						sd_json_add_lineup("lineups/$country");
  					}
  					else {
  						my $count = 0;
  						my @uri;
  
! 						if(ask_search_by_transmitter($country)) {
! 							my $transmitters = sd_json_get_transmitters($country);
! 
! 							say('#. Lineup ID | Transmitter');
! 							for my $transmitter (sort(keys %{$transmitters})) {
  								$count++;
! 								my $lineup = $transmitters->{$transmitter};
! 								push(@uri, "lineups/$lineup");
! 								say("$count. $lineup | $transmitter");
  							}
  						}
+ 						else {
+ 							my $postalcode = ask(($country eq 'USA') ? 'Zip Code:' : 'Postal Code:');
+ 							my $headends = sd_json_get_headends($country, $postalcode);
  
! 							say('#. Lineup ID | Name | Location | Transport');
! 							for my $headend (@{$headends}) {
! 								for my $lineup (@{$headend->{'lineups'}}) {
! 									$count++;
! 									push(@uri, $lineup->{'uri'});
! 									my ($id) = $lineup->{'uri'} =~ m{.*/(.*)};
! 									say("$count. $id | $lineup->{'name'} | $headend->{'location'} | $headend->{'transport'}");
! 								}
! 							}
! 						}
! 
! 						my $add = ask_choice('Add lineup (0 = none):', 0, (0 .. $count));
  						if($add) {
  							sd_json_add_lineup($uri[$add - 1]);
***************
*** 490,494 ****
  				}
  				elsif($edit eq 'delete') {
! 					my $delete = ask_choice('Delete lineup (0 = none)', 0, (0 .. $count));
  					if($delete) {
  						sd_json_delete_lineup($lineups->[$delete - 1]->{'uri'});
--- 527,531 ----
  				}
  				elsif($edit eq 'delete') {
! 					my $delete = ask_choice('Delete lineup (0 = none):', 0, (0 .. $count));
  					if($delete) {
  						sd_json_delete_lineup($lineups->[$delete - 1]->{'uri'});


------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape