forked from qnblackcat/uYouPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uYouPlus.xm
1379 lines (1225 loc) · 44.6 KB
/
uYouPlus.xm
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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
#import <dlfcn.h>
#import <sys/utsname.h>
#import <substrate.h>
#import "Header.h"
#import "Tweaks/FLEX/FLEX.h"
#import "Tweaks/YouTubeHeader/YTVideoQualitySwitchOriginalController.h"
#import "Tweaks/YouTubeHeader/YTPlayerViewController.h"
#import "Tweaks/YouTubeHeader/YTWatchController.h"
#import "Tweaks/YouTubeHeader/YTIGuideResponse.h"
#import "Tweaks/YouTubeHeader/YTIGuideResponseSupportedRenderers.h"
#import "Tweaks/YouTubeHeader/YTIPivotBarSupportedRenderers.h"
#import "Tweaks/YouTubeHeader/YTIPivotBarRenderer.h"
#import "Tweaks/YouTubeHeader/YTIBrowseRequest.h"
#import "Tweaks/YouTubeHeader/YTCommonColorPalette.h"
#import "Tweaks/YouTubeHeader/ASCollectionView.h"
#import "Tweaks/YouTubeHeader/YTPlayerOverlay.h"
#import "Tweaks/YouTubeHeader/YTPlayerOverlayProvider.h"
#import "Tweaks/YouTubeHeader/YTReelWatchPlaybackOverlayView.h"
#import "Tweaks/YouTubeHeader/YTReelPlayerBottomButton.h"
#import "Tweaks/YouTubeHeader/YTReelPlayerViewController.h"
#import "Tweaks/YouTubeHeader/YTAlertView.h"
#import "Tweaks/YouTubeHeader/YTISectionListRenderer.h"
// Tweak's bundle for Localizations support - @PoomSmart - https://github.com/PoomSmart/YouPiP/commit/aea2473f64c75d73cab713e1e2d5d0a77675024f
NSBundle *uYouPlusBundle() {
static NSBundle *bundle = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSString *tweakBundlePath = [[NSBundle mainBundle] pathForResource:@"uYouPlus" ofType:@"bundle"];
if (tweakBundlePath)
bundle = [NSBundle bundleWithPath:tweakBundlePath];
else
bundle = [NSBundle bundleWithPath:@"/Library/Application Support/uYouPlus.bundle"];
});
return bundle;
}
NSBundle *tweakBundle = uYouPlusBundle();
// Keychain patching
static NSString *accessGroupID() {
NSDictionary *query = [NSDictionary dictionaryWithObjectsAndKeys:
(__bridge NSString *)kSecClassGenericPassword, (__bridge NSString *)kSecClass,
@"bundleSeedID", kSecAttrAccount,
@"", kSecAttrService,
(id)kCFBooleanTrue, kSecReturnAttributes,
nil];
CFDictionaryRef result = nil;
OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)query, (CFTypeRef *)&result);
if (status == errSecItemNotFound)
status = SecItemAdd((__bridge CFDictionaryRef)query, (CFTypeRef *)&result);
if (status != errSecSuccess)
return nil;
NSString *accessGroup = [(__bridge NSDictionary *)result objectForKey:(__bridge NSString *)kSecAttrAccessGroup];
return accessGroup;
}
//
static BOOL IsEnabled(NSString *key) {
return [[NSUserDefaults standardUserDefaults] boolForKey:key];
}
static BOOL isDarkMode() {
return ([[NSUserDefaults standardUserDefaults] integerForKey:@"page_style"] == 1);
}
static BOOL oledDarkTheme() {
return ([[NSUserDefaults standardUserDefaults] integerForKey:@"appTheme"] == 1);
}
static BOOL oldDarkTheme() {
return ([[NSUserDefaults standardUserDefaults] integerForKey:@"appTheme"] == 2);
}
//
# pragma mark - uYou's patches
// Workaround for https://github.com/MiRO92/uYou-for-YouTube/issues/94
%hook UIResponder
%new
- (id)entry {
return nil;
}
%end
// Workaround for https://github.com/MiRO92/uYou-for-YouTube/issues/140
%hook YTLocalPlaybackController
%new
- (id)activeVideoController {
return [self activeVideo];
}
%end
// Workaround for qnblackcat/uYouPlus#10
%hook boolSettingsVC
- (instancetype)initWithTitle:(NSString *)title sections:(NSArray *)sections footer:(NSString *)footer {
if (@available(iOS 15, *))
if (![self valueForKey:@"_lastNotifiedTraitCollection"])
[self setValue:[UITraitCollection currentTraitCollection] forKey:@"_lastNotifiedTraitCollection"];
return %orig;
}
%end
// Prevent uYou player bar from showing when not playing downloaded media
%hook PlayerManager
- (void)pause {
if (isnan([self progress]))
return;
%orig;
}
%end
// Workaround for issue #54
%hook YTMainAppVideoPlayerOverlayViewController
- (void)updateRelatedVideos {
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"relatedVideosAtTheEndOfYTVideos"] == NO) {}
else { return %orig; }
}
%end
// Workaround for qnblackcat/uYouPlus#253, qnblackcat/uYouPlus#170
%hook YTReelWatchPlaybackOverlayView
- (YTQTMButton *)overflowButton {
if ([self respondsToSelector:@selector(orderedRightSideButtons)] &&
[self orderedRightSideButtons].count != 0)
return [self orderedRightSideButtons][0];
return %orig;
}
%end
%hook YTReelContentView
- (void)didTapOverflowButton:(id)sender {}
%end
%subclass YTReelPlayerBottomButton : YTReelPlayerButton
%end
%hook NSLayoutConstraint
+ (instancetype)constraintWithItem:(UIView *)view1
attribute:(NSLayoutAttribute)attr1
relatedBy:(NSLayoutRelation)relation
toItem:(UIView *)view2
attribute:(NSLayoutAttribute)attr2
multiplier:(CGFloat)multiplier
constant:(CGFloat)c {
if (![view1 isKindOfClass:%c(YTReelPlayerBottomButton)] &&
![view1.accessibilityIdentifier isEqualToString:@"com.miro.uyou"])
return %orig;
if (!view2) {
view1.hidden = YES;
return [NSLayoutConstraint alloc];
}
YTReelPlayerBottomButton *uYouButton = (YTReelPlayerBottomButton *)view1;
YTReelPlayerBottomButton *topButton = (YTReelPlayerBottomButton *)view2;
NSString *uYouButtonTitle =
[view2.accessibilityIdentifier isEqualToString:@"com.miro.uyou"]
? @"uYou"
: @"uYouLocal";
uYouButton.accessibilityLabel = uYouButtonTitle;
uYouButton.uppercaseTitle = NO;
[uYouButton setTitle:uYouButtonTitle forState:UIControlStateNormal];
[uYouButton
setTitleTypeKind:MSHookIvar<NSInteger>(topButton, "_typeKind")
typeVariant:MSHookIvar<NSInteger>(topButton, "_typeVariant")];
uYouButton.applyRightSideLayoutImageSize = topButton.applyRightSideLayoutImageSize;
uYouButton.buttonImageTitlePadding = topButton.buttonImageTitlePadding;
uYouButton.buttonLayoutStyle = topButton.buttonLayoutStyle;
uYouButton.sizeWithPaddingAndInsets = topButton.sizeWithPaddingAndInsets;
uYouButton.verticalContentPadding = topButton.verticalContentPadding;
return %orig;
}
%end
// iOS 16 uYou crash fix - @level3tjg: https://github.com/qnblackcat/uYouPlus/pull/224
%group iOS16
%hook OBPrivacyLinkButton
%new
- (instancetype)initWithCaption:(NSString *)caption
buttonText:(NSString *)buttonText
image:(UIImage *)image
imageSize:(CGSize)imageSize
useLargeIcon:(BOOL)useLargeIcon {
return [self initWithCaption:caption
buttonText:buttonText
image:image
imageSize:imageSize
useLargeIcon:useLargeIcon
displayLanguage:[NSLocale currentLocale].languageCode];
}
%end
%end
// Workaround for qnblackcat/uYouPlus#617
static BOOL didFinishLaunching;
%hook YTAppDelegate
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary<UIApplicationLaunchOptionsKey, id> *)launchOptions {
didFinishLaunching = %orig;
self.downloadsVC = [self.downloadsVC init];
if (IsEnabled(@"flex_enabled")) {
[[FLEXManager sharedManager] showExplorer];
}
return didFinishLaunching;
}
- (void)appWillResignActive:(id)arg1 {
%orig;
if (IsEnabled(@"flex_enabled")) {
[[FLEXManager sharedManager] showExplorer];
}
}
%end
%hook DownloadsPagerVC
- (instancetype)init {
return didFinishLaunching ? %orig : self;
}
%end
// uYou's slide settings?
%hook FRPSliderCell
- (void)didMoveToWindow {
%orig;
if (self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
MSHookIvar<UILabel *>(self, "_lLabel").textColor = [UIColor whiteColor];
MSHookIvar<UILabel *>(self, "_rLabel").textColor = [UIColor whiteColor];
MSHookIvar<UILabel *>(self, "_cLabel").textColor = [UIColor whiteColor];
}
}
%end
// Remove uYou download button in playlists
// https://github.com/qnblackcat/uYouPlus/issues/798#issuecomment-1364853420
%hook YTPlaylistHeaderViewController
- (void)viewDidLoad {
%orig;
self.downloadsButton.hidden = YES;
}
%end
# pragma mark - YouTube's patches
// Workaround for MiRO92/uYou-for-YouTube#12, qnblackcat/uYouPlus#263
%hook YTDataUtils
+ (NSMutableDictionary *)spamSignalsDictionary {
return nil;
}
%end
// Fix login for YouTube 17.33.2 and higher
%hook SSOKeychainCore
+ (NSString *)accessGroup {
return accessGroupID();
}
+ (NSString *)sharedAccessGroup {
return accessGroupID();
}
%end
// Fix App Group Directory by move it to document directory
%hook NSFileManager
- (NSURL *)containerURLForSecurityApplicationGroupIdentifier:(NSString *)groupIdentifier {
if (groupIdentifier != nil) {
NSArray *paths = [[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask];
NSURL *documentsURL = [paths lastObject];
return [documentsURL URLByAppendingPathComponent:@"AppGroup"];
}
return %orig(groupIdentifier);
}
%end
// Hide YouTube annoying banner in Home page? - @MiRO92 - YTNoShorts: https://github.com/MiRO92/YTNoShorts
%hook YTAsyncCollectionView
- (id)cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = %orig;
if ([cell isKindOfClass:NSClassFromString(@"_ASCollectionViewCell")]) {
_ASCollectionViewCell *cell = %orig;
if ([cell respondsToSelector:@selector(node)]) {
if ([[[cell node] accessibilityIdentifier] isEqualToString:@"statement_banner.view"]) { [self removeShortsAndFeaturesAdsAtIndexPath:indexPath]; }
if ([[[cell node] accessibilityIdentifier] isEqualToString:@"compact.view"]) { [self removeShortsAndFeaturesAdsAtIndexPath:indexPath]; }
// if ([[[cell node] accessibilityIdentifier] isEqualToString:@"id.ui.video_metadata_carousel"]) { [self removeShortsAndFeaturesAdsAtIndexPath:indexPath]; }
}
}
return %orig;
}
%new
- (void)removeShortsAndFeaturesAdsAtIndexPath:(NSIndexPath *)indexPath {
[self deleteItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]];
}
%end
# pragma mark - Tweaks
// IAmYouTube - https://github.com/PoomSmart/IAmYouTube/
%hook YTVersionUtils
+ (NSString *)appName { return YT_NAME; }
+ (NSString *)appID { return YT_BUNDLE_ID; }
%end
%hook GCKBUtils
+ (NSString *)appIdentifier { return YT_BUNDLE_ID; }
%end
%hook GPCDeviceInfo
+ (NSString *)bundleId { return YT_BUNDLE_ID; }
%end
%hook OGLBundle
+ (NSString *)shortAppName { return YT_NAME; }
%end
%hook GVROverlayView
+ (NSString *)appName { return YT_NAME; }
%end
%hook OGLPhenotypeFlagServiceImpl
- (NSString *)bundleId { return YT_BUNDLE_ID; }
%end
%hook APMAEU
+ (BOOL)isFAS { return YES; }
%end
%hook GULAppEnvironmentUtil
+ (BOOL)isFromAppStore { return YES; }
%end
%hook SSOConfiguration
- (id)initWithClientID:(id)clientID supportedAccountServices:(id)supportedAccountServices {
self = %orig;
[self setValue:YT_NAME forKey:@"_shortAppName"];
[self setValue:YT_BUNDLE_ID forKey:@"_applicationIdentifier"];
return self;
}
%end
%hook NSBundle
- (NSString *)bundleIdentifier {
NSArray *address = [NSThread callStackReturnAddresses];
Dl_info info = {0};
if (dladdr((void *)[address[2] longLongValue], &info) == 0)
return %orig;
NSString *path = [NSString stringWithUTF8String:info.dli_fname];
if ([path hasPrefix:NSBundle.mainBundle.bundlePath])
return YT_BUNDLE_ID;
return %orig;
}
- (id)objectForInfoDictionaryKey:(NSString *)key {
if ([key isEqualToString:@"CFBundleIdentifier"])
return YT_BUNDLE_ID;
if ([key isEqualToString:@"CFBundleDisplayName"] || [key isEqualToString:@"CFBundleName"])
return YT_NAME;
return %orig;
}
// Fix Google Sign in by @PoomSmart and @level3tjg (qnblackcat/uYouPlus#684)
- (NSDictionary *)infoDictionary {
NSMutableDictionary *info = %orig.mutableCopy;
NSString *altBundleIdentifier = info[@"ALTBundleIdentifier"];
if (altBundleIdentifier) info[@"CFBundleIdentifier"] = altBundleIdentifier;
return info;
}
%end
// YTMiniPlayerEnabler: https://github.com/level3tjg/YTMiniplayerEnabler/
%hook YTWatchMiniBarViewController
- (void)updateMiniBarPlayerStateFromRenderer {
if (IsEnabled(@"ytMiniPlayer_enabled")) {}
else { return %orig; }
}
%end
// YTAutoFullScreen: https://github.com/PoomSmart/YTAutoFullScreen/
%hook YTPlayerViewController
- (void)loadWithPlayerTransition:(id)arg1 playbackConfig:(id)arg2 {
%orig;
if (IsEnabled(@"autoFull_enabled"))
[NSTimer scheduledTimerWithTimeInterval:0.75 target:self selector:@selector(autoFullscreen) userInfo:nil repeats:NO];
}
%new
- (void)autoFullscreen {
YTWatchController *watchController = [self valueForKey:@"_UIDelegate"];
[watchController showFullScreen];
}
%end
// YTNoHoverCards: https://github.com/level3tjg/YTNoHoverCards
%hook YTCreatorEndscreenView
- (void)setHidden:(BOOL)hidden {
if (IsEnabled(@"hideHoverCards_enabled"))
hidden = YES;
%orig;
}
%end
//YTCastConfirm: https://github.com/JamieBerghmans/YTCastConfirm
%hook MDXPlaybackRouteButtonController
- (void)didPressButton:(id)arg1 {
if (IsEnabled(@"castConfirm_enabled")) {
NSBundle *tweakBundle = uYouPlusBundle();
YTAlertView *alertView = [%c(YTAlertView) confirmationDialogWithAction:^{
%orig;
} actionTitle:LOC(@"MSG_YES")];
alertView.title = LOC(@"CASTING");
alertView.subtitle = LOC(@"MSG_ARE_YOU_SURE");
[alertView show];
} else {
return %orig;
}
}
%end
// Hide search ads by @PoomSmart - https://github.com/PoomSmart/YouTube-X
%hook YTIElementRenderer
- (NSData *)elementData {
if (self.hasCompatibilityOptions && self.compatibilityOptions.hasAdLoggingData)
return nil;
return %orig;
}
%end
%hook YTSectionListViewController
- (void)loadWithModel:(YTISectionListRenderer *)model {
NSMutableArray <YTISectionListSupportedRenderers *> *contentsArray = model.contentsArray;
NSIndexSet *removeIndexes = [contentsArray indexesOfObjectsPassingTest:^BOOL(YTISectionListSupportedRenderers *renderers, NSUInteger idx, BOOL *stop) {
YTIItemSectionRenderer *sectionRenderer = renderers.itemSectionRenderer;
YTIItemSectionSupportedRenderers *firstObject = [sectionRenderer.contentsArray firstObject];
return firstObject.hasPromotedVideoRenderer || firstObject.hasCompactPromotedVideoRenderer || firstObject.hasPromotedVideoInlineMutedRenderer;
}];
[contentsArray removeObjectsAtIndexes:removeIndexes];
%orig;
}
%end
// YTClassicVideoQuality: https://github.com/PoomSmart/YTClassicVideoQuality
%hook YTVideoQualitySwitchControllerFactory
- (id)videoQualitySwitchControllerWithParentResponder:(id)responder {
Class originalClass = %c(YTVideoQualitySwitchOriginalController);
return originalClass ? [[originalClass alloc] initWithParentResponder:responder] : %orig;
}
%end
// A/B flags
%hook YTColdConfig
- (BOOL)respectDeviceCaptionSetting { return NO; } // YouRememberCaption: https://poomsmart.github.io/repo/depictions/youremembercaption.html
- (BOOL)isLandscapeEngagementPanelSwipeRightToDismissEnabled { return YES; } // Swipe right to dismiss the right panel in fullscreen mode
- (BOOL)mainAppCoreClientIosTransientVisualGlitchInPivotBarFix { return NO; } // Fix uYou's label glitching - qnblackcat/uYouPlus#552
%end
// NOYTPremium - https://github.com/PoomSmart/NoYTPremium/
%hook YTCommerceEventGroupHandler
- (void)addEventHandlers {}
%end
%hook YTInterstitialPromoEventGroupHandler
- (void)addEventHandlers {}
%end
%hook YTPromosheetEventGroupHandler
- (void)addEventHandlers {}
%end
%hook YTPromoThrottleController
- (BOOL)canShowThrottledPromo { return NO; }
- (BOOL)canShowThrottledPromoWithFrequencyCap:(id)arg1 { return NO; }
- (BOOL)canShowThrottledPromoWithFrequencyCaps:(id)arg1 { return NO; }
%end
%hook YTIShowFullscreenInterstitialCommand
- (BOOL)shouldThrottleInterstitial { return YES; }
%end
%hook YTSurveyController
- (void)showSurveyWithRenderer:(id)arg1 surveyParentResponder:(id)arg2 {}
%end
// YTShortsProgress - @PoomSmart - https://github.com/PoomSmart/YTShortsProgress
%hook YTReelPlayerViewController
- (BOOL)shouldEnablePlayerBar { return YES; }
- (BOOL)shouldAlwaysEnablePlayerBar { return YES; }
- (BOOL)shouldEnablePlayerBarOnlyOnPause { return NO; }
%end
%hook YTReelPlayerViewControllerSub
- (BOOL)shouldEnablePlayerBar { return YES; }
- (BOOL)shouldAlwaysEnablePlayerBar { return YES; }
- (BOOL)shouldEnablePlayerBarOnlyOnPause { return NO; }
%end
%hook YTColdConfig
- (BOOL)iosEnableVideoPlayerScrubber { return YES; }
- (BOOL)mobileShortsTabInlined { return YES; }
%end
%hook YTHotConfig
- (BOOL)enablePlayerBarForVerticalVideoWhenControlsHiddenInFullscreen { return YES; }
%end
// YTNoPaidPromo: https://github.com/PoomSmart/YTNoPaidPromo
%hook YTMainAppVideoPlayerOverlayViewController
- (void)setPaidContentWithPlayerData:(id)data {
if (IsEnabled(@"hidePaidPromotionCard_enabled")) {}
else { return %orig; }
}
- (void)playerOverlayProvider:(YTPlayerOverlayProvider *)provider didInsertPlayerOverlay:(YTPlayerOverlay *)overlay {
if ([[overlay overlayIdentifier] isEqualToString:@"player_overlay_paid_content"] && IsEnabled(@"hidePaidPromotionCard_enabled")) return;
%orig;
}
%end
%hook YTInlineMutedPlaybackPlayerOverlayViewController
- (void)setPaidContentWithPlayerData:(id)data {
if (IsEnabled(@"hidePaidPromotionCard_enabled")) {}
else { return %orig; }
}
%end
// YTReExplore: https://github.com/PoomSmart/YTReExplore/
%group gReExplore
static void replaceTab(YTIGuideResponse *response) {
NSMutableArray <YTIGuideResponseSupportedRenderers *> *renderers = [response itemsArray];
for (YTIGuideResponseSupportedRenderers *guideRenderers in renderers) {
YTIPivotBarRenderer *pivotBarRenderer = [guideRenderers pivotBarRenderer];
NSMutableArray <YTIPivotBarSupportedRenderers *> *items = [pivotBarRenderer itemsArray];
NSUInteger shortIndex = [items indexOfObjectPassingTest:^BOOL(YTIPivotBarSupportedRenderers *renderers, NSUInteger idx, BOOL *stop) {
return [[[renderers pivotBarItemRenderer] pivotIdentifier] isEqualToString:@"FEshorts"];
}];
if (shortIndex != NSNotFound) {
[items removeObjectAtIndex:shortIndex];
NSUInteger exploreIndex = [items indexOfObjectPassingTest:^BOOL(YTIPivotBarSupportedRenderers *renderers, NSUInteger idx, BOOL *stop) {
return [[[renderers pivotBarItemRenderer] pivotIdentifier] isEqualToString:[%c(YTIBrowseRequest) browseIDForExploreTab]];
}];
if (exploreIndex == NSNotFound) {
YTIPivotBarSupportedRenderers *exploreTab = [%c(YTIPivotBarRenderer) pivotSupportedRenderersWithBrowseId:[%c(YTIBrowseRequest) browseIDForExploreTab] title:@"Explore" iconType:292];
[items insertObject:exploreTab atIndex:1];
}
break;
}
}
}
%hook YTGuideServiceCoordinator
- (void)handleResponse:(YTIGuideResponse *)response withCompletion:(id)completion {
replaceTab(response);
%orig(response, completion);
}
- (void)handleResponse:(YTIGuideResponse *)response error:(id)error completion:(id)completion {
replaceTab(response);
%orig(response, error, completion);
}
%end
%end
// BigYTMiniPlayer: https://github.com/Galactic-Dev/BigYTMiniPlayer
%group Main
%hook YTWatchMiniBarView
- (void)setWatchMiniPlayerLayout:(int)arg1 {
%orig(1);
}
- (int)watchMiniPlayerLayout {
return 1;
}
- (void)layoutSubviews {
%orig;
self.frame = CGRectMake(([UIScreen mainScreen].bounds.size.width - self.frame.size.width), self.frame.origin.y, self.frame.size.width, self.frame.size.height);
}
%end
%hook YTMainAppVideoPlayerOverlayView
- (BOOL)isUserInteractionEnabled {
if([[self _viewControllerForAncestor].parentViewController.parentViewController isKindOfClass:%c(YTWatchMiniBarViewController)]) {
return NO;
}
return %orig;
}
%end
%end
// DontEatMyContent - @therealFoxster: https://github.com/therealFoxster/DontEatMyContent
static double videoAspectRatio = 16/9;
static bool zoomedToFill = false;
static bool engagementPanelIsVisible = false, removeEngagementPanelViewControllerWithIdentifierCalled = false;
static MLHAMSBDLSampleBufferRenderingView *renderingView;
static NSLayoutConstraint *widthConstraint, *heightConstraint, *centerXConstraint, *centerYConstraint;
%group gDontEatMyContent
// Retrieve video aspect ratio
%hook YTPlayerView
- (void)setAspectRatio:(CGFloat)aspectRatio {
%orig(aspectRatio);
videoAspectRatio = aspectRatio;
}
%end
%hook YTPlayerViewController
- (void)viewDidAppear:(BOOL)animated {
YTPlayerView *playerView = [self playerView];
UIView *renderingViewContainer = MSHookIvar<UIView *>(playerView, "_renderingViewContainer");
renderingView = [playerView renderingView];
// Making renderingView a bit larger since constraining to safe area leaves a gap between the notch and video
CGFloat constant = 22.0; // Tested on iPhone 13 mini & 14 Pro Max
widthConstraint = [renderingView.widthAnchor constraintEqualToAnchor:renderingViewContainer.safeAreaLayoutGuide.widthAnchor constant:constant];
heightConstraint = [renderingView.heightAnchor constraintEqualToAnchor:renderingViewContainer.safeAreaLayoutGuide.heightAnchor constant:constant];
centerXConstraint = [renderingView.centerXAnchor constraintEqualToAnchor:renderingViewContainer.centerXAnchor];
centerYConstraint = [renderingView.centerYAnchor constraintEqualToAnchor:renderingViewContainer.centerYAnchor];
// playerView.backgroundColor = [UIColor blueColor];
// renderingViewContainer.backgroundColor = [UIColor greenColor];
// renderingView.backgroundColor = [UIColor redColor];
YTMainAppVideoPlayerOverlayViewController *activeVideoPlayerOverlay = [self activeVideoPlayerOverlay];
// Must check class since YTInlineMutedPlaybackPlayerOverlayViewController doesn't have -(BOOL)isFullscreen
if ([NSStringFromClass([activeVideoPlayerOverlay class]) isEqualToString:@"YTMainAppVideoPlayerOverlayViewController"] // isKindOfClass doesn't work for some reason
&& [activeVideoPlayerOverlay isFullscreen]) {
if (!zoomedToFill && !engagementPanelIsVisible) DEMC_activate();
} else {
DEMC_centerRenderingView();
}
%orig(animated);
}
- (void)didPressToggleFullscreen {
%orig;
if (![[self activeVideoPlayerOverlay] isFullscreen]) { // Entering full screen
if (!zoomedToFill && !engagementPanelIsVisible) DEMC_activate();
} else { // Exiting full screen
DEMC_deactivate();
}
%orig;
}
- (void)didSwipeToEnterFullscreen {
%orig;
if (!zoomedToFill && !engagementPanelIsVisible) DEMC_activate();
}
- (void)didSwipeToExitFullscreen {
%orig;
DEMC_deactivate();
}
// New video played
-(void)playbackController:(id)playbackController didActivateVideo:(id)video withPlaybackData:(id)playbackData {
%orig(playbackController, video, playbackData);
if ([[self activeVideoPlayerOverlay] isFullscreen]) // New video played while in full screen (landscape)
// Activate since new videos played in full screen aren't zoomed-to-fill by default
// (i.e. the notch/Dynamic Island will cut into content when playing a new video in full screen)
DEMC_activate();
engagementPanelIsVisible = false;
removeEngagementPanelViewControllerWithIdentifierCalled = false;
}
%end
// Pinch to zoom
%hook YTVideoFreeZoomOverlayView
- (void)didRecognizePinch:(UIPinchGestureRecognizer *)pinchGestureRecognizer {
DEMC_deactivate();
%orig(pinchGestureRecognizer);
}
// Detect zoom to fill
- (void)showLabelForSnapState:(NSInteger)snapState {
if (snapState == 0) { // Original
zoomedToFill = false;
DEMC_activate();
} else if (snapState == 1) { // Zoomed to fill
zoomedToFill = true;
// No need to deactivate constraints as it's already done in -(void)didRecognizePinch:(UIPinchGestureRecognizer *)
}
%orig(snapState);
}
%end
// Mini bar dismiss
%hook YTWatchMiniBarViewController
- (void)dismissMiniBarWithVelocity:(CGFloat)velocity gestureType:(int)gestureType {
%orig(velocity, gestureType);
zoomedToFill = false; // Setting to false since YouTube undoes zoom-to-fill when mini bar is dismissed
}
- (void)dismissMiniBarWithVelocity:(CGFloat)velocity gestureType:(int)gestureType skipShouldDismissCheck:(BOOL)skipShouldDismissCheck {
%orig(velocity, gestureType, skipShouldDismissCheck);
zoomedToFill = false;
}
%end
%hook YTMainAppEngagementPanelViewController
// Engagement panel (comment, description, etc.) about to show up
- (void)viewWillAppear:(BOOL)animated {
if ([self isPeekingSupported]) {
// Shorts (only Shorts support peeking, I think)
} else {
// Everything else
engagementPanelIsVisible = true;
if ([self isLandscapeEngagementPanel]) {
DEMC_deactivate();
}
}
%orig(animated);
}
// Engagement panel about to dismiss
// - (void)viewDidDisappear:(BOOL)animated { %orig; %log; } // Called too late & isn't reliable so sometimes constraints aren't activated even when engagement panel is closed
%end
%hook YTEngagementPanelContainerViewController
// Engagement panel about to dismiss
- (void)notifyEngagementPanelContainerControllerWillHideFinalPanel { // Called in time but crashes if plays new video while in full screen causing engagement panel dismissal
// Must check if engagement panel was dismissed because new video played
// (i.e. if -(void)removeEngagementPanelViewControllerWithIdentifier:(id) was called prior)
if (![self isPeekingSupported] && !removeEngagementPanelViewControllerWithIdentifierCalled) {
engagementPanelIsVisible = false;
if ([self isLandscapeEngagementPanel] && !zoomedToFill) {
DEMC_activate();
}
}
%orig;
}
- (void)removeEngagementPanelViewControllerWithIdentifier:(id)identifier {
// Usually called when engagement panel is open & new video is played or mini bar is dismissed
removeEngagementPanelViewControllerWithIdentifierCalled = true;
%orig(identifier);
}
%end
%end// group gDontEatMyContent
BOOL DEMC_deviceIsSupported() {
// Get device model identifier (e.g. iPhone14,4)
// https://stackoverflow.com/a/11197770/19227228
struct utsname systemInfo;
uname(&systemInfo);
NSString *deviceModelID = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
NSArray *unsupportedModelIDs = DEMC_UNSUPPORTED_DEVICES;
for (NSString *identifier in unsupportedModelIDs) {
if ([deviceModelID isEqualToString:identifier]) {
return NO;
}
}
if ([deviceModelID containsString:@"iPhone"]) {
if ([deviceModelID isEqualToString:@"iPhone13,1"]) {
// iPhone 12 mini
return YES;
}
NSString *modelNumber = [[deviceModelID stringByReplacingOccurrencesOfString:@"iPhone" withString:@""] stringByReplacingOccurrencesOfString:@"," withString:@"."];
if ([modelNumber floatValue] >= 14.0) {
// iPhone 13 series and newer
return YES;
} else return NO;
} else return NO;
}
void DEMC_activate() {
if (videoAspectRatio < DEMC_THRESHOLD) {
DEMC_deactivate();
return;
}
// NSLog(@"activate");
DEMC_centerRenderingView();
renderingView.translatesAutoresizingMaskIntoConstraints = NO;
widthConstraint.active = YES;
heightConstraint.active = YES;
}
void DEMC_deactivate() {
// NSLog(@"deactivate");
DEMC_centerRenderingView();
renderingView.translatesAutoresizingMaskIntoConstraints = YES;
widthConstraint.active = NO;
heightConstraint.active = NO;
}
void DEMC_centerRenderingView() {
centerXConstraint.active = YES;
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<NSArray *>(self, "_options") = varispeedArray;
return result;
}
%end
%hook MLHAMQueuePlayer
- (void)setRate:(float)rate {
MSHookIvar<float>(self, "_rate") = rate;
MSHookIvar<float>(self, "_preferredRate") = rate;
id player = MSHookIvar<HAMPlayerInternal *>(self, "_player");
[player setRate: rate];
id stickySettings = MSHookIvar<MLPlayerStickySettings *>(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
# pragma mark - uYouPlus
// Video Player Options
// Skips content warning before playing *some videos - @PoomSmart
%hook YTPlayabilityResolutionUserActionUIController
- (void)showConfirmAlert { [self confirmAlertDidPressConfirm]; }
%end
// Disable snap to chapter
%hook YTSegmentableInlinePlayerBarView
- (void)didMoveToWindow {
%orig;
if (IsEnabled(@"snapToChapter_enabled")) {
self.enableSnapToChapter = NO;
}
}
%end
// Disable Pinch to zoom
%hook YTColdConfig
- (BOOL)videoZoomFreeZoomEnabledGlobalConfig {
return IsEnabled(@"pinchToZoom_enabled") ? NO : %orig;
}
%end
// Video Controls Overlay Options
// Hide CC / Autoplay switch
%hook YTMainAppControlsOverlayView
- (void)setClosedCaptionsOrSubtitlesButtonAvailable:(BOOL)arg1 { // hide CC button
return IsEnabled(@"hideCC_enabled") ? %orig(NO) : %orig;
}
- (void)setAutoplaySwitchButtonRenderer:(id)arg1 { // hide Autoplay
if (IsEnabled(@"hideAutoplaySwitch_enabled")) {}
else { return %orig; }
}
%end
// Hide HUD Messages
%hook YTHUDMessageView
- (id)initWithMessage:(id)arg1 dismissHandler:(id)arg2 {
return IsEnabled(@"hideHUD_enabled") ? nil : %orig;
}
%end
// Hide Watermark
%hook YTAnnotationsViewController
- (void)loadFeaturedChannelWatermark {
if (IsEnabled(@"hideChannelWatermark_enabled")) {}
else { return %orig; }
}
%end
// Hide Next & Previous button
%group gHidePreviousAndNextButton
%hook YTColdConfig
- (BOOL)removeNextPaddleForSingletonVideos { return YES; }
- (BOOL)removePreviousPaddleForSingletonVideos { return YES; }
%end
%end
// Replace Next & Previous button with Fast forward & Rewind button
%group gReplacePreviousAndNextButton
%hook YTColdConfig
- (BOOL)replaceNextPaddleWithFastForwardButtonForSingletonVods { return YES; }
- (BOOL)replacePreviousPaddleWithRewindButtonForSingletonVods { return YES; }
%end
%end
// Bring back the red progress bar
%hook YTColdConfig
- (BOOL)segmentablePlayerBarUpdateColors {
return IsEnabled(@"redProgressBar_enabled") ? NO : %orig;
}
%end
// Disable the right panel in fullscreen mode
%hook YTColdConfig
- (BOOL)isLandscapeEngagementPanelEnabled {
return IsEnabled(@"hideRightPanel_enabled") ? NO : %orig;
}
%end
// Shorts Controls Overlay Options
%hook YTReelWatchPlaybackOverlayView
- (void)setNativePivotButton:(id)arg1 {
if (IsEnabled(@"hideShortsChannelAvatar_enabled")) {}
else { return %orig; }
}
- (void)setReelDislikeButton:(id)arg1 {
if (IsEnabled(@"hideShortsDislikeButton_enabled")) {}
else { return %orig; }
}
- (void)setViewCommentButton:(id)arg1 {
if (IsEnabled(@"hideShortsCommentButton_enabled")) {}
else { return %orig; }
}
- (void)setRemixButton:(id)arg1 {
if (IsEnabled(@"hideShortsRemixButton_enabled")) {}
else { return %orig; }
}
- (void)setShareButton:(id)arg1 {
if (IsEnabled(@"hideShortsShareButton_enabled")) {}
else { return %orig; }
}
%end
%hook YTHotConfig
- (BOOL)iosEnableShortsPlayerSplitViewController {
return IsEnabled(@"hideuYouShortsDownloadButton_enabled") ? YES : NO;
}
%end
%hook _ASDisplayView
- (void)didMoveToWindow {
%orig;
if ((IsEnabled(@"hideBuySuperThanks_enabled")) && ([self.accessibilityIdentifier isEqualToString:@"id.elements.components.suggested_action"])) {
self.hidden = YES;
}
}
%end
%hook YTShortsStartupCoordinator
- (id)evaluateResumeToShorts {
return IsEnabled(@"disableResumeToShorts") ? nil : %orig;
}
%end
// Theme Options
// Old dark theme (gray)
%group gOldDarkTheme
%hook YTColdConfig
- (BOOL)uiSystemsClientGlobalConfigUseDarkerPaletteBgColorForNative { return NO; }
- (BOOL)uiSystemsClientGlobalConfigUseDarkerPaletteTextColorForNative { return NO; }
- (BOOL)enableCinematicContainerOnClient { return NO; }
%end
%hook _ASDisplayView
- (void)didMoveToWindow {
%orig;
if ([self.accessibilityIdentifier isEqualToString:@"id.elements.components.comment_composer"]) { self.backgroundColor = [UIColor clearColor]; }
if ([self.accessibilityIdentifier isEqualToString:@"id.elements.components.video_list_entry"]) { self.backgroundColor = [UIColor clearColor]; }
}
%end
%hook ASCollectionView
- (void)didMoveToWindow {
%orig;
self.superview.backgroundColor = [UIColor colorWithRed:0.129 green:0.129 blue:0.129 alpha:1.0];
}
%end
%hook YTFullscreenEngagementOverlayView
- (void)didMoveToWindow {
%orig;
self.subviews[0].backgroundColor = [UIColor clearColor];
}
%end
%hook YTRelatedVideosView
- (void)didMoveToWindow {
%orig;
self.subviews[0].backgroundColor = [UIColor clearColor];
}
%end
%end
// OLED dark mode by BandarHL
UIColor* raisedColor = [UIColor colorWithRed:0.035 green:0.035 blue:0.035 alpha:1.0];
%group gOLED
%hook YTCommonColorPalette
- (UIColor *)brandBackgroundSolid {
return self.pageStyle == 1 ? [UIColor blackColor] : %orig;
}
- (UIColor *)brandBackgroundPrimary {
return self.pageStyle == 1 ? [UIColor blackColor] : %orig;
}