Skip to content

Commit

Permalink
project
Browse files Browse the repository at this point in the history
  • Loading branch information
BandarHL committed Jul 12, 2023
1 parent 66ee22d commit 267f07d
Show file tree
Hide file tree
Showing 42 changed files with 5,592 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.theos/
packages/
.DS_Store
35 changes: 35 additions & 0 deletions BHDownload.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// BHDownload.h
// DIYTableView
//
// Created by BandarHelal on 12/01/1442 AH.
// Copyright © 1442 BandarHelal. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@protocol BHDownloadDelegate <NSObject>
@optional
- (void)downloadProgress:(float)progress;
- (void)downloadDidFinish:(NSURL *)filePath Filename:(NSString *)fileName;
- (void)downloadDidFailureWithError:(NSError *)error;
@end

@interface BHDownload : NSObject
{
id delegate;
}
- (void)setDelegate:(id)newDelegate;
- (instancetype)init;
- (void)downloadFileWithURL:(NSURL *)url;
@property (nonatomic, strong) NSString *fileName;
@end

@interface BHDownload () <NSURLSessionDelegate, NSURLSessionDataDelegate, NSURLSessionDownloadDelegate, NSURLSessionStreamDelegate>
@property (nonatomic, strong) NSURLSession *Session;
@end

NS_ASSUME_NONNULL_END
45 changes: 45 additions & 0 deletions BHDownload.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// BHDownload.m
// DIYTableView
//
// Created by BandarHelal on 12/01/1442 AH.
// Copyright © 1442 BandarHelal. All rights reserved.
//

#import "BHDownload.h"

@implementation BHDownload
- (instancetype)init {
self = [super init];
if (self) {
self.Session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration] delegate:self delegateQueue:[NSOperationQueue mainQueue]];
}
return self;
}

- (void)downloadFileWithURL:(NSURL *)url {
if (url) {
self.fileName = url.absoluteString.lastPathComponent;
NSURLSessionDownloadTask *downloadTask = [self.Session downloadTaskWithURL:url];
[downloadTask resume];
}
}
- (void)setDelegate:(id)newDelegate {
if (newDelegate) {
delegate = newDelegate;
}
}
- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didWriteData:(int64_t)bytesWritten totalBytesWritten:(int64_t)totalBytesWritten totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite {
float prog = (float)totalBytesWritten / (float)totalBytesExpectedToWrite;
[delegate downloadProgress:prog];
}
- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(nonnull NSURL *)location {
[delegate downloadDidFinish:location Filename:self.fileName];
}
- (void)URLSession:(NSURLSession *)session didBecomeInvalidWithError:(NSError *)error {
[delegate downloadDidFailureWithError:error];
}
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error {
[delegate downloadDidFailureWithError:error];
}
@end
32 changes: 32 additions & 0 deletions BHIManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

@interface BHIManager: NSObject
+ (BOOL)hideAds;
+ (BOOL)downloadVideos;
+ (BOOL)downloadMusics;
+ (BOOL)hideElementButton;
+ (BOOL)copyVideoDecription;
+ (BOOL)copyMusicLink;
+ (BOOL)copyVideoLink;
+ (BOOL)autoPlay;
+ (BOOL)progressBar;
+ (BOOL)likeConfirmation;
+ (BOOL)likeCommentConfirmation;
+ (BOOL)dislikeCommentConfirmation;
+ (BOOL)followConfirmation;
+ (BOOL)profileSave;
+ (BOOL)profileCopy;
+ (BOOL)alwaysOpenSafari;
+ (BOOL)regionChangingEnabled;
+ (NSDictionary *)selectedRegion;
+ (BOOL)fakeChangesEnabled;
+ (BOOL)fakeVerified;
+ (BOOL)extendedBio;
+ (BOOL)extendedComment;
+ (BOOL)appLock;
+ (void)showSaveVC:(id)item;
+ (void)cleanCache;
+ (BOOL)isEmpty:(NSURL *)url;
+ (NSString *)getDownloadingPersent:(float)per;
@end
149 changes: 149 additions & 0 deletions BHIManager.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
#import "BHIManager.h"
#import "TikTokHeaders.h"

