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.

351 lines
10KB

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