Save your Bkstg media (Reddit TweakBounty)
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

243 lines
6.7KB

  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. @interface FLPhotoDetailViewController : UIViewController
  33. @property (assign, nonatomic) FLImageView *photoView;
  34. @end
  35. // Save Image with UIImage and the Controller
  36. inline void requestSaveImage(UIImage *snapshot, UIViewController *sender) {
  37. UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  38. [actionSheet addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  39. [sender dismissViewControllerAnimated:YES completion:^{ }]; }]];
  40. [actionSheet addAction:[UIAlertAction actionWithTitle:@"Save Image" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  41. [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^
  42. {
  43. PHAssetChangeRequest *changeRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:snapshot];
  44. changeRequest.creationDate = [NSDate date];
  45. }
  46. completionHandler:^(BOOL success, NSError *error)
  47. {
  48. if (success)
  49. {
  50. NSLog(@"successfully saved");
  51. }
  52. else
  53. {
  54. NSLog(@"error saving to photos: %@", error);
  55. }
  56. }];
  57. [sender dismissViewControllerAnimated:YES completion:^{
  58. }];
  59. }]];
  60. [sender presentViewController:actionSheet animated:YES completion:nil];
  61. }
  62. #define SETUP_LONGPRESS_ONCONTROLLER UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)]; longPress.minimumPressDuration = 1.5; [self.view addGestureRecognizer:longPress];
  63. // Media tab images
  64. %hook FLHubPhotoViewController
  65. -(void)viewDidLoad
  66. {
  67. SETUP_LONGPRESS_ONCONTROLLER
  68. %orig;
  69. }
  70. %new
  71. -(void)handleLongPress:(UILongPressGestureRecognizer *)sender
  72. {
  73. requestSaveImage(self.imageView.originalImage, self);
  74. }
  75. %end
  76. //Normal Timeline Photos
  77. %hook FLPhotoDetailViewController
  78. -(void)viewDidLoad
  79. {
  80. SETUP_LONGPRESS_ONCONTROLLER
  81. %orig;
  82. }
  83. %new
  84. -(void)handleLongPress:(UILongPressGestureRecognizer *)sender
  85. {
  86. requestSaveImage([self.photoView image], self);
  87. }
  88. %end
  89. //Collage Photos
  90. %hook FLCollageSinglePhotoViewController
  91. -(void)viewDidLoad
  92. {
  93. SETUP_LONGPRESS_ONCONTROLLER
  94. %orig;
  95. }
  96. %new
  97. -(void)handleLongPress:(UILongPressGestureRecognizer *)sender
  98. {
  99. requestSaveImage(self.photoView.photoView.originalImage, self);
  100. }
  101. %end
  102. //Poll Images
  103. %hook FLPollSinglePhotoViewController
  104. -(void)viewDidLoad
  105. {
  106. SETUP_LONGPRESS_ONCONTROLLER
  107. %orig;
  108. }
  109. %new
  110. -(void)handleLongPress:(UILongPressGestureRecognizer *)sender
  111. {
  112. requestSaveImage(self.photoView.originalImage, self);
  113. }
  114. %end
  115. //Profile Pictures
  116. %hook FLFullScreenPhotoViewController
  117. -(void)viewDidLoad
  118. {
  119. SETUP_LONGPRESS_ONCONTROLLER
  120. %orig;
  121. }
  122. %new
  123. -(void)handleLongPress:(UILongPressGestureRecognizer *)sender
  124. {
  125. requestSaveImage(self.imageView.image, self);
  126. }
  127. %end
  128. //Saves Videos
  129. %hook FLPostCollectionViewCell
  130. -(void)setPostView:(FLBaseContentHolderView *)holderView
  131. {
  132. if([holderView respondsToSelector:@selector(videoView)])
  133. {
  134. if(holderView.videoView.videoURL)
  135. {
  136. UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(downloadVideo:)];
  137. doubleTap.numberOfTapsRequired = 3;
  138. [self addGestureRecognizer:doubleTap];
  139. }
  140. }
  141. %orig;
  142. }
  143. %new
  144. -(void)downloadVideo:(UITapGestureRecognizer *)sender
  145. {
  146. [sender setEnabled:NO];
  147. NSLog(@"DOWNLOAD FROM URL: %@", self.postView.videoView.videoURL);
  148. UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  149. [actionSheet addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  150. [sender setEnabled:YES];
  151. // Cancel button tappped.
  152. [[[UIApplication sharedApplication] keyWindow].rootViewController dismissViewControllerAnimated:YES completion:^{
  153. }];
  154. }]];
  155. [actionSheet addAction:[UIAlertAction actionWithTitle:@"Save Video" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  156. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self animated:YES];
  157. hud.label.text = @"Downloading";
  158. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  159. NSLog(@"Downloading Started");
  160. NSURL *url = self.postView.videoView.videoURL;
  161. NSData *urlData = [NSData dataWithContentsOfURL:url];
  162. if ( urlData )
  163. {
  164. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  165. NSString *documentsDirectory = [paths objectAtIndex:0];
  166. NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,@"tempVideo.mp4"];
  167. dispatch_async(dispatch_get_main_queue(), ^{
  168. hud.label.text = @"Saving";
  169. [urlData writeToFile:filePath atomically:YES];
  170. NSLog(@"File Saved !");
  171. hud.label.text = @"Importing";
  172. [sender setEnabled:YES];
  173. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  174. NSString *documentsDirectory = [paths objectAtIndex:0];
  175. [[[ALAssetsLibrary alloc] init] writeVideoAtPathToSavedPhotosAlbum:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@", documentsDirectory,@"tempVideo.mp4"]] completionBlock:^(NSURL *assetURL, NSError *error) {
  176. if(assetURL) {
  177. hud.label.text = @"DONE!";
  178. [hud hideAnimated:YES];
  179. } else {
  180. hud.label.text = @"ERROR. Try Again.";
  181. }
  182. }];
  183. });
  184. }
  185. });
  186. [[[UIApplication sharedApplication] keyWindow].rootViewController dismissViewControllerAnimated:YES completion:^{
  187. }];
  188. }]];
  189. // Present action sheet.
  190. [[[UIApplication sharedApplication] keyWindow].rootViewController presentViewController:actionSheet animated:YES completion:nil];
  191. }
  192. %end