Skip to content
This repository has been archived by the owner on Jan 3, 2019. It is now read-only.

Commit

Permalink
Merge pull request #630 from madkub/master
Browse files Browse the repository at this point in the history
Updated ITV Listings pull to use HTTPS. Added handling of HTTPS to BB…
  • Loading branch information
dinkypumpkin authored Apr 25, 2017
2 parents 3b7193e + 4f52585 commit e5a8f60
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 20 deletions.
46 changes: 31 additions & 15 deletions GetCurrentWebpage.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ + (Programme *)getCurrentWebpage:(LogController *)logger
NSString *newShowName=nil;
//Get Default Browser
NSString *browser = [[NSUserDefaults standardUserDefaults] objectForKey:@"DefaultBrowser"];

//Prepare Pointer for URL
NSString *url = nil;
NSString *source = nil;

//Prepare Alert in Case the Browser isn't Open
NSAlert *browserNotOpen = [[NSAlert alloc] init];
[browserNotOpen addButtonWithTitle:@"OK"];
[browserNotOpen setMessageText:[NSString stringWithFormat:@"%@ is not open.", browser]];
[browserNotOpen setInformativeText:@"Please ensure your browser is running and has at least one window open."];
[browserNotOpen setAlertStyle:NSWarningAlertStyle];

