Read images from a iphone album using ALAssetsLibrary make slow - ios

Read images from a iphone album using ALAssetsLibrary will took 30 seconds to load images of 700. Is there any other version of code using ALAssetsLibrary? My version of Code was below
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
NSLog(#"number of assets = %ld",(long)group.numberOfAssets);
[group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
if(result == nil) {
return;
}
ALAssetRepresentation *representation = [result defaultRepresentation];
BR_AssetsInfo *info = [[BR_AssetsInfo alloc] init];
info.thumbnail = [UIImage imageWithCGImage:[result thumbnail]];
info.originalImage = [UIImage imageWithCGImage:[representation fullResolutionImage]];
info.imageURLString = [[representation url] absoluteString];
info.isSelected = NO;
for (BR_AssetsInfo *asset in self.selectedAssetsArray) {
if ([asset isEqual:info]) {
info.isSelected = YES;
}
}
[self.assetsDataArray addObject:info];
[self.photosCollectionView reloadData];
}];
} failureBlock:^(NSError *error) {
if (error.code == ALAssetsLibraryAccessUserDeniedError) {
NSLog(#"user denied access, code: %li",(long)error.code);
}else{
NSLog(#"Other error code: %li",(long)error.code);
}
}];

Related

how to display images by using ALAsseetLibrary

I am accessing the list of images by using the ALAssetLibrary and i got the list of all image in log file . But i am unable to display any image. Can anyone help me through this?
For getting the list of all images my code is here---
- (IBAction)getListOfImages:(id)sender {
NSMutableArray* assetURLDictionaries = [[NSMutableArray alloc] init];
NSMutableArray *xy =[[NSMutableArray alloc]init];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
void (^assetEnumerator)( ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) {
if(result != nil) {
if([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto]) {
[assetURLDictionaries addObject:[result valueForProperty:ALAssetPropertyURLs]];
NSLog(#"result is:%#",result);
NSLog(#"asset URLDictionary is:%#",assetURLDictionaries);
NSURL *url= (NSURL*) [[result defaultRepresentation]url];
[library assetForURL:url
resultBlock:^(ALAsset *asset) {
[xy addObject:[UIImage imageWithCGImage:[[asset defaultRepresentation] fullScreenImage]]];
NSLog(#" xy is:%#",xy);
UIImageView *image =[ [UIImageView alloc ] initWithImage:[xy objectAtIndex:0]];
NSLog(#"image is:%#",image);
}
failureBlock:^(NSError *error){ NSLog(#"test:Fail"); } ];
}
}
};
NSMutableArray *assetGroups = [[NSMutableArray alloc] init];
void (^ assetGroupEnumerator) ( ALAssetsGroup *, BOOL *)= ^(ALAssetsGroup *group, BOOL *stop) {
NSLog(#"hello");
if(group != nil) {
[group enumerateAssetsUsingBlock:assetEnumerator];
[assetGroups addObject:group];
NSLog(#"Number of assets in group :%d",[group numberOfAssets]);
NSLog(#"asset group is:%#",assetGroups);
}
};
assetGroups = [[NSMutableArray alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupAll
usingBlock:assetGroupEnumerator
failureBlock:^(NSError *error) {
NSLog(#"A problem occurred");
}];
}

Get All Images from cameraroll asynchrously

I want to get all images from cameraroll asynchrously
Now I am using that code but my application got hanged untill all the images retrieved , I noticed in instigram or other application it doen't take time to load picture from camerroll.
-(void)getAllPictures
{
NSLog(#"i m in ");
imageArray=[[NSArray alloc] init];
mutableArray =[[NSMutableArray alloc]init];
NSMutableArray* assetURLDictionaries = [[NSMutableArray alloc] init];
library = [[ALAssetsLibrary alloc] init];
void (^assetEnumerator)( ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) {
NSLog(#"i m in block");
if(result != nil) {
if([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto]) {
NSLog(#"result not nill");
[assetURLDictionaries addObject:[result valueForProperty:ALAssetPropertyURLs]];
NSURL *url= (NSURL*) [[result defaultRepresentation]url];
NSLog(#"url=%#",url);
[library assetForURL:url
resultBlock:^(ALAsset *asset) {
[mutableArray addObject:[UIImage imageWithCGImage:[[asset defaultRepresentation] fullScreenImage]]];
imageArray=[[NSArray alloc] initWithArray:mutableArray];
[self allPhotosCollected:imageArray];
if ([mutableArray count]==count)
{NSLog(#"condition %lu , %i",(unsigned long)mutableArray.count,count);
imageArray=[[NSArray alloc] initWithArray:mutableArray];
[self allPhotosCollected:imageArray];
}
}
failureBlock:^(NSError *error){ NSLog(#"operation was not successfull!"); } ];
}
}
};
NSLog(#"image array= %#",imageArray);
NSMutableArray *assetGroups = [[NSMutableArray alloc] init];
void (^ assetGroupEnumerator) ( ALAssetsGroup *, BOOL *)= ^(ALAssetsGroup *group, BOOL *stop) {
if(group != nil) {
NSLog(#"group not nill");
[group enumerateAssetsUsingBlock:assetEnumerator];
[assetGroups addObject:group];
count=(int)[group numberOfAssets];
}
};
assetGroups = [[NSMutableArray alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupAll
usingBlock:assetGroupEnumerator
failureBlock:^(NSError *error) {NSLog(#"There is an error");}];
}
-(void)allPhotosCollected:(NSArray*)imgArray
{
//write your code here after getting all the photos from library...
NSLog(#"all pictures are %#",imgArray);
[_collection_view reloadData];
/*
CGRect collectionFrame = self.collection_view.frame;
collectionFrame.size.height=700;
collectionFrame.size.width=320;*/
self.verticalLayoutConstraint.constant = 700;
//self.collection_view.frame=collectionFrame;
}
Try like this .. Its increasing fast speed. If you will get all images in array then it will crashing your application while using iPhone & iPad that contain 1000+ photos. So Try like this.
library = [[ALAssetsLibrary alloc] init];
if (library == nil)
library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop)
{
[group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop)
{
if (asset)
{
[imageArray addObject:asset];
[collectionViewObj reloadData];
}
}];
}
failureBlock:^(NSError *error)
{
UIAlertView *alertViewObj = [[UIAlertView alloc]initWithTitle:#"Max6Miz does not have access to your photos" message:#"You can enable access in Settings" delegate:self cancelButtonTitle:nil otherButtonTitles:#"Settings",#"Ok", nil];
[alertViewObj show];
NSLog(#"error");
}];
Show your image in your delegate function like this using this collectionView cellForItemAtIndexPath
ALAsset *asset = (ALAsset *)imageArray[indexPath.row];
UIImage *showingImage = [UIImage imageWithCGImage:[asset thumbnail]];
Please use new modern Photos framework which is available from iOS 8.0. I've tested it on 50k photos and 1.5k videos stored in hundreds of albums at my own iCloud Photo Library. It works fast and allows to track and animate changes of albums and assets.
Here is nice article to start with Photos framework: https://www.objc.io/issues/21-camera-and-photos/the-photos-framework/

Get timestamp of images in Photo Library using ALAssetLibrary

I am trying to display images from photo library along with time stamp(the time when the were created or modified). I have fetched the images using following code. How can I get their time stamp correctly? here is the code:
-(void)getAllPictures{
imageArray=[[NSArray alloc] init];
mutableArray =[[NSMutableArray alloc]init];
NSMutableArray* assetURLDictionaries = [[NSMutableArray alloc] init];
library = [[ALAssetsLibrary alloc] init];
void (^assetEnumerator)( ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) {
if(result != nil) {
if([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto]) {
[assetURLDictionaries addObject:[result valueForProperty:ALAssetPropertyURLs]];
NSURL *url= (NSURL*) [[result defaultRepresentation]url];
[library assetForURL:url
resultBlock:^(ALAsset *asset) {
[mutableArray addObject:[UIImage imageWithCGImage:[[asset defaultRepresentation] fullScreenImage]]];
if ([mutableArray count]==count)
{
imageArray=[[NSArray alloc] initWithArray:mutableArray];
[self allPhotosCollected:imageArray];
}
}
failureBlock:^(NSError *error){ NSLog(#"operation was not successfull!"); } ];
NSLog(#"ali: %#",result);
}
}
};
NSMutableArray *assetGroups = [[NSMutableArray alloc] init];
void (^ assetGroupEnumerator) ( ALAssetsGroup *, BOOL *)= ^(ALAssetsGroup *group, BOOL *stop) {
if(group != nil) {
[group enumerateAssetsUsingBlock:assetEnumerator];
[assetGroups addObject:group];
count=[group numberOfAssets];
}
};
assetGroups = [[NSMutableArray alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupAll
usingBlock:assetGroupEnumerator
failureBlock:^(NSError *error) {NSLog(#"There is an error");}];}
-(void)allPhotosCollected:(NSArray*)imgArray{
//write your code here after getting all the photos from library...
NSLog(#"all pictures are %#",imgArray);
for (int i=0; i<imgArray.count; i++) {
UIImageView *img=[[UIImageView alloc] initWithImage:imgArray[i]];
img.frame=CGRectMake(10, 20+105*i, 200, 100);
[self.view addSubview:img];
}
}
To get Time Stamp Use This:
NSDate *date = [asset valueForProperty:ALAssetPropertyDate];

How to retrieve all the photos and videos in an array from Photos library?

In my code I have tried to fetch all the photos from the photo library and store them in an array.
I want to fetch even the videos also and store them in the same array.
Please tell me how to modify this code for the above requirement.
I have been struggling for this since months as I am a newbie.
-(IBAction)getAllPictures: (id) sender
{
imageArray=[[NSArray alloc] init];
mutableArray =[[NSMutableArray alloc]init];
NSMutableArray* assetURLDictionaries = [[NSMutableArray alloc] init];
library = [[ALAssetsLibrary alloc] init];
void (^assetEnumerator)( ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop)
{
if(result != nil)
{
if([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto])
{
if([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypeVideo])
{
if([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypeUnknown])
{
[assetURLDictionaries addObject:[result valueForProperty:ALAssetPropertyURLs]];
NSURL *url= (NSURL*) [[result defaultRepresentation]url];
[library assetForURL:url
resultBlock:^(ALAsset *asset)
{
[mutableArray addObject:[UIImage imageWithCGImage:[[asset defaultRepresentation] fullScreenImage]]];
if ([mutableArray count]==count)
{
imageArray=[[NSArray alloc] initWithArray:mutableArray];
[self allPhotosCollected:imageArray];
}
}
failureBlock:^(NSError *error){ NSLog(#"operation was not successfull!");
} ];
}
}
}
}
};
NSMutableArray *assetGroups = [[NSMutableArray alloc] init];
void (^ assetGroupEnumerator) ( ALAssetsGroup *, BOOL *)= ^(ALAssetsGroup *group, BOOL *stop)
{
if(group != nil)
{
[group enumerateAssetsUsingBlock:assetEnumerator];
[assetGroups addObject:group];
count=[group numberOfAssets];
}
};
assetGroups = [[NSMutableArray alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupAll
usingBlock:assetGroupEnumerator
failureBlock:^(NSError *error)
{
NSLog(#"There is an error");
}];
}
-(void)allPhotosCollected:(NSArray*)imgArray
{
//write your code here after getting all the photos from library...
NSLog(#"all pictures are %#",imgArray);
}
You have to use assetLibraries Try this code :-
My code for fetching all the photos from the photo library
- (void)viewDidLoad
{
carousel.type = iCarouselTypeCoverFlow2;
[super viewDidLoad];
xy =[[NSMutableArray alloc]init];
NSMutableArray* assetURLDictionaries = [[NSMutableArray alloc] init];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
void (^assetEnumerator)( ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) {
if(result != nil) {
if([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto]) {
[assetURLDictionaries addObject:[result valueForProperty:ALAssetPropertyURLs]];
NSLog(#"result is:%#",result);
NSLog(#"asset URLDictionary is:%#",assetURLDictionaries);
NSURL *url= (NSURL*) [[result defaultRepresentation]url];
[library assetForURL:url
resultBlock:^(ALAsset *asset) {
[xy addObject:[UIImage imageWithCGImage:[[asset defaultRepresentation] fullScreenImage]]];
NSLog(#" xy is:%#",xy);
image =[ [UIImageView alloc ] initWithImage:[xy objectAtIndex:0]];
NSLog(#"image is:%#",image);
}
failureBlock:^(NSError *error){ NSLog(#"test:Fail"); } ];
}
}
};
NSMutableArray *assetGroups = [[NSMutableArray alloc] init];
void (^ assetGroupEnumerator) ( ALAssetsGroup *, BOOL *)= ^(ALAssetsGroup *group, BOOL *stop) {
NSLog(#"hello");
if(group != nil) {
[group enumerateAssetsUsingBlock:assetEnumerator];
[assetGroups addObject:group];
NSLog(#"Number of assets in group :%d",[group numberOfAssets]);
NSLog(#"asset group is:%#",assetGroups);
}
};
assetGroups = [[NSMutableArray alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupAll
usingBlock:assetGroupEnumerator
failureBlock:^(NSError *error) {NSLog(#"A problem occurred");}];
}
My code for fetching all the videos from the library
- (void)updateAssetsLibrary
{
loadImgView.hidden = NO;
[spinner startAnimating];
//selectVideoBtn .userInteractionEnabled = NO;
assetItems = [NSMutableArray arrayWithCapacity:0];
ALAssetsLibrary *assetLibrary = assetsLibrary;
[assetLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop)
{
if (group)
{
[group setAssetsFilter:[ALAssetsFilter allVideos]];
[group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop)
{
if (asset)
{
dic = [[NSMutableDictionary alloc] init];
ALAssetRepresentation *defaultRepresentation = [asset defaultRepresentation];
NSString *uti = [defaultRepresentation UTI];
appDelegate.videoURL = [[asset valueForProperty:ALAssetPropertyURLs] valueForKey:uti];
mpVideoPlayer = [[MPMoviePlayerController alloc] initWithContentURL:appDelegate.videoURL];
NSString *title = [NSString stringWithFormat:#"%# %i", NSLocalizedString(#"Video", nil), [assetItems count]+1];
[self performSelector:#selector(imageFromVideoURL)];
[dic setValue:title forKey:kName];
[dic setValue:appDelegate.videoURL forKey:kURL];
AssetBrowserItem *item = [[AssetBrowserItem alloc] initWithURL:appDelegate.videoURL title:title];
[assetItems addObject:item];
[appDelegate.videoURLArray addObject:dic];
NSLog(#"Video has info:%#",appDelegate.videoURLArray);
}
NSLog(#"Values of dictionary==>%#", dic);
//NSLog(#"assetItems:%#",assetItems);
NSLog(#"Videos Are:%#",appDelegate.videoURLArray);
} ];
}
// group == nil signals we are done iterating.
else
{
dispatch_async(dispatch_get_main_queue(), ^{
//[self updateBrowserItemsAndSignalDelegate:assetItems];
loadImgView.hidden = NO;
[spinner stopAnimating];
[loadImgView removeFromSuperview];
//selectVideoBtn .userInteractionEnabled = YES;
});
}
}
failureBlock:^(NSError *error)
{
NSLog(#"error enumerating AssetLibrary groups %#\n", error);
}];
}
- (UIImage *)imageFromVideoURL
{
// result
UIImage *image = nil;
// AVAssetImageGenerator
AVAsset *asset = [[AVURLAsset alloc] initWithURL:appDelegate.videoURL options:nil];;
AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
imageGenerator.appliesPreferredTrackTransform = YES;
// calc midpoint time of video
Float64 durationSeconds = CMTimeGetSeconds([asset duration]);
CMTime midpoint = CMTimeMakeWithSeconds(durationSeconds/2.0, 600);
// get the image from
NSError *error = nil;
CMTime actualTime;
CGImageRef halfWayImage = [imageGenerator copyCGImageAtTime:midpoint actualTime:&actualTime error:&error];
if (halfWayImage != NULL)
{
// CGImage to UIImage
image = [[UIImage alloc] initWithCGImage:halfWayImage];
[dic setValue:image forKey:kImage];
NSLog(#"Values of dictionary==>%#", dic);
NSLog(#"Videos Are:%#",appDelegate.videoURLArray);
CGImageRelease(halfWayImage);
}
return image;
}
- (void)assetsLibraryDidChange:(NSNotification*)changeNotification
{
[self updateAssetsLibrary];
}
- (void)buildAssetsLibrary
{
assetsLibrary = [[ALAssetsLibrary alloc] init];
ALAssetsLibrary *notificationSender = nil;
NSString *minimumSystemVersion = #"4.1";
NSString *systemVersion = [[UIDevice currentDevice] systemVersion];
if ([systemVersion compare:minimumSystemVersion options:NSNumericSearch] != NSOrderedAscending)
notificationSender = assetsLibrary;
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(assetsLibraryDidChange:) name:ALAssetsLibraryChangedNotification object:notificationSender];
[self updateAssetsLibrary];
}
This code will give u list of videos of your iPhone.
It may help you :)
For Future Reference Use this:-
Try this answer very simple and easy to understand
-(void)getFromGallery:(BOOL )IsImages
{
if(self.csCollectionsArray != nil)
[self.csCollectionsArray removeAllObjects];
__block NSMutableDictionary *date = [[NSMutableDictionary alloc] init];
ALAssetsLibrary *csAssetsLibrary = [[ALAssetsLibrary alloc] init];
NSUInteger groupTypes = ALAssetsGroupAlbum | ALAssetsGroupEvent | ALAssetsGroupFaces | ALAssetsGroupSavedPhotos;
[csAssetsLibrary enumerateGroupsWithTypes:groupTypes usingBlock:^(ALAssetsGroup *group, BOOL *stop)
{
if([group numberOfAssets] > 0)
{
if(IsImages)
[group setAssetsFilter:[ALAssetsFilter allPhotos]];
else
[group setAssetsFilter:[ALAssetsFilter allVideos]];
[group enumerateAssetsWithOptions:NSEnumerationReverse usingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop)
{
if(asset)
{ //1.fetching all assets from device library
//2.Add all fetched assests from library
[date setObject:asset forKey:[asset valueForProperty:ALAssetPropertyDate]];
}
}];
}
else
{ NSLog(#"---> load table -------->");
if(date != nil && date.count > 0)
{ //3.Sort using date by ascending order and moved to dictionary to array
NSArray *sortedKeys = [[date allKeys] sortedArrayUsingSelector: #selector(compare:)];
for (NSString *key in sortedKeys)
[self.csCollectionsArray addObject: [date objectForKey:key]];
//4.Load images into collection view after fetching all datas
[self reloadCollectionView];
if(self.csCollectionView != nil)
[self.csCollectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:([self.csCollectionsArray count] - 1) inSection:0] atScrollPosition:UICollectionViewScrollPositionBottom animated:YES];
}
date = nil;
}
}failureBlock:^(NSError *error)
{
if((csCollectionsArray == nil || [csCollectionsArray count] == 0))
{
ALAuthorizationStatus status = [ALAssetsLibrary authorizationStatus]; if(status != ALAuthorizationStatusAuthorized)
{
[self showAlertAndCloseUploaderView:#"You can just go to \"Settings\" app (General -> Reset -> Reset Location & Privacy) then come again and click ok when the alert dialog is showing for enable the permission to access the photo library"];
}
}
}];
}

How do i get only the videos using ALAssetsLibrary

I am trying to get videos present from the photo library from the following piece of code.But i also get images list.How do i get list of all videos? what am i doing wrong?
NSMutableArray* assetURLDictionaries = [[NSMutableArray alloc] init];
xy =[[NSMutableArray alloc]init];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
void (^assetEnumerator)( ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) {
if(result != nil) {
if([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypeVideo]) {
[assetURLDictionaries addObject:[result valueForProperty:ALAssetPropertyURLs]];
NSLog(#"result is:%#",result);
NSLog(#"asset URLDictionary is:%#",assetURLDictionaries);
NSURL *url= (NSURL*) [[result defaultRepresentation]url];
[library assetForURL:url
resultBlock:^(ALAsset *asset) {
[xy addObject:[UIImage imageWithCGImage:[[asset defaultRepresentation] fullScreenImage]]];
NSLog(#" xy is:%#",xy);
image =[ [UIImageView alloc ] initWithImage:[xy objectAtIndex:0]];
NSLog(#"image is:%#",image);
}
failureBlock:^(NSError *error){ NSLog(#"test:Fail"); } ];
}
}
};
NSMutableArray *assetGroups = [[NSMutableArray alloc] init];
void (^ assetGroupEnumerator) ( ALAssetsGroup *, BOOL *)= ^(ALAssetsGroup *group, BOOL *stop) {
NSLog(#"hello");
if(group != nil) {
[group enumerateAssetsUsingBlock:assetEnumerator];
[assetGroups addObject:group];
NSLog(#"Number of assets in group :%d",[group numberOfAssets]);
NSLog(#"asset group is:%#",assetGroups);
}
};
assetGroups = [[NSMutableArray alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupAll
usingBlock:assetGroupEnumerator
failureBlock:^(NSError *error) {NSLog(#"A problem occurred");}];
You need to add an ALAssetsFilter to the group during enumeration. Here's a basic example:
ALAssetsLibrary* library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
if (group) {
[group setAssetsFilter:[ALAssetsFilter allVideos]];
[group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop){
if (asset){
NSDictionary *meta = [[asset defaultRepresentation] metadata];
}
}];
}
} failureBlock:^(NSError *error) {
NSLog(#"error enumerating AssetLibrary groups %#\n", error);
}];
For future reference, the available filters are:
- allPhotos
- allVideos
- allAssets

Resources