Save your Bkstg media (Reddit TweakBounty)
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

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