-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathTweak.x
148 lines (115 loc) · 4.48 KB
/
Tweak.x
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
#import "../YTVideoOverlay/Header.h"
#import "../YTVideoOverlay/Init.x"
#import <YouTubeHeader/YTMainAppVideoPlayerOverlayViewController.h>
#define TweakKey @"YouQuality"
@interface YTMainAppControlsOverlayView (YouQuality)
- (void)didPressYouQuality:(id)arg;
- (void)updateYouQualityButton:(id)arg;
@end
@interface YTInlinePlayerBarContainerView (YouQuality)
- (void)didPressYouQuality:(id)arg;
- (void)updateYouQualityButton:(id)arg;
@end
NSString *YouQualityUpdateNotification = @"YouQualityUpdateNotification";
NSString *currentQualityLabel = @"N/A";
static void setButtonStyle(YTQTMButton *button) {
button.titleLabel.numberOfLines = 3;
[button setTitle:@"Auto" forState:0];
}
%group Video
NSString *getCompactQualityLabel(MLFormat *format) {
NSString *qualityLabel = [format qualityLabel];
BOOL shouldShowFPS = [format FPS] > 30;
if ([qualityLabel hasPrefix:@"2160p"])
qualityLabel = [qualityLabel stringByReplacingOccurrencesOfString:@"2160p" withString:shouldShowFPS ? @"4K\n" : @"4K"];
else if ([qualityLabel hasPrefix:@"1440p"])
qualityLabel = [qualityLabel stringByReplacingOccurrencesOfString:@"1440p" withString:shouldShowFPS ? @"2K\n" : @"2K"];
else if ([qualityLabel hasPrefix:@"1080p"])
qualityLabel = [qualityLabel stringByReplacingOccurrencesOfString:@"1080p" withString:shouldShowFPS ? @"HD\n" : @"HD"];
else if (shouldShowFPS)
qualityLabel = [qualityLabel stringByReplacingOccurrencesOfString:@"p" withString:@"p\n"];
if ([qualityLabel hasSuffix:@" HDR"])
qualityLabel = [qualityLabel stringByReplacingOccurrencesOfString:@" HDR" withString:@"\nHDR"];
return qualityLabel;
}
%hook YTVideoQualitySwitchOriginalController
- (void)singleVideo:(id)singleVideo didSelectVideoFormat:(MLFormat *)format {
currentQualityLabel = getCompactQualityLabel(format);
[[NSNotificationCenter defaultCenter] postNotificationName:YouQualityUpdateNotification object:nil];
%orig;
}
%end
%hook YTVideoQualitySwitchRedesignedController
- (void)singleVideo:(id)singleVideo didSelectVideoFormat:(MLFormat *)format {
currentQualityLabel = getCompactQualityLabel(format);
[[NSNotificationCenter defaultCenter] postNotificationName:YouQualityUpdateNotification object:nil];
%orig;
}
%end
%end
%group Top
%hook YTMainAppControlsOverlayView
%property (retain, nonatomic) YTQTMButton *qualityButton;
- (id)initWithDelegate:(id)delegate {
self = %orig;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateYouQualityButton:) name:YouQualityUpdateNotification object:nil];
setButtonStyle(self.overlayButtons[TweakKey]);
return self;
}
- (id)initWithDelegate:(id)delegate autoplaySwitchEnabled:(BOOL)autoplaySwitchEnabled {
self = %orig;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateYouQualityButton:) name:YouQualityUpdateNotification object:nil];
setButtonStyle(self.overlayButtons[TweakKey]);
return self;
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self name:YouQualityUpdateNotification object:nil];
%orig;
}
%new(v@:@)
- (void)updateYouQualityButton:(id)arg {
[self.overlayButtons[TweakKey] setTitle:currentQualityLabel forState:0];
}
%new(v@:@)
- (void)didPressYouQuality:(id)arg {
YTMainAppVideoPlayerOverlayViewController *c = [self valueForKey:@"_eventsDelegate"];
[c didPressVideoQuality:arg];
[self updateYouQualityButton:nil];
}
%end
%end
%group Bottom
%hook YTInlinePlayerBarContainerView
- (id)init {
self = %orig;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateYouQualityButton:) name:YouQualityUpdateNotification object:nil];
setButtonStyle(self.overlayButtons[TweakKey]);
return self;
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self name:YouQualityUpdateNotification object:nil];
setButtonStyle(self.overlayButtons[TweakKey]);
%orig;
}
%new(v@:@)
- (void)updateYouQualityButton:(id)arg {
[self.overlayButtons[TweakKey] setTitle:currentQualityLabel forState:0];
}
%new(v@:@)
- (void)didPressYouQuality:(id)arg {
YTMainAppVideoPlayerOverlayViewController *c = [self.delegate valueForKey:@"_delegate"];
[c didPressVideoQuality:arg];
[self updateYouQualityButton:nil];
}
%end
%end
%ctor {
initYTVideoOverlay(TweakKey, @{
AccessibilityLabelKey: @"Quality",
SelectorKey: @"didPressYouQuality:",
AsTextKey: @YES
});
%init(Video);
%init(Top);
%init(Bottom);
}