Skip to content

Commit

Permalink
Update YouTube-X
Browse files Browse the repository at this point in the history
  • Loading branch information
aricloverEXALT authored Jul 20, 2024
1 parent 007dbb0 commit ff1ad94
Showing 1 changed file with 26 additions and 46 deletions.
72 changes: 26 additions & 46 deletions Sources/uYouPlus.xm
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,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 +153,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,52 +189,28 @@ 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;
}
NSString *adString = getAdString(description);
if (adString) {
HBLogDebug(@"YTX getAdString 1 %@ %@", adString, cellDividerData);
return cellDividerData;
}
return %orig;
}
%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;
}
- (void)addSectionsFromArray:(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];
}
%orig;
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;
}
return NO;
}];
[newArray removeObjectsAtIndexes:removeIndexes];
%orig(newArray.copy);
}
%end
%end
Expand Down

0 comments on commit ff1ad94

Please sign in to comment.