Save your Bkstg media (Reddit TweakBounty)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

410 satır
12KB

  1. #import <Photos/Photos.h>
  2. #import <AssetsLibrary/AssetsLibrary.h>
  3. #import "MBProgressHUD.h"
  4. @interface FLImageView : UIView
  5. @property (assign, nonatomic) UIImage *originalImage;
  6. -(UIImage *)image;
  7. @end
  8. @interface FLHubPhotoViewController : UIViewController
  9. @property (assign, nonatomic) FLImageView *imageView;
  10. @end
  11. @interface FLVideoContentView : UIView
  12. @property (assign, nonatomic) NSURL *videoURL;
  13. @end
  14. @interface FLBaseContentHolderView : UIView
  15. @property (assign, nonatomic) FLVideoContentView *videoView;
  16. @end
  17. @interface FLPostCollectionViewCell : UIView
  18. @property (assign, nonatomic) FLBaseContentHolderView *postView;
  19. @end
  20. @interface FLCollageSinglePhotoView : UIView
  21. @property (assign, nonatomic) FLImageView* photoView;
  22. @end
  23. @interface FLCollageSinglePhotoViewController : UIViewController
  24. @property (assign, nonatomic) FLCollageSinglePhotoView* photoView;
  25. @end
  26. @interface FLPollSinglePhotoViewController : UIViewController
  27. @property (assign, nonatomic) FLImageView *photoView;
  28. @end
  29. @interface FLFullScreenPhotoViewController : UIViewController
  30. @property (assign, nonatomic) UIImageView *imageView;
  31. @end
  32. %hook FLHubPhotoViewController
  33. -(void)viewDidLoad
  34. {
  35. UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]
  36. initWithTarget:self
  37. action:@selector(handleLongPress:)];
  38. longPress.minimumPressDuration = 1.5;
  39. [self.view addGestureRecognizer:longPress];
  40. %orig;
  41. }
  42. %new
  43. -(void)handleLongPress:(UILongPressGestureRecognizer *)sender
  44. {
  45. UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  46. [actionSheet addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  47. // Cancel button tappped.
  48. [self dismissViewControllerAnimated:YES completion:^{
  49. }];
  50. }]];
  51. [actionSheet addAction:[UIAlertAction actionWithTitle:@"Save Image" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  52. UIImage *snapshot = self.imageView.originalImage;
  53. [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^
  54. {
  55. PHAssetChangeRequest *changeRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:snapshot];
  56. changeRequest.creationDate = [NSDate date];
  57. }
  58. completionHandler:^(BOOL success, NSError *error)
  59. {
  60. if (success)
  61. {
  62. NSLog(@"successfully saved");
  63. }
  64. else
  65. {
  66. NSLog(@"error saving to photos: %@", error);
  67. }
  68. }];
  69. [self dismissViewControllerAnimated:YES completion:^{
  70. }];
  71. }]];
  72. // Present action sheet.
  73. [self presentViewController:actionSheet animated:YES completion:nil];
  74. }
  75. %end
  76. @interface FLPhotoDetailViewController : UIViewController
  77. @property (assign, nonatomic) FLImageView *photoView;
  78. @end
  79. %hook FLPhotoDetailViewController
  80. -(void)viewDidLoad
  81. {
  82. UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]
  83. initWithTarget:self
  84. action:@selector(handleLongPress:)];
  85. longPress.minimumPressDuration = 1.5;
  86. [self.view addGestureRecognizer:longPress];
  87. %orig;
  88. }
  89. %new
  90. -(void)handleLongPress:(UILongPressGestureRecognizer *)sender
  91. {
  92. UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  93. [actionSheet addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  94. // Cancel button tappped.
  95. [self dismissViewControllerAnimated:YES completion:^{
  96. }];
  97. }]];
  98. [actionSheet addAction:[UIAlertAction actionWithTitle:@"Save Image" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  99. UIImage *snapshot = [self.photoView image];
  100. [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^
  101. {
  102. PHAssetChangeRequest *changeRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:snapshot];
  103. changeRequest.creationDate = [NSDate date];
  104. }
  105. completionHandler:^(BOOL success, NSError *error)
  106. {
  107. if (success)
  108. {
  109. NSLog(@"successfully saved");
  110. }
  111. else
  112. {
  113. NSLog(@"error saving to photos: %@", error);
  114. }
  115. }];
  116. [self dismissViewControllerAnimated:YES completion:^{
  117. }];
  118. }]];
  119. // Present action sheet.
  120. [self presentViewController:actionSheet animated:YES completion:nil];
  121. }
  122. %end
  123. %hook FLCollageSinglePhotoViewController
  124. -(void)viewDidLoad
  125. {
  126. UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]
  127. initWithTarget:self
  128. action:@selector(handleLongPress:)];
  129. longPress.minimumPressDuration = 1.5;
  130. [self.view addGestureRecognizer:longPress];
  131. %orig;
  132. }
  133. %new
  134. -(void)handleLongPress:(UILongPressGestureRecognizer *)sender
  135. {
  136. UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  137. [actionSheet addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  138. // Cancel button tappped.
  139. [self dismissViewControllerAnimated:YES completion:^{
  140. }];
  141. }]];
  142. [actionSheet addAction:[UIAlertAction actionWithTitle:@"Save Image" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  143. UIImage *snapshot = self.photoView.photoView.originalImage;
  144. [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^
  145. {
  146. PHAssetChangeRequest *changeRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:snapshot];
  147. changeRequest.creationDate = [NSDate date];
  148. }
  149. completionHandler:^(BOOL success, NSError *error)
  150. {
  151. if (success)
  152. {
  153. NSLog(@"successfully saved");
  154. }
  155. else
  156. {
  157. NSLog(@"error saving to photos: %@", error);
  158. }
  159. }];
  160. [self dismissViewControllerAnimated:YES completion:^{
  161. }];
  162. }]];
  163. // Present action sheet.
  164. [self presentViewController:actionSheet animated:YES completion:nil];
  165. }
  166. %end
  167. %hook FLPollSinglePhotoViewController
  168. -(void)viewDidLoad
  169. {
  170. UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]
  171. initWithTarget:self
  172. action:@selector(handleLongPress:)];
  173. longPress.minimumPressDuration = 1.5;
  174. [self.view addGestureRecognizer:longPress];
  175. %orig;
  176. }
  177. %new
  178. -(void)handleLongPress:(UILongPressGestureRecognizer *)sender
  179. {
  180. UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  181. [actionSheet addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  182. // Cancel button tappped.
  183. [self dismissViewControllerAnimated:YES completion:^{
  184. }];
  185. }]];
  186. [actionSheet addAction:[UIAlertAction actionWithTitle:@"Save Image" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  187. UIImage *snapshot = self.photoView.originalImage;
  188. [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^
  189. {
  190. PHAssetChangeRequest *changeRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:snapshot];
  191. changeRequest.creationDate = [NSDate date];
  192. }
  193. completionHandler:^(BOOL success, NSError *error)
  194. {
  195. if (success)
  196. {
  197. NSLog(@"successfully saved");
  198. }
  199. else
  200. {
  201. NSLog(@"error saving to photos: %@", error);
  202. }
  203. }];
  204. [self dismissViewControllerAnimated:YES completion:^{
  205. }];
  206. }]];
  207. // Present action sheet.
  208. [self presentViewController:actionSheet animated:YES completion:nil];
  209. }
  210. %end
  211. %hook FLFullScreenPhotoViewController
  212. -(void)viewDidLoad
  213. {
  214. UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]
  215. initWithTarget:self
  216. action:@selector(handleLongPress:)];
  217. longPress.minimumPressDuration = 1.5;
  218. [self.view addGestureRecognizer:longPress];
  219. %orig;
  220. }
  221. %new
  222. -(void)handleLongPress:(UILongPressGestureRecognizer *)sender
  223. {
  224. UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  225. [actionSheet addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  226. // Cancel button tappped.
  227. [self dismissViewControllerAnimated:YES completion:^{
  228. }];
  229. }]];
  230. [actionSheet addAction:[UIAlertAction actionWithTitle:@"Save Image" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  231. UIImage *snapshot = self.imageView.image;
  232. [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^
  233. {
  234. PHAssetChangeRequest *changeRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:snapshot];
  235. changeRequest.creationDate = [NSDate date];
  236. }
  237. completionHandler:^(BOOL success, NSError *error)
  238. {
  239. if (success)
  240. {
  241. NSLog(@"successfully saved");
  242. }
  243. else
  244. {
  245. NSLog(@"error saving to photos: %@", error);
  246. }
  247. }];
  248. [self dismissViewControllerAnimated:YES completion:^{
  249. }];
  250. }]];
  251. // Present action sheet.
  252. [self presentViewController:actionSheet animated:YES completion:nil];
  253. }
  254. %end
  255. // IGNORE ABOVE. SAVES IMAGES
  256. //FLAVPlayerLayerView
  257. //FLHubVideoCollection
  258. //FLVideoContentHolderVIew
  259. %hook FLPostCollectionViewCell
  260. -(void)setPostView:(FLBaseContentHolderView *)holderView
  261. {
  262. if([holderView respondsToSelector:@selector(videoView)])
  263. {
  264. if(holderView.videoView.videoURL)
  265. {
  266. UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(downloadVideo:)];
  267. doubleTap.numberOfTapsRequired = 3;
  268. [self addGestureRecognizer:doubleTap];
  269. }
  270. }
  271. %orig;
  272. }
  273. %new
  274. -(void)downloadVideo:(UITapGestureRecognizer *)sender
  275. {
  276. [sender setEnabled:NO];
  277. NSLog(@"DOWNLOAD FROM URL: %@", self.postView.videoView.videoURL);
  278. UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  279. [actionSheet addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  280. [sender setEnabled:YES];
  281. // Cancel button tappped.
  282. [[[UIApplication sharedApplication] keyWindow].rootViewController dismissViewControllerAnimated:YES completion:^{
  283. }];
  284. }]];
  285. [actionSheet addAction:[UIAlertAction actionWithTitle:@"Save Video" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  286. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self animated:YES];
  287. hud.label.text = @"Downloading";
  288. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  289. NSLog(@"Downloading Started");
  290. NSURL *url = self.postView.videoView.videoURL;
  291. NSData *urlData = [NSData dataWithContentsOfURL:url];
  292. if ( urlData )
  293. {
  294. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  295. NSString *documentsDirectory = [paths objectAtIndex:0];
  296. NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,@"tempVideo.mp4"];
  297. dispatch_async(dispatch_get_main_queue(), ^{
  298. hud.label.text = @"Saving";
  299. [urlData writeToFile:filePath atomically:YES];
  300. NSLog(@"File Saved !");
  301. hud.label.text = @"Importing";
  302. [sender setEnabled:YES];
  303. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  304. NSString *documentsDirectory = [paths objectAtIndex:0];
  305. [[[ALAssetsLibrary alloc] init] writeVideoAtPathToSavedPhotosAlbum:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@", documentsDirectory,@"tempVideo.mp4"]] completionBlock:^(NSURL *assetURL, NSError *error) {
  306. if(assetURL) {
  307. hud.label.text = @"DONE!";
  308. [hud hideAnimated:YES];
  309. } else {
  310. hud.label.text = @"ERROR. Try Again.";
  311. }
  312. }];
  313. });
  314. }
  315. });
  316. [[[UIApplication sharedApplication] keyWindow].rootViewController dismissViewControllerAnimated:YES completion:^{
  317. }];
  318. }]];
  319. // Present action sheet.
  320. [[[UIApplication sharedApplication] keyWindow].rootViewController presentViewController:actionSheet animated:YES completion:nil];
  321. }
  322. %end