forked from Ascoware/get-iplayer-automator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtendedShowInformationController.m
146 lines (127 loc) · 6.05 KB
/
ExtendedShowInformationController.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
//
// ExtendedShowInformationController.m
// Get_iPlayer GUI
//
// Created by Thomas Willson on 8/7/14.
//
//
#import "ExtendedShowInformationController.h"
@implementation ExtendedShowInformationController
- (instancetype)init
{
if (!(self = [super init])) return nil;
modeSizeSorters = @[[NSSortDescriptor sortDescriptorWithKey:@"group" ascending:YES],
[NSSortDescriptor sortDescriptorWithKey:@"version" ascending:YES],
[NSSortDescriptor sortDescriptorWithKey:@"size" ascending:NO comparator:^(id obj1, id obj2) {
return [(NSString *)obj1 compare:(NSString *)obj2 options:NSNumericSearch];
}],
[NSSortDescriptor sortDescriptorWithKey:@"mode" ascending:YES]];
return self;
}
#pragma mark Extended Show Information
- (IBAction)showExtendedInformationForSelectedProgramme:(id)sender {
popover.behavior = NSPopoverBehaviorTransient;
loadingLabel.stringValue = @"Loading Episode Info";
[[NSNotificationCenter defaultCenter] postNotificationName:@"AddToLogNotification" object:self userInfo:@{@"message": @"Retrieving Information"}];
Programme *programme = searchResultsArrayController.arrangedObjects[searchResultsTable.selectedRow];
if (programme) {
if ( [programme.tvNetwork isEqualToString:@"ITV Player"] )
{
NSAlert *notNewITV = [[NSAlert alloc] init];
[notNewITV addButtonWithTitle:@"OK"];
notNewITV.messageText = [NSString stringWithFormat:@"This feature is not available for ITV programmes"];
notNewITV.alertStyle = NSWarningAlertStyle;
[notNewITV runModal];
notNewITV = nil;
return;
}
infoView.alphaValue = 0.1;
loadingView.alphaValue = 1.0;
[retrievingInfoIndicator startAnimation:self];
@try {
[popover showRelativeToRect:[searchResultsTable frameOfCellAtColumn:1 row:searchResultsTable.selectedRow] ofView:(NSView *)searchResultsTable preferredEdge:NSMaxYEdge];
}
@catch (NSException *exception) {
NSLog(@"%@",exception.description);
NSLog(@"%@",searchResultsTable);
return;
}
if (!programme.extendedMetadataRetrieved.boolValue) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(informationRetrieved:) name:@"ExtendedInfoRetrieved" object:programme];
[programme retrieveExtendedMetadata];
[NSTimer scheduledTimerWithTimeInterval:60 target:self selector:@selector(timeoutTimer:) userInfo:nil repeats:NO];
}
else {
[self informationRetrieved:[NSNotification notificationWithName:@"" object:programme]];
}
}
}
- (void)timeoutTimer:(NSTimer *)timer
{
Programme *programme = searchResultsArrayController.arrangedObjects[searchResultsTable.selectedRow];
if (!programme.extendedMetadataRetrieved.boolValue) {
[[NSNotificationCenter defaultCenter] postNotificationName:@"AddToLogNotification" object:self userInfo:@{@"message":@"Metadata Retrieval Timed Out"}];
[programme cancelMetadataRetrieval];
loadingLabel.stringValue = @"Programme Information Retrieval Timed Out";
}
}
- (void)informationRetrieved:(NSNotification *)note {
Programme *programme = note.object;
if (programme.successfulRetrieval.boolValue) {
if (programme.thumbnail)
imageView.image = programme.thumbnail;
else
imageView.image = nil;
if (programme.seriesName)
seriesNameField.stringValue = programme.seriesName;
else
seriesNameField.stringValue = @"Unable to Retrieve";
if (programme.episodeName)
episodeNameField.stringValue = programme.episodeName;
else
seriesNameField.stringValue = @"";
if (programme.season && programme.episode)
numbersField.stringValue = [NSString stringWithFormat:@"Series: %ld Episode: %ld",(long)programme.season,(long)programme.episode];
else
numbersField.stringValue = @"";
if (programme.duration)
durationField.stringValue = [NSString stringWithFormat:@"Duration: %d minutes",programme.duration.intValue];
else
durationField.stringValue = @"";
if (programme.categories)
categoriesField.stringValue = [NSString stringWithFormat:@"Categories: %@",programme.categories];
else
categoriesField.stringValue = @"";
if (programme.firstBroadcast)
firstBroadcastField.stringValue = [NSString stringWithFormat:@"First Broadcast: %@",(programme.firstBroadcast).description];
else
firstBroadcastField.stringValue = @"";
if (programme.lastBroadcast)
lastBroadcastField.stringValue = [NSString stringWithFormat:@"Last Broadcast: %@", (programme.lastBroadcast).description];
else
lastBroadcastField.stringValue = @"";
if (programme.desc)
descriptionView.string = programme.desc;
else
descriptionView.string = @"";
if (programme.modeSizes)
modeSizeController.content = programme.modeSizes;
else
modeSizeController.content = @[];
if ([programme typeDescription])
typeField.stringValue = [NSString stringWithFormat:@"Type: %@",[programme typeDescription]];
else
typeField.stringValue = @"";
[retrievingInfoIndicator stopAnimation:self];
infoView.alphaValue = 1.0;
loadingView.alphaValue = 0.0;
[[NSNotificationCenter defaultCenter] postNotificationName:@"AddToLogNotification" object:self userInfo:@{@"message":@"Info Retrieved"}];
}
else {
[retrievingInfoIndicator stopAnimation:self];
loadingLabel.stringValue = @"Info could not be retrieved.";
[[NSNotificationCenter defaultCenter] postNotificationName:@"AddToLogNotification" object:self userInfo:@{@"message":@"Info could not be retrieved."}];
}
}
@synthesize modeSizeSorters;
@end