Skip to content

Commit

Permalink
feat: enhance video blocking logic
Browse files Browse the repository at this point in the history
  • Loading branch information
castdrian committed Dec 27, 2024
1 parent 510c696 commit f905b9e
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"command": "zsh",
"args": [
"-c",
"rm -rf packages && make clean && make package FINALPACKAGE=1 THEOS_PACKAGE_SCHEME=rootless && cp ./packages/*arm64.deb ~/Library/Mobile\\ Documents/com~apple~CloudDocs/ && cp ./.theos/obj/Gonerino.dylib ~/Library/Mobile\\ Documents/com~apple~CloudDocs/"
"rm -rf packages && make clean && make package"
],
"problemMatcher": {
"owner": "cpp",
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ TARGET := iphone:clang:latest:14.0
ARCHS = arm64
INSTALL_TARGET_PROCESSES = YouTube
THEOS_PACKAGE_SCHEME = rootless
FINALPACKAGE = 1

include $(THEOS)/makefiles/common.mk

Expand Down
31 changes: 5 additions & 26 deletions Tweak.x
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@

- (void)layoutSubviews {
%orig;
[self removeOffendingCells];
}

%new
- (void)removeOffendingCells {
__weak typeof(self) weakSelf = self;

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
dispatch_async(dispatch_get_main_queue(), ^{
__strong typeof(weakSelf) strongSelf = weakSelf;
if (!strongSelf)
return;
Expand Down Expand Up @@ -50,31 +54,6 @@
});
}

%new
- (void)removeOffendingCells {
NSArray *visibleCells = [self visibleCells];
NSMutableArray *indexPathsToRemove = [NSMutableArray array];

for (UICollectionViewCell *cell in visibleCells) {
if ([cell isKindOfClass:NSClassFromString(@"_ASCollectionViewCell")]) {
_ASCollectionViewCell *asCell = (_ASCollectionViewCell *)cell;
if ([asCell respondsToSelector:@selector(node)]) {
id node = [asCell node];
if ([Util nodeContainsBlockedVideo:node]) {
NSIndexPath *indexPath = [self indexPathForCell:cell];
if (indexPath) {
[indexPathsToRemove addObject:indexPath];
}
}
}
}
}

if (indexPathsToRemove.count > 0) {
[self performBatchUpdates:^{ [self deleteItemsAtIndexPaths:indexPathsToRemove]; } completion:nil];
}
}

%end

%hook YTDefaultSheetController
Expand Down
49 changes: 48 additions & 1 deletion Util.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,58 @@ + (void)extractVideoInfoFromNode:(id)node
}

+ (BOOL)nodeContainsBlockedVideo:(id)node {
if ([node respondsToSelector:@selector(accessibilityLabel)]) {
NSString *accessibilityLabel = [node accessibilityLabel];
if (accessibilityLabel) {
if ([[WordManager sharedInstance] isWordBlocked:accessibilityLabel]) {
NSLog(@"[Gonerino] Blocking video because of blocked word: %@", accessibilityLabel);
return YES;
}
}
}

if ([node isKindOfClass:NSClassFromString(@"ASTextNode")]) {
NSAttributedString *attributedText = [(ASTextNode *)node attributedText];
NSString *text = [attributedText string];

if ([[WordManager sharedInstance] isWordBlocked:text]) {
NSLog(@"[Gonerino] Blocking content with blocked word: %@", text);
return YES;
}

if ([text containsString:@" · "]) {
NSArray *components = [text componentsSeparatedByString:@" · "];
if (components.count >= 1) {
NSString *potentialChannelName = components[0];
if ([[ChannelManager sharedInstance] isChannelBlocked:potentialChannelName]) {
NSLog(@"[Gonerino] Blocking content from blocked channel: %@", potentialChannelName);
return YES;
}
}
}
}

if ([node respondsToSelector:@selector(channelName)]) {
NSString *nodeChannelName = [node channelName];
if ([[ChannelManager sharedInstance] isChannelBlocked:nodeChannelName]) {
NSLog(@"[Gonerino] Blocking content from blocked channel: %@", nodeChannelName);
return YES;
}
}

if ([node respondsToSelector:@selector(ownerName)]) {
NSString *nodeOwnerName = [node ownerName];
if ([[ChannelManager sharedInstance] isChannelBlocked:nodeOwnerName]) {
NSLog(@"[Gonerino] Blocking content from blocked channel: %@", nodeOwnerName);
return YES;
}
}

__block BOOL isBlocked = NO;

if ([node isKindOfClass:NSClassFromString(@"ASTextNode")]) {
NSAttributedString *attributedText = [(ASTextNode *)node attributedText];
NSString *text = [attributedText string];
NSString *text = [attributedText string];

if ([[NSUserDefaults standardUserDefaults] boolForKey:@"GonerinoPeopleWatched"] &&
[text isEqualToString:@"People also watched this video"]) {
Expand Down
2 changes: 1 addition & 1 deletion control
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: dev.adrian.gonerino
Name: Gonerino
Version: 1.0.1
Version: 1.1.0
Architecture: iphoneos-arm
Description: Remove videos uploaded by specific channels
Maintainer: Adrian Castro
Expand Down

0 comments on commit f905b9e

Please sign in to comment.