Skip to content

Commit

Permalink
Merge branch 'arichornlover:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
dora727 authored Aug 3, 2024
2 parents fe8de04 + 064774b commit 1a81a88
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 43 deletions.
89 changes: 48 additions & 41 deletions Sources/uYouPlus.xm
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ NSBundle *tweakBundle = uYouPlusBundle();
- (void)decorateContext:(id)context { %orig(nil); }
%end

%hook YTLocalPlaybackController
- (id)createAdsPlaybackCoordinator { return nil; }
%end

%hook MDXSession
- (void)adPlaying:(id)ad {}
%end

%hook YTReelInfinitePlaybackDataSource
- (void)setReels:(NSMutableOrderedSet <YTReelModel *> *)reels {
[reels removeObjectsAtIndexes:[reels indexesOfObjectsPassingTest:^BOOL(YTReelModel *obj, NSUInteger idx, BOOL *stop) {
Expand Down Expand Up @@ -138,6 +146,12 @@ NSBundle *tweakBundle = uYouPlusBundle();
%hook YTAccountScopedAdsInnerTubeContextDecorator
- (void)decorateContext:(id)context { %orig(nil); }
%end
%hook YTLocalPlaybackController
- (id)createAdsPlaybackCoordinator { return nil; }
%end
%hook MDXSession
- (void)adPlaying:(id)ad {}
%end
%hook YTReelInfinitePlaybackDataSource
- (void)setReels:(NSMutableOrderedSet <YTReelModel *> *)reels {
[reels removeObjectsAtIndexes:[reels indexesOfObjectsPassingTest:^BOOL(YTReelModel *obj, NSUInteger idx, BOOL *stop) {
Expand All @@ -147,8 +161,6 @@ NSBundle *tweakBundle = uYouPlusBundle();
}
%end
NSString *getAdString(NSString *description) {
if ([description containsString:@"ad_layout"])
return @"ad_layout";
if ([description containsString:@"brand_promo"])
return @"brand_promo";
if ([description containsString:@"carousel_footered_layout"])
Expand Down Expand Up @@ -185,53 +197,48 @@ NSString *getAdString(NSString *description) {
return @"video_display_full_buttoned_layout";
return nil;
}
static __strong NSData *cellDividerData;
%hook YTIElementRenderer
- (NSData *)elementData {
NSString *description = [self description];
if ([description containsString:@"cell_divider"]) {
if (!cellDividerData) cellDividerData = %orig;
return cellDividerData;
}
if (!cellDividerData) return %orig;
if ([self respondsToSelector:@selector(hasCompatibilityOptions)] && self.hasCompatibilityOptions && self.compatibilityOptions.hasAdLoggingData) {
HBLogDebug(@"YTX adLogging 1 %@", cellDividerData);
return cellDividerData;
static BOOL isAdRenderer(YTIElementRenderer *elementRenderer, int kind) {
if ([elementRenderer respondsToSelector:@selector(hasCompatibilityOptions)] && elementRenderer.hasCompatibilityOptions && elementRenderer.compatibilityOptions.hasAdLoggingData) {
HBLogDebug(@"YTX adLogging %d %@", kind, elementRenderer);
return YES;
}
NSString *description = [elementRenderer description];
NSString *adString = getAdString(description);
if (adString) {
HBLogDebug(@"YTX getAdString 1 %@ %@", adString, cellDividerData);
return cellDividerData;
HBLogDebug(@"YTX getAdString %d %@ %@", kind, adString, elementRenderer);
return YES;
}
return %orig;
return NO;
}
%end
%hook YTInnerTubeCollectionViewController
- (void)loadWithModel:(YTISectionListRenderer *)model {
if ([model isKindOfClass:%c(YTISectionListRenderer)]) {
NSMutableArray <YTISectionListSupportedRenderers *> *contentsArray = model.contentsArray;
NSIndexSet *removeIndexes = [contentsArray indexesOfObjectsPassingTest:^BOOL(YTISectionListSupportedRenderers *renderers, NSUInteger idx, BOOL *stop) {
if (![renderers isKindOfClass:%c(YTISectionListSupportedRenderers)])
return NO;
YTIItemSectionRenderer *sectionRenderer = renderers.itemSectionRenderer;
YTIItemSectionSupportedRenderers *firstObject = [sectionRenderer.contentsArray firstObject];
YTIElementRenderer *elementRenderer = firstObject.elementRenderer;
if ([elementRenderer respondsToSelector:@selector(hasCompatibilityOptions)] && elementRenderer.hasCompatibilityOptions && elementRenderer.compatibilityOptions.hasAdLoggingData) {
HBLogDebug(@"YTX adLogging 2 %@", elementRenderer);
return YES;
}
NSString *description = [elementRenderer description];
NSString *adString = getAdString(description);
if (adString) {
HBLogDebug(@"YTX getAdString 2 %@ %@", adString, elementRenderer);
return YES;
}
static NSMutableArray <YTIItemSectionRenderer *> *filteredArray(NSArray <YTIItemSectionRenderer *> *array) {
NSMutableArray <YTIItemSectionRenderer *> *newArray = [array mutableCopy];
NSIndexSet *removeIndexes = [newArray indexesOfObjectsPassingTest:^BOOL(YTIItemSectionRenderer *sectionRenderer, NSUInteger idx, BOOL *stop) {
if (![sectionRenderer isKindOfClass:%c(YTIItemSectionRenderer)])
return NO;
}];
[contentsArray removeObjectsAtIndexes:removeIndexes];
}
NSMutableArray <YTIItemSectionSupportedRenderers *> *contentsArray = sectionRenderer.contentsArray;
if (contentsArray.count > 1) {
NSIndexSet *removeContentsArrayIndexes = [contentsArray indexesOfObjectsPassingTest:^BOOL(YTIItemSectionSupportedRenderers *sectionSupportedRenderers, NSUInteger idx2, BOOL *stop2) {
YTIElementRenderer *elementRenderer = sectionSupportedRenderers.elementRenderer;
return isAdRenderer(elementRenderer, 3);
}];
[contentsArray removeObjectsAtIndexes:removeContentsArrayIndexes];
}
YTIItemSectionSupportedRenderers *firstObject = [contentsArray firstObject];
YTIElementRenderer *elementRenderer = firstObject.elementRenderer;
return isAdRenderer(elementRenderer, 2);
}];
[newArray removeObjectsAtIndexes:removeIndexes];
return newArray;
}
%hook YTInnerTubeCollectionViewController
- (void)displaySectionsWithReloadingSectionControllerByRenderer:(id)renderer {
NSMutableArray *sectionRenderers = [self valueForKey:@"_sectionRenderers"];
[self setValue:filteredArray(sectionRenderers) forKey:@"_sectionRenderers"];
%orig;
}
- (void)addSectionsFromArray:(NSArray <YTIItemSectionRenderer *> *)array {
%orig(filteredArray(array));
}
%end
%end

Expand Down
13 changes: 11 additions & 2 deletions Sources/uYouPlusPatches.xm
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

# pragma mark - YouTube patches

/*
// Fix Google Sign in by @PoomSmart and @level3tjg (qnblackcat/uYouPlus#684)
%group gGoogleSignInPatch
%hook NSBundle
- (NSDictionary *)infoDictionary {
NSMutableDictionary *info = %orig.mutableCopy;
Expand All @@ -12,7 +12,7 @@
return info;
}
%end
*/
%end

// Workaround for MiRO92/uYou-for-YouTube#12, qnblackcat/uYouPlus#263
%hook YTDataUtils
Expand Down Expand Up @@ -98,6 +98,7 @@ typedef NS_ENUM(NSInteger, ShareEntityType) {
ShareEntityFieldVideo = 1,
ShareEntityFieldPlaylist = 2,
ShareEntityFieldChannel = 3,
ShareEntityFieldPost = 6,
ShareEntityFieldClip = 8
};

Expand All @@ -110,6 +111,7 @@ static inline NSString* extractIdWithFormat(GPBUnknownFieldSet *fields, NSIntege
NSString *id = [[NSString alloc] initWithData:[idField.lengthDelimitedList firstObject] encoding:NSUTF8StringEncoding];
return [NSString stringWithFormat:format, id];
}

static BOOL showNativeShareSheet(NSString *serializedShareEntity, UIView *sourceView) {
GPBMessage *shareEntity = [%c(GPBMessage) deserializeFromString:serializedShareEntity];
GPBUnknownFieldSet *fields = shareEntity.unknownFields;
Expand Down Expand Up @@ -138,6 +140,9 @@ static BOOL showNativeShareSheet(NSString *serializedShareEntity, UIView *source
if (!shareUrl)
shareUrl = extractIdWithFormat(fields, ShareEntityFieldVideo, @"https://youtube.com/watch?v=%@");

if (!shareUrl)
shareUrl = extractIdWithFormat(fields, ShareEntityFieldPost, @"https://youtube.com/post/%@");

if (!shareUrl)
return NO;

Expand Down Expand Up @@ -171,6 +176,7 @@ static BOOL showNativeShareSheet(NSString *serializedShareEntity, UIView *source
}
%end


/* ------------------- iPhone Layout ------------------- */

%hook ELMPBShowActionSheetCommand
Expand Down Expand Up @@ -331,6 +337,9 @@ static void refreshUYouAppearance() {

%ctor {
%init;
if (IS_ENABLED(@"googleSignInPatch_enabled")) {
%init(gGoogleSignInPatch);
}
// if (@available(iOS 16, *)) {
// %init(iOS16);
// }
Expand Down
1 change: 1 addition & 0 deletions Sources/uYouPlusSettings.xm
Original file line number Diff line number Diff line change
Expand Up @@ -1340,6 +1340,7 @@ extern NSBundle *uYouPlusBundle();
# pragma mark - Miscellaneous
SECTION_HEADER(LOC(@"MISCELLANEOUS"));

SWITCH_ITEM2(LOC(@"YouTube Sign-In Patch"), LOC(@"When enabled, it will allow you to sign in on the YouTube App when sideloaded.\nUnwanted Side Effects: Most Icons in the app will be Invisible & Notifications might not work."), @"googleSignInPatch_enabled");
SWITCH_ITEM2(LOC(@"ADBLOCK_WORKAROUND_LITE"), LOC(@"ADBLOCK_WORKAROUND_LITE_DESC"), @"uYouAdBlockingWorkaroundLite_enabled");
SWITCH_ITEM2(LOC(@"ADBLOCK_WORKAROUND"), LOC(@"ADBLOCK_WORKAROUND_DESC"), @"uYouAdBlockingWorkaround_enabled");
SWITCH_ITEM3(
Expand Down

0 comments on commit 1a81a88

Please sign in to comment.