public IEnumerable <DiscoveredFile> Discover(string path, HashSet <string> existingSources)
{
string photosetId = path.Replace("/", "");
int page = 1;
int maxPages = 1;
while (page <= maxPages)
{
// existing sources gives us a list of photoset ids
PagedPhotoCollection photos;
try
{
if (photosetId == "")
{
photos = _flickr.PhotosGetNotInSet(page, 100, PhotoSearchExtras.OriginalUrl | PhotoSearchExtras.Media | PhotoSearchExtras.LargeUrl);
}
else
{
photos = _flickr.PhotosetsGetPhotos(photosetId, PhotoSearchExtras.OriginalUrl | PhotoSearchExtras.Media | PhotoSearchExtras.LargeUrl, page, 100);
}
maxPages = photos.Pages;
page++;
}
catch
{
photos = new PhotoCollection();
}
foreach (var photo in photos)
{
if (!existingSources.Contains(path + photo.PhotoId))
{
if (photo.MediaStatus == "failed")
{
continue;
}
string url = photo.OriginalUrl;
if (url == null)
{
url = photo.LargeUrl;
}
if (url == null)
{
url = photo.MediumUrl;
}
string extension = System.IO.Path.GetExtension(url);
if (photo.Media == "video")
{
url = $"http://www.flickr.com/video_download.gne?id={photo.PhotoId}";
try
{
if (!photo.IsPublic)
{
_flickr.PhotosSetPerms(photo.PhotoId, true, photo.IsFriend, photo.IsFamily, PermissionComment.Nobody, PermissionAddMeta.Owner);
}
string fileName = GetHeaderFileName(url);
extension = System.IO.Path.GetExtension(fileName);
if (!photo.IsPublic)
{
_flickr.PhotosSetPerms(photo.PhotoId, photo.IsPublic, photo.IsFriend, photo.IsFamily, PermissionComment.Nobody, PermissionAddMeta.Owner);
}
}
catch (Exception ex)
{
}
}
yield return
(new DiscoveredFile
{
Name = photo.Title,
Path = path + photo.PhotoId,
Extension = extension,
Url = url
});
}
}
}
}