From 5a7189fb952505ecff6a49d3997751ffbab009be Mon Sep 17 00:00:00 2001 From: qnblackcat Date: Mon, 17 Oct 2022 02:00:22 +0700 Subject: [PATCH] add YTSpeed --- uYouPlus.xm | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/uYouPlus.xm b/uYouPlus.xm index 0cb17bf..e7091d0 100644 --- a/uYouPlus.xm +++ b/uYouPlus.xm @@ -1049,6 +1049,53 @@ void center() { centerYConstraint.active = YES; } +// YTSpeed - https://github.com/Lyvendia/YTSpeed +%hook YTVarispeedSwitchController +- (id)init { + id result = %orig; + + const int size = 12; + float speeds[] = {0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0, 2.25, 2.5, 2.75, 3.0}; + id varispeedSwitchControllerOptions[size]; + + for (int i = 0; i < size; ++i) { + id title = [NSString stringWithFormat:@"%.2fx", speeds[i]]; + varispeedSwitchControllerOptions[i] = [[%c(YTVarispeedSwitchControllerOption) alloc] initWithTitle:title rate:speeds[i]]; + } + + NSUInteger count = sizeof(varispeedSwitchControllerOptions) / sizeof(id); + NSArray *varispeedArray = [NSArray arrayWithObjects:varispeedSwitchControllerOptions count:count]; + MSHookIvar(self, "_options") = varispeedArray; + + return result; +} +%end + +%hook MLHAMQueuePlayer +- (void)setRate:(float)rate { + MSHookIvar(self, "_rate") = rate; + MSHookIvar(self, "_preferredRate") = rate; + + id player = MSHookIvar(self, "_player"); + [player setRate: rate]; + + id stickySettings = MSHookIvar(self, "_stickySettings"); + [stickySettings setRate: rate]; + + [self.playerEventCenter broadcastRateChange: rate]; + + YTSingleVideoController *singleVideoController = self.delegate; + [singleVideoController playerRateDidChange: rate]; +} +%end + +%hook YTPlayerViewController +%property float playbackRate; +- (void)singleVideo:(id)video playbackRateDidChange:(float)rate { + %orig; +} +%end + // iOS 16 uYou crash fix - @level3tjg: https://github.com/qnblackcat/uYouPlus/pull/224 %group iOS16 %hook OBPrivacyLinkButton