forked from GetiPlayerAutomator/get-iplayer-automator
-
Notifications
You must be signed in to change notification settings - Fork 26
/
NPHistoryWindowController.m
368 lines (274 loc) · 13.9 KB
/
NPHistoryWindowController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
//
// NPHistoryWindowController.m
// Get_iPlayer GUI
//
// Created by LFS on 8/6/16.
//
//
#import "NPHistoryWindowController.h"
#import <Get_iPlayer_Automator-Swift.h>
NewProgrammeHistory *sharedHistoryContoller;
@implementation NPHistoryTableViewController
-(instancetype)init
{
self = [super init];
if (!self)
return self;
/* Load in programme History */
sharedHistoryContoller = [NewProgrammeHistory sharedInstance];
programmeHistoryArray = sharedHistoryContoller.programmeHistoryArray;
historyDisplayArray = [[NSMutableArray alloc]init];
[self loadDisplayData];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loadDisplayData) name:@"NewProgrammeDisplayFilterChanged" object:nil];
return self;
}
- (IBAction)changeFilter:(id)sender {
[self loadDisplayData];
}
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
{
return historyDisplayArray.count;
}
- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
ProgrammeHistoryObject *np = historyDisplayArray[row];
NSString *identifer = tableColumn.identifier;
return [np valueForKey:identifer];
}
-(void)loadDisplayData
{
NSString *displayDate = nil;
NSString *headerDate = nil;
NSString *theItem = nil;
int pageNumber = 0;
/* Set up date for use in headings comparison */
double secondsSince1970 = [NSDate date].timeIntervalSince1970;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; dateFormatter.dateFormat = @"EEE MMM dd";
NSDateFormatter *dateFormatterDayOfWeek = [[NSDateFormatter alloc] init]; dateFormatterDayOfWeek.dateFormat = @"EEEE";
NSMutableDictionary *dayNames = [[NSMutableDictionary alloc]init];
NSString *keyValue;
NSString *key;
for (int i=0;i<7;i++, secondsSince1970-=(24*60*60)) {
if (i==0)
keyValue = @"Today";
else if (i==1)
keyValue = @"Yesterday";
else
keyValue = [dateFormatterDayOfWeek stringFromDate:[NSDate dateWithTimeIntervalSince1970:secondsSince1970]];
key = [dateFormatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:secondsSince1970]];
[dayNames setValue:keyValue forKey:key];
}
[historyDisplayArray removeAllObjects];
for (ProgrammeHistoryObject *np in programmeHistoryArray ) {
if ( [self showITVProgramme:np] || [self showBBCTVProgramme:np] || [self showBBCRadioProgramme:np] ) {
if ( [np.dateFound isNotEqualTo:displayDate] ) {
displayDate = np.dateFound;
headerDate = dayNames[np.dateFound];
if (!headerDate) {
headerDate = @"On : ";
headerDate = [headerDate stringByAppendingString:displayDate];
}
[historyDisplayArray addObject:[[HistoryDisplay alloc]initWithItemString:nil andTVChannel:nil andLineNumber:2 andPageNumber:pageNumber]];
[historyDisplayArray addObject:[[HistoryDisplay alloc]initWithItemString:headerDate andTVChannel:nil andLineNumber:0 andPageNumber:++pageNumber]];
}
theItem = @" ";
theItem = [theItem stringByAppendingString:np.programmeName];
[historyDisplayArray addObject:[[HistoryDisplay alloc]initWithItemString:theItem andTVChannel:np.tvChannel andLineNumber:1 andPageNumber:pageNumber]];
}
}
[historyDisplayArray addObject:[[HistoryDisplay alloc]initWithItemString:nil andTVChannel:nil andLineNumber:2 andPageNumber:pageNumber]];
/* Sort in to programme within reverse date order */
NSSortDescriptor *sort4 = [NSSortDescriptor sortDescriptorWithKey:@"networkNameString" ascending:YES];
NSSortDescriptor *sort3 = [NSSortDescriptor sortDescriptorWithKey:@"programmeNameString" ascending:YES];
NSSortDescriptor *sort2 = [NSSortDescriptor sortDescriptorWithKey:@"lineNumber" ascending:YES];
NSSortDescriptor *sort1 = [NSSortDescriptor sortDescriptorWithKey:@"pageNumber" ascending:NO];
[historyDisplayArray sortUsingDescriptors:@[sort1, sort2, sort3, sort4]];
[historyTable reloadData];
return;
}
-(BOOL)showITVProgramme:(ProgrammeHistoryObject *)np
{
if ( [[[NSUserDefaults standardUserDefaults] valueForKey:@"ShowITV"]isEqualTo:@NO] )
return NO;
if ( ![np.networkName isEqualToString:@"ITV"] )
return NO;
if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"IgnoreAllTVNews"]isEqualTo:@YES]) {
if ([np.programmeName rangeOfString:@"news" options:NSCaseInsensitiveSearch].location != NSNotFound) {
return NO;
}
}
return YES;
}
-(BOOL)showBBCTVProgramme:(ProgrammeHistoryObject *)np
{
/*
'p00fzl6b' => 'BBC Four', # bbcfour/programmes/schedules
'p00fzl6g' => 'BBC News', # bbcnews/programmes/schedules
'p00fzl6n' => 'BBC One', # bbcone/programmes/schedules/hd
'p00fzl73' => 'BBC Parliament', # bbcparliament/programmes/schedules
'p015pksy' => 'BBC Two', # bbctwo/programmes/schedules/hd
'p00fzl9r' => 'CBBC', # cbbc/programmes/schedules
'p00fzl9s' => 'CBeebies', # cbeebies/programmes/schedules
*/
/*
'p00fzl67' => 'BBC Alba', # bbcalba/programmes/schedules
'p00fzl6q' => 'BBC One Northern Ireland', # bbcone/programmes/schedules/ni
'p00zskxc' => 'BBC One Northern Ireland', # bbcone/programmes/schedules/ni_hd
'p00fzl6v' => 'BBC One Scotland', # bbcone/programmes/schedules/scotland
'p013blmc' => 'BBC One Scotland', # bbcone/programmes/schedules/scotland_hd
'p00fzl6z' => 'BBC One Wales', # bbcone/programmes/schedules/wales
'p013bkc7' => 'BBC One Wales', # bbcone/programmes/schedules/wales_hd
'p06kvypx' => 'BBC Scotland', # bbcscotland/programmes/schedules
'p06p396y' => 'BBC Scotland', # bbcscotland/programmes/schedules/hd
'p00fzl97' => 'BBC Two England', # bbctwo/programmes/schedules/england
'p00fzl99' => 'BBC Two Northern Ireland', # bbctwo/programmes/schedules/ni
'p06ngcbm' => 'BBC Two Northern Ireland', # bbctwo/programmes/schedules/ni_hd
'p00fzl9d' => 'BBC Two Wales', # bbctwo/programmes/schedules/wales
'p06ngc52' => 'BBC Two Wales', # bbctwo/programmes/schedules/wales_hd
'p020dmkf' => 'S4C', # s4c/programmes/schedules
*/
NSArray *regionalChannels = @[
@"BBC Alba",
@"BBC One Northern Ireland",
@"BBC One Scotland",
@"BBC One Wales",
@"BBC Scotland",
@"BBC Two England",
@"BBC Two Northern Ireland",
@"BBC Two Wales",
@"S4C"];
if ( [[[NSUserDefaults standardUserDefaults] valueForKey:@"ShowBBCTV"]isEqualTo:@NO] )
return NO;
if ( ![np.networkName isEqualToString:@"BBC TV"] )
return NO;
if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"IgnoreAllTVNews"]isEqualTo:@YES]) {
if ([np.programmeName rangeOfString:@"news" options:NSCaseInsensitiveSearch].location != NSNotFound) {
return NO;
}
}
if ([np.tvChannel isEqualToString:@"BBC Four"]) {
return [[[NSUserDefaults standardUserDefaults] valueForKey:@"BBCFour"]isEqualTo:@YES];
}
if ([np.tvChannel isEqualToString:@"BBC News"]) {
return [[[NSUserDefaults standardUserDefaults] valueForKey:@"BBCNews"]isEqualTo:@YES];
}
if ([np.tvChannel isEqualToString:@"BBC One"]) {
return [[[NSUserDefaults standardUserDefaults] valueForKey:@"BBCOne"]isEqualTo:@YES];
}
if ([np.tvChannel isEqualToString:@"BBC Parliament"]) {
return [[[NSUserDefaults standardUserDefaults] valueForKey:@"BBCParliament"]isEqualTo:@YES];
}
if ([np.tvChannel isEqualToString:@"BBC Two"]) {
return [[[NSUserDefaults standardUserDefaults] valueForKey:@"BBCTwo"]isEqualTo:@YES];
}
if ([np.tvChannel isEqualToString:@"CBBC"]) {
return [[[NSUserDefaults standardUserDefaults] valueForKey:@"CBBC"]isEqualTo:@YES];
}
if ([np.tvChannel isEqualToString:@"CBeebies"]) {
return [[[NSUserDefaults standardUserDefaults] valueForKey:@"CBeebies"]isEqualTo:@YES];
}
// Next, filter out regional channels
BOOL showRegionalTV = [[[NSUserDefaults standardUserDefaults] valueForKey:@"ShowRegionalTVStations"]isEqualTo:@YES];
for (NSString *region in regionalChannels) {
if ([np.tvChannel containsString:region]) {
return showRegionalTV;
}
}
/* Otherwise must be local */
return [[[NSUserDefaults standardUserDefaults] valueForKey:@"ShowLocalTVStations"]isEqualTo:@YES];
}
-(BOOL)showBBCRadioProgramme:(ProgrammeHistoryObject *)np
{
/*
'p00fzl7b' => 'BBC Radio Cymru', # radiocymru/programmes/schedules
'p00fzl7m' => 'BBC Radio Foyle', # radiofoyle/programmes/schedules
'p00fzl81' => 'BBC Radio Nan Gaidheal', # radionangaidheal/programmes/schedules
'p00fzl8d' => 'BBC Radio Scotland', # radioscotland/programmes/schedules/fm
'p00fzl8g' => 'BBC Radio Scotland', # radioscotland/programmes/schedules/mw
'p00fzl8b' => 'BBC Radio Scotland', # radioscotland/programmes/schedules/orkney
'p00fzl8j' => 'BBC Radio Scotland', # radioscotland/programmes/schedules/shetland
'p00fzl8w' => 'BBC Radio Ulster', # radioulster/programmes/schedules
'p00fzl8y' => 'BBC Radio Wales', # radiowales/programmes/schedules/fm
'p00fzl8x' => 'BBC Radio Wales', # radiowales/programmes/schedules/mw
*/
/*
'national' => {
'p00fzl64' => 'BBC Radio 1Xtra', # 1xtra/programmes/schedules
'p00fzl7g' => 'BBC Radio 5 live', # 5live/programmes/schedules
'p00fzl7h' => 'BBC Radio 5 live sports extra', # 5livesportsextra/programmes/schedules
'p00fzl65' => 'BBC Radio 6 Music', # 6music/programmes/schedules
'p00fzl68' => 'BBC Asian Network', # asiannetwork/programmes/schedules
'p00fzl86' => 'BBC Radio 1', # radio1/programmes/schedules
'p00fzl8v' => 'BBC Radio 2', # radio2/programmes/schedules
'p00fzl8t' => 'BBC Radio 3', # radio3/programmes/schedules
'p00fzl7j' => 'BBC Radio 4', # radio4/programmes/schedules/fm
'p00fzl7k' => 'BBC Radio 4', # radio4/programmes/schedules/lw
'p00fzl7l' => 'BBC Radio 4 Extra', # radio4extra/programmes/schedules
'p02zbmb3' => 'BBC World Service', # worldserviceradio/programmes/schedules/uk
},
*/
NSArray *regions = @[@"BBC Radio Cymru", @"BBC Radio Foyle", @"BBC Radio Nan Gaidheal", @"BBC Radio Scotland", @"BBC Radio Ulster", @"BBC Radio Wales"];
/* Filter out if not radio or news and news not wanted */
if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"ShowBBCRadio"]isEqualTo:@NO])
return NO;
if (![np.networkName isEqualToString:@"BBC Radio"])
return NO;
if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"IgnoreAllRadioNews"]isEqualTo:@YES]) {
if ([np.programmeName rangeOfString:@"news" options:NSCaseInsensitiveSearch].location != NSNotFound) {
return NO;
}
}
/* Filter each of the nationals in turn */
if ([np.tvChannel isEqualToString:@"BBC Radio 1Xtra"]) {
return [[[NSUserDefaults standardUserDefaults] valueForKey:@"Radio1Xtra"]isEqualTo:@YES];
}
if ([np.tvChannel isEqualToString:@"BBC Radio 1"]) {
return [[[NSUserDefaults standardUserDefaults] valueForKey:@"Radio1"]isEqualTo:@YES];
}
if ([np.tvChannel isEqualToString:@"BBC Radio 2"]) {
return [[[NSUserDefaults standardUserDefaults] valueForKey:@"Radio2"]isEqualTo:@YES];
}
if ([np.tvChannel isEqualToString:@"BBC Radio 3"]) {
return [[[NSUserDefaults standardUserDefaults] valueForKey:@"Radio3"]isEqualTo:@YES];
}
if ([np.tvChannel isEqualToString:@"BBC Radio 4"]) {
return [[[NSUserDefaults standardUserDefaults] valueForKey:@"Radio4"]isEqualTo:@YES];
}
if ([np.tvChannel isEqualToString:@"BBC Radio 4 Extra"]) {
return [[[NSUserDefaults standardUserDefaults] valueForKey:@"Radio4Extra"]isEqualTo:@YES];
}
if ([np.tvChannel isEqualToString:@"BBC Radio 5 live"]) {
return [[[NSUserDefaults standardUserDefaults] valueForKey:@"Radio5Live"]isEqualTo:@YES];
}
if ([np.tvChannel isEqualToString:@"BBC 5 live sports extra"]) {
return [[[NSUserDefaults standardUserDefaults] valueForKey:@"Radio5LiveSportsExtra"]isEqualTo:@YES];
}
if ([np.tvChannel isEqualToString:@"BBC Radio 6 Music"]) {
return [[[NSUserDefaults standardUserDefaults] valueForKey:@"Radio6Music"]isEqualTo:@YES];
}
if ([np.tvChannel isEqualToString:@"BBC Asian Network"]) {
return [[[NSUserDefaults standardUserDefaults] valueForKey:@"RadioAsianNetwork"]isEqualTo:@YES];
}
if ([np.tvChannel isEqualToString:@"BBC World Service"]) {
return [[[NSUserDefaults standardUserDefaults] valueForKey:@"BBCWorldService"]isEqualTo:@YES];
}
/* Filter for regionals */
for (int i=0; i<regions.count;i++) {
if ([np.tvChannel containsString:regions[i]]) {
return [[[NSUserDefaults standardUserDefaults] valueForKey:@"ShowRegionalRadioStations"]isEqualTo:@YES];
}
}
/* Otherwise must be local */
return [[[NSUserDefaults standardUserDefaults] valueForKey:@"ShowLocalRadioStations"]isEqualTo:@YES];
}
@end
@implementation HistoryDisplay
- (instancetype)initWithItemString:(NSString *)aItemString andTVChannel:(NSString *)aTVChannel andLineNumber:(int)aLineNumber andPageNumber:(int)aPageNumber;
{
programmeNameString = aItemString;
lineNumber = aLineNumber;
pageNumber = aPageNumber;
networkNameString = aTVChannel;
return self;
}
@end