//Get URL
if ([browser isEqualToString:@"Safari"])
{
Expand All @@ -45,7 +45,12 @@ + (Programme *)getCurrentWebpage:(LogController *)logger
[[tab URL] hasPrefix:@"http://bbc.co.uk/iplayer/episode/"] ||
[[tab URL] hasPrefix:@"http://bbc.co.uk/iplayer/console/"] ||
[[tab URL] hasPrefix:@"http://www.bbc.co.uk/iplayer/console/"] ||
[[tab URL] hasPrefix:@"http://bbc.co.uk/sport"])
[[tab URL] hasPrefix:@"http://bbc.co.uk/sport"] ||
[[tab URL] hasPrefix:@"https://www.bbc.co.uk/iplayer/episode/"] ||
[[tab URL] hasPrefix:@"https://bbc.co.uk/iplayer/episode/"] ||
[[tab URL] hasPrefix:@"https://bbc.co.uk/iplayer/console/"] ||
[[tab URL] hasPrefix:@"https://www.bbc.co.uk/iplayer/console/"] ||
[[tab URL] hasPrefix:@"https://bbc.co.uk/sport"])
{
url = [NSString stringWithString:[tab URL]];
NSScanner *nameScanner = [NSScanner scannerWithString:[tab name]];
Expand All @@ -54,7 +59,8 @@ + (Programme *)getCurrentWebpage:(LogController *)logger
[nameScanner scanUpToString:@"kjklgfdjfgkdlj" intoString:&newShowName];
foundURL=YES;
}
else if ([[tab URL] hasPrefix:@"http://www.bbc.co.uk/programmes/"]) {
else if ([[tab URL] hasPrefix:@"http://www.bbc.co.uk/programmes/"] ||
[[tab URL] hasPrefix:@"https://www.bbc.co.uk/programmes/"]) {
url = [NSString stringWithString:[tab URL]];
NSScanner *nameScanner = [NSScanner scannerWithString:[tab name]];
[nameScanner scanUpToString:@"- " intoString:nil];
Expand All @@ -63,7 +69,8 @@ + (Programme *)getCurrentWebpage:(LogController *)logger
foundURL=YES;
source = [tab source];
}
else if ([[tab URL] hasPrefix:@"http://www.itv.com/hub/"])
else if ([[tab URL] hasPrefix:@"http://www.itv.com/hub/"] ||
[[tab URL] hasPrefix:@"https://www.itv.com/hub/"])
{
url = [NSString stringWithString:[tab URL]];
source = [tab source];
Expand Down Expand Up @@ -113,7 +120,12 @@ + (Programme *)getCurrentWebpage:(LogController *)logger
[[tab URL] hasPrefix:@"http://bbc.co.uk/iplayer/episode/"] ||
[[tab URL] hasPrefix:@"http://bbc.co.uk/iplayer/console/"] ||
[[tab URL] hasPrefix:@"http://www.bbc.co.uk/iplayer/console/"] ||
[[tab URL] hasPrefix:@"http://bbc.co.uk/sport"])
[[tab URL] hasPrefix:@"http://bbc.co.uk/sport"] ||
[[tab URL] hasPrefix:@"https://www.bbc.co.uk/iplayer/episode/"] ||
[[tab URL] hasPrefix:@"https://bbc.co.uk/iplayer/episode/"] ||
[[tab URL] hasPrefix:@"https://bbc.co.uk/iplayer/console/"] ||
[[tab URL] hasPrefix:@"https://www.bbc.co.uk/iplayer/console/"] ||
[[tab URL] hasPrefix:@"https://bbc.co.uk/sport"])
{
url = [NSString stringWithString:[tab URL]];
NSScanner *nameScanner = [NSScanner scannerWithString:[tab title]];
Expand All @@ -122,7 +134,8 @@ + (Programme *)getCurrentWebpage:(LogController *)logger
[nameScanner scanUpToString:@"kjklgfdjfgkdlj" intoString:&newShowName];
foundURL=YES;
}
else if ([[tab URL] hasPrefix:@"http://www.bbc.co.uk/programmes/"]) {
else if ([[tab URL] hasPrefix:@"http://www.bbc.co.uk/programmes/"] ||
[[tab URL] hasPrefix:@"https://www.bbc.co.uk/programmes/"]) {
url = [NSString stringWithString:[tab URL]];
NSScanner *nameScanner = [NSScanner scannerWithString:[tab title]];
[nameScanner scanUpToString:@"- " intoString:nil];
Expand All @@ -131,7 +144,8 @@ + (Programme *)getCurrentWebpage:(LogController *)logger
foundURL=YES;
source = [tab executeJavascript:@"document.documentElement.outerHTML"];
}
else if ([[tab URL] hasPrefix:@"http://www.itv.com/hub/"])
else if ([[tab URL] hasPrefix:@"http://www.itv.com/hub/"] ||
[[tab URL] hasPrefix:@"https://www.itv.com/hub/"])
{
url = [NSString stringWithString:[tab URL]];
source = [tab executeJavascript:@"document.documentElement.outerHTML"];
Expand Down Expand Up @@ -162,16 +176,17 @@ + (Programme *)getCurrentWebpage:(LogController *)logger
[browserNotOpen runModal];
return nil;
}

}
else
{
[[NSAlert alertWithMessageText:@"Get iPlayer Automator currently only supports Safari and Chrome." defaultButton:@"OK" alternateButton:nil otherButton:nil informativeTextWithFormat:@"Please change your preferred browser in the preferences and try again."] runModal];
return nil;
}