@implementation BHIManager
+ (BOOL)hideAds {
return [[NSUserDefaults standardUserDefaults] boolForKey:@"hide_ads"];
}
+ (BOOL)downloadVideos {
return [[NSUserDefaults standardUserDefaults] boolForKey:@"dw_videos"];
}
+ (BOOL)downloadMusics {
return [[NSUserDefaults standardUserDefaults] boolForKey:@"dw_musics"];
}
+ (BOOL)hideElementButton {
return [[NSUserDefaults standardUserDefaults] boolForKey:@"remove_elements_button"];
}
+ (BOOL)copyVideoDecription {
return [[NSUserDefaults standardUserDefaults] boolForKey:@"copy_decription"];
}
+ (BOOL)copyMusicLink {
return [[NSUserDefaults standardUserDefaults] boolForKey:@"copy_music_link"];
}
+ (BOOL)copyVideoLink {
return [[NSUserDefaults standardUserDefaults] boolForKey:@"copy_video_link"];
}
+ (BOOL)autoPlay {
return [[NSUserDefaults standardUserDefaults] boolForKey:@"auto_play"];
}
+ (BOOL)progressBar {
return [[NSUserDefaults standardUserDefaults] boolForKey:@"show_porgress_bar"];
}
+ (BOOL)likeConfirmation {
return [[NSUserDefaults standardUserDefaults] boolForKey:@"like_confirm"];
}
+ (BOOL)likeCommentConfirmation {
return [[NSUserDefaults standardUserDefaults] boolForKey:@"like_comment_confirm"];
}
+ (BOOL)dislikeCommentConfirmation {
return [[NSUserDefaults standardUserDefaults] boolForKey:@"dislike_comment_confirm"];
}
+ (BOOL)followConfirmation {
return [[NSUserDefaults standardUserDefaults] boolForKey:@"follow_confirm"];
}
+ (BOOL)profileSave {
return [[NSUserDefaults standardUserDefaults] boolForKey:@"save_profile"];
}
+ (BOOL)profileCopy {
return [[NSUserDefaults standardUserDefaults] boolForKey:@"copy_profile_information"];
}
+ (BOOL)alwaysOpenSafari {
return [[NSUserDefaults standardUserDefaults] boolForKey:@"openInBrowser"];
}
+ (BOOL)regionChangingEnabled {
return [[NSUserDefaults standardUserDefaults] boolForKey:@"en_region"];
}
+ (NSDictionary *)selectedRegion {
return [[NSUserDefaults standardUserDefaults] dictionaryForKey:@"region"];
}
+ (BOOL)fakeChangesEnabled {
return [[NSUserDefaults standardUserDefaults] boolForKey:@"en_fake"];
}
+ (BOOL)fakeVerified {
return [[NSUserDefaults standardUserDefaults] boolForKey:@"fake_verify"];
}
+ (BOOL)extendedBio {
return [[NSUserDefaults standardUserDefaults] boolForKey:@"extended_bio"];
}
+ (BOOL)extendedComment {
return [[NSUserDefaults standardUserDefaults] boolForKey:@"extendedComment"];
}
+ (BOOL)appLock {
return [[NSUserDefaults standardUserDefaults] boolForKey:@"padlock"];
}
+ (void)cleanCache {
NSArray <NSURL *> *DocumentFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtURL:[NSURL fileURLWithPath:NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true).firstObject] includingPropertiesForKeys:@[] options:NSDirectoryEnumerationSkipsHiddenFiles error:nil];

for (NSURL *file in DocumentFiles) {
if ([file.pathExtension.lowercaseString isEqualToString:@"mp4"]) {
[[NSFileManager defaultManager] removeItemAtURL:file error:nil];
}
if ([file.pathExtension.lowercaseString isEqualToString:@"png"]) {
[[NSFileManager defaultManager] removeItemAtURL:file error:nil];
}
if ([file.pathExtension.lowercaseString isEqualToString:@"jpeg"]) {
[[NSFileManager defaultManager] removeItemAtURL:file error:nil];
}
if ([file.pathExtension.lowercaseString isEqualToString:@"mp3"]) {
[[NSFileManager defaultManager] removeItemAtURL:file error:nil];
}
if ([file.pathExtension.lowercaseString isEqualToString:@"m4a"]) {
[[NSFileManager defaultManager] removeItemAtURL:file error:nil];
}
}

NSArray <NSURL *> *TempFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtURL:[NSURL fileURLWithPath:NSTemporaryDirectory()] includingPropertiesForKeys:@[] options:NSDirectoryEnumerationSkipsHiddenFiles error:nil];

for (NSURL *file in TempFiles) {
if ([file.pathExtension.lowercaseString isEqualToString:@"mp4"]) {
[[NSFileManager defaultManager] removeItemAtURL:file error:nil];
}
if ([file.pathExtension.lowercaseString isEqualToString:@"mov"]) {
[[NSFileManager defaultManager] removeItemAtURL:file error:nil];
}
if ([file.pathExtension.lowercaseString isEqualToString:@"tmp"]) {
[[NSFileManager defaultManager] removeItemAtURL:file error:nil];
}
if ([file.pathExtension.lowercaseString isEqualToString:@"png"]) {
[[NSFileManager defaultManager] removeItemAtURL:file error:nil];
}
if ([file.pathExtension.lowercaseString isEqualToString:@"jpeg"]) {
[[NSFileManager defaultManager] removeItemAtURL:file error:nil];
}
if ([file.pathExtension.lowercaseString isEqualToString:@"mp3"]) {
[[NSFileManager defaultManager] removeItemAtURL:file error:nil];
}
if ([file.pathExtension.lowercaseString isEqualToString:@"m4a"]) {
[[NSFileManager defaultManager] removeItemAtURL:file error:nil];
}
if ([file hasDirectoryPath]) {
if ([BHIManager isEmpty:file]) {
[[NSFileManager defaultManager] removeItemAtURL:file error:nil];
}
}
}
}
+ (BOOL)isEmpty:(NSURL *)url {
NSArray *FolderFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtURL:url includingPropertiesForKeys:@[] options:NSDirectoryEnumerationSkipsHiddenFiles error:nil];
if (FolderFiles.count == 0) {
return true;
} else {
return false;
}
}
+ (void)showSaveVC:(id)item {
UIActivityViewController *acVC = [[UIActivityViewController alloc] initWithActivityItems:item applicationActivities:nil];
if (is_iPad()) {
acVC.popoverPresentationController.sourceView = topMostController().view;
acVC.popoverPresentationController.sourceRect = CGRectMake(topMostController().view.bounds.size.width / 2.0, topMostController().view.bounds.size.height / 2.0, 1.0, 1.0);
}
[topMostController() presentViewController:acVC animated:true completion:nil];
}

+ (NSString *)getDownloadingPersent:(float)per {
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setNumberStyle:NSNumberFormatterPercentStyle];
NSNumber *number = [NSNumber numberWithFloat:per];
return [numberFormatter stringFromNumber:number];
}
@end
14 changes: 14 additions & 0 deletions BHMultipleDownload.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#import <Foundation/Foundation.h>

@protocol BHMultipleDownloadDelegate <NSObject>
- (void)downloaderProgress:(float)progress;
- (void)downloaderDidFinishDownloadingAllFiles:(NSMutableArray<NSURL *> *)downloadedFilePaths;
- (void)downloaderDidFailureWithError:(NSError *)error;
@end

@interface BHMultipleDownload : NSObject <NSURLSessionDownloadDelegate>
@property (nonatomic, strong) NSURLSession *session;
@property (nonatomic, weak) id<BHMultipleDownloadDelegate> delegate;
- (void)downloadFiles:(NSArray<NSURL *> *)fileURLs;

@end
65 changes: 65 additions & 0 deletions BHMultipleDownload.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#import "BHMultipleDownload.h"

@implementation BHMultipleDownload {
NSMutableArray<NSURL *> *_downloadedFilePaths;
NSInteger _completedDownloads;
NSInteger _totalDownloads;
}

- (instancetype)init {
self = [super init];
if (self) {
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
self.session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:[NSOperationQueue mainQueue]];
}
return self;
}

- (void)downloadFiles:(NSArray<NSURL *> *)fileURLs {
_downloadedFilePaths = [NSMutableArray array];
_completedDownloads = 0;
_totalDownloads = fileURLs.count;

for (NSURL *fileURL in fileURLs) {
NSURLSessionDownloadTask *downloadTask = [self.session downloadTaskWithURL:fileURL];
[downloadTask resume];
}

if (fileURLs.count == 0) {
[self URLSession:self.session didBecomeInvalidWithError:[NSError errorWithDomain:NSURLErrorDomain code:99 userInfo:nil]];
}
}

- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didWriteData:(int64_t)bytesWritten totalBytesWritten:(int64_t)totalBytesWritten totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite {
float prog = (float)totalBytesWritten / (float)totalBytesExpectedToWrite;
if ([self.delegate respondsToSelector:@selector(downloaderProgress:)]) {
[self.delegate downloaderProgress:prog];
}
}
- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask
didFinishDownloadingToURL:(NSURL *)location {
NSString *documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
NSString *destinationPath = [documentsPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@-%@", NSUUID.UUID.UUIDString, downloadTask.response.suggestedFilename]];

NSError *error;
[[NSFileManager defaultManager] moveItemAtURL:location toURL:[NSURL fileURLWithPath:destinationPath] error:&error];

if (error == nil) {
[_downloadedFilePaths addObject:[NSURL fileURLWithPath:destinationPath]];
}

_completedDownloads++;

if (_completedDownloads == _totalDownloads) {
if ([self.delegate respondsToSelector:@selector(downloaderDidFinishDownloadingAllFiles:)]) {
[self.delegate downloaderDidFinishDownloadingAllFiles:_downloadedFilePaths];
}
}
}

- (void)URLSession:(NSURLSession *)session didBecomeInvalidWithError:(NSError *)error {
if ([self.delegate respondsToSelector:@selector(downloaderDidFailureWithError:)]) {
[self.delegate downloaderDidFailureWithError:error];
}
}
@end
1 change: 1 addition & 0 deletions BHTikTok.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ Filter = { Bundles = ( "com.zhiliaoapp.musically" ); }; }
Loading

0 comments on commit 267f07d

Please sign in to comment.