//Process URL
if([url hasPrefix:@"http://www.bbc.co.uk/iplayer/episode/"] || [url hasPrefix:@"http://beta.bbc.co.uk/iplayer/episode"])
if([url hasPrefix:@"http://www.bbc.co.uk/iplayer/episode/"] || [url hasPrefix:@"http://beta.bbc.co.uk/iplayer/episode"] ||
[url hasPrefix:@"https://www.bbc.co.uk/iplayer/episode/"] || [url hasPrefix:@"https://beta.bbc.co.uk/iplayer/episode"])
{
NSString *pid = nil;
NSScanner *urlScanner = [[NSScanner alloc] initWithString:url];
Expand Down Expand Up @@ -222,15 +237,16 @@ + (Programme *)getCurrentWebpage:(LogController *)logger
// [newProg performSelectorInBackground:@selector(getName) withObject:nil];
return newProg;
}
else if ([url hasPrefix:@"http://www.bbc.co.uk/sport/olympics/2012/live-video/"])
else if ([url hasPrefix:@"http://www.bbc.co.uk/sport/olympics/2012/live-video/"] ||
[url hasPrefix:@"https://www.bbc.co.uk/sport/olympics/2012/live-video/"])
{
NSString *pid = nil;
NSScanner *urlScanner = [NSScanner scannerWithString:url];
[urlScanner scanString:@"http://www.bbc.co.uk/sport/olympics/2012/live-video/" intoString:nil];
[urlScanner scanUpToString:@"kfejklfjklj" intoString:&pid];
return [[Programme alloc] initWithInfo:nil pid:pid programmeName:newShowName network:@"BBC Sport" logController:logger];
}
else if ([url hasPrefix:@"http://www.itv.com/hub/"])
else if ([url hasPrefix:@"http://www.itv.com/hub/"] || [url hasPrefix:@"https://www.itv.com/hub/"])
{
NSString *progname = nil, *productionId = nil, *title = nil, *desc = nil;
NSInteger seriesnum = 0, episodenum = 0;
Expand Down Expand Up @@ -297,7 +313,7 @@ + (Programme *)getCurrentWebpage:(LogController *)logger
[invalidPage runModal];
return nil;
}

}

@end
10 changes: 5 additions & 5 deletions GetITVListings.m
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ -(void)itvUpdateWithLogger:(LogController *)theLogger
- (id)requestTodayListing
{

[[mySession dataTaskWithURL:[NSURL URLWithString:@"http://www.itv.com/hub/shows"] completionHandler:^(NSData *data, NSURLResponse *response, NSError *error)
[[mySession dataTaskWithURL:[NSURL URLWithString:@"https://www.itv.com/hub/shows"] completionHandler:^(NSData *data, NSURLResponse *response, NSError *error)
{
htmlData = [[NSString alloc]initWithData:data encoding:NSASCIIStringEncoding];
if ( ![self createTodayProgrammeArray] )
Expand Down Expand Up @@ -152,7 +152,7 @@ -(void)processProgrammeEpisodesData:(ProgrammeData *)aProgramme :(NSString *)myH
NSString *token = nil;
NSString *fullProgramme = nil;
NSString *searchPath = nil;
NSString *basePath = @"<a href=\"http://www.itv.com/hub/";
NSString *basePath = @"<a href=\"https://www.itv.com/hub/";
NSUInteger scanPoint = 0;
int seriesNumber = 0;
int episodeNumber = 0;
Expand Down Expand Up @@ -586,7 +586,7 @@ -(BOOL)createTodayProgrammeArray

/* Get first programme */

[scanner scanUpToString:@"<a href=\"http://www.itv.com/hub/" intoString:NULL];
[scanner scanUpToString:@"<a href=\"https://www.itv.com/hub/" intoString:NULL];
[scanner scanUpToString:@"</a>" intoString:&fullProgramme];

while ( (![scanner isAtEnd]) && ++testingProgrammeCount ) {
Expand All @@ -602,7 +602,7 @@ -(BOOL)createTodayProgrammeArray
/* Programme Name */

fullProgrammeScanner.scanLocation = scanPoint;
[fullProgrammeScanner scanString:@"<a href=\"http://www.itv.com/hub/" intoString:NULL];
[fullProgrammeScanner scanString:@"<a href=\"https://www.itv.com/hub/" intoString:NULL];
[fullProgrammeScanner scanUpToString:@"/" intoString:&programmeName];

/* Production ID */
Expand Down Expand Up @@ -636,7 +636,7 @@ -(BOOL)createTodayProgrammeArray

/* Scan for next programme */

[scanner scanUpToString:@"<a href=\"http://www.itv.com/hub/" intoString:NULL];
[scanner scanUpToString:@"<a href=\"https://www.itv.com/hub/" intoString:NULL];
[scanner scanUpToString:@"</a>" intoString:&fullProgramme];

}
Expand Down

0 comments on commit e5a8f60

Please sign in to comment.