public void WidthTest()
 {
     PicasaEntry entry = new PhotoEntry();
     PhotoAccessor target = new PhotoAccessor(entry); 
     int expected = 5; // TODO: Initialize to an appropriate value
     int actual;
     target.Width = expected;
     actual = target.Width;
     Assert.AreEqual(expected, actual);
 }
 public PicasaWebPhoto(PicasaEntry photo, string albumName)
 {
     PhotoAccessor pa = new PhotoAccessor(photo);
     this.m_accessId = pa.Id;
     this.m_media = photo.Media;
     this.m_id = photo.Id.Uri.ToString();
     this.m_title = photo.Title.Text;
     this.m_albumName = albumName;
     this.m_height = pa.Height;
     this.m_width = pa.Width;
     this.m_uploaded = photo.Updated.ToShortDateString() + " " + photo.Updated.ToShortTimeString();
     this.m_location = (string)photo.Media.Content.Attributes["url"];
     pa = null;
 }
예제 #3
0
        /////////////////////////////////////////////////////////////////////////////

        //////////////////////////////////////////////////////////////////////
        /// <summary>runs an authentication test, iterates all entries</summary> 
        //////////////////////////////////////////////////////////////////////
        [Test] public void QueryPhotosTest()
        {
            Tracing.TraceMsg("Entering PhotosQueryPhotosTest");

            PhotoQuery query = new PhotoQuery();
            PicasaService service = new PicasaService("unittests");
           
            if (this.defaultPhotosUri != null)
            {
                if (this.userName != null)
                {
                    service.Credentials = new GDataCredentials(this.userName, this.passWord);
                }

                GDataLoggingRequestFactory factory = (GDataLoggingRequestFactory) this.factory;
                factory.MethodOverride = true;
                service.RequestFactory = this.factory; 

                query.Uri = new Uri(this.defaultPhotosUri);
                PicasaFeed feed = service.Query(query);

                ObjectModelHelper.DumpAtomObject(feed,CreateDumpFileName("PhotoAuthTest")); 
     
                if (feed != null && feed.Entries.Count > 0)
                {
                    Tracing.TraceMsg("Found a Feed " + feed.ToString());
                    DisplayExtensions(feed);

                    foreach (PicasaEntry entry in feed.Entries)
                    {
                        Tracing.TraceMsg("Found an entry " + entry.ToString());
                        DisplayExtensions(entry);

                        GeoRssWhere w = entry.Location;
                        if (w != null)
                        {
                            Tracing.TraceMsg("Found an location " + w.Latitude + w.Longitude);
                        }

                        ExifTags tags = entry.Exif;
                        if (tags != null)
                        {
                            Tracing.TraceMsg("Found an exif block ");
                        }

                        MediaGroup group = entry.Media;
                        if (group != null)
                        {
                            Tracing.TraceMsg("Found a media Group");
                            if (group.Title != null)
                            {
                                Tracing.TraceMsg(group.Title.Value);
                            }
                            if (group.Keywords != null)
                            {
                                Tracing.TraceMsg(group.Keywords.Value);
                            }
                            if (group.Credit != null)
                            {
                                Tracing.TraceMsg(group.Credit.Value);
                            }
                            if (group.Description != null)
                            {
                                Tracing.TraceMsg(group.Description.Value);
                            }
                        }


                        PhotoAccessor photo = new PhotoAccessor(entry);

                        Assert.IsTrue(entry.IsPhoto, "this is a photo entry, it should have the kind set");
                        Assert.IsTrue(photo != null, "this is a photo entry, it should convert to PhotoEntry");

                        Assert.IsTrue(photo.AlbumId != null);
                        Assert.IsTrue(photo.Height > 0);
                        Assert.IsTrue(photo.Width > 0);
                    }
                }

                factory.MethodOverride = false;
            }
        }
 public void TimestampTest()
 {
     PicasaEntry entry = new PhotoEntry();
     PhotoAccessor target = new PhotoAccessor(entry);
     ulong expected = 122; // TODO: Initialize to an appropriate value
     ulong actual;
     target.Timestamp = expected;
     actual = target.Timestamp;
     Assert.AreEqual(expected, actual);
 }
 public void VersionTest()
 {
     PicasaEntry entry = new PhotoEntry();
     PhotoAccessor target = new PhotoAccessor(entry);
     string expected = "TestValue"; 
     string actual;
     target.Version = expected;
     actual = target.Version;
     Assert.AreEqual(expected, actual);
 }
 public void CommentCountTest()
 {
     PicasaEntry entry = new PhotoEntry();
     PhotoAccessor target = new PhotoAccessor(entry);
     uint expected = 12; // TODO: Initialize to an appropriate value
     uint actual;
     target.CommentCount = expected;
     actual = target.CommentCount;
     Assert.AreEqual(expected, actual);
 }
 public void CommentingEnabledTest()
 {
     PicasaEntry entry = new PhotoEntry();
     PhotoAccessor target = new PhotoAccessor(entry);
     bool expected = true;
     bool actual;
     target.CommentingEnabled = expected;
     actual = target.CommentingEnabled;
     Assert.AreEqual(expected, actual);
 }
 public void LatitudeTest()
 {
     PicasaEntry entry = new PhotoEntry();
     PhotoAccessor target = new PhotoAccessor(entry);
     double expected = 12.5F; // TODO: Initialize to an appropriate value
     double actual;
     target.Latitude = expected;
     actual = target.Latitude;
     Assert.AreEqual(expected, actual);
 }
 public void SizeTest()
 {
     PicasaEntry entry = new PhotoEntry();
     PhotoAccessor target = new PhotoAccessor(entry);
     long expected = 12; // TODO: Initialize to an appropriate value
     long actual;
     target.Size = expected;
     actual = target.Size;
     Assert.AreEqual(expected, actual);
 }
        public static object GetMinDateKey(PicasaEntry picasaEntry, Dictionary<object, List<object>> driveKeys)
        {
            var photo = new PhotoAccessor(picasaEntry);

            /*
            var value = photo.Timestamp;
            var time = DateTime.FromFileTimeUtc((long)value);
                
            var tmp = new DateTime(1970, 1, 1, 0, 0, 0);
            tmp = tmp.AddMilliseconds(value);
            
            return time;*/

            //Picasa API do not have video metadata.
            //Try to match video by size (size on google drive are the same as on picasa)

            //Make dictionary Size -> Keys from driveKeys
            var sizeToKeys = new Dictionary<string, List<object>>();
            foreach (var pair in driveKeys)
            {
                foreach (object googleObject in pair.Value)
                {
                    var googleFile = (File)googleObject;
                    long size = googleFile.FileSize.HasValue ? googleFile.FileSize.Value : 0;
                    var sizeKey = size.ToString() + "&&" + googleFile.OriginalFilename;
                    if (!sizeToKeys.ContainsKey(sizeKey))
                        sizeToKeys.Add(sizeKey, new List<object>());
                    sizeToKeys[sizeKey].Add(pair.Key);
                }
            }

            //Get key by size
            var photoKey = photo.Size.ToString() + "&&" + photo.PhotoTitle;

            if (sizeToKeys.ContainsKey(photoKey) && sizeToKeys[photoKey].Count == 1)
                return sizeToKeys[photoKey][0];

            return null;

        }
        public static object GetPicasaKeyByDriveKey(PicasaEntry picasaEntry, Dictionary<object, List<object>> driveKeys)
        {
            //Make dictionary Size -> Keys from driveKeys
            var sizeToKeys = new Dictionary<string, List<object>>();
            foreach (var pair in driveKeys)
            {
                foreach (object googleObject in pair.Value)
                {
                    var googleFile = (File)googleObject;
                    long size = googleFile.FileSize.HasValue ? googleFile.FileSize.Value : 0;
                    var sizeKey = size.ToString() + "&&" + googleFile.OriginalFilename;
                    if (!sizeToKeys.ContainsKey(sizeKey))
                        sizeToKeys.Add(sizeKey, new List<object>());
                    sizeToKeys[sizeKey].Add(pair.Key);
                }
            }

            //Get key by size
            PhotoAccessor photo = new PhotoAccessor(picasaEntry);
            var photoKey = photo.Size.ToString() + "&&" + photo.PhotoTitle;

            if (sizeToKeys.ContainsKey(photoKey) && sizeToKeys[photoKey].Count == 1)
                return sizeToKeys[photoKey][0];
            return null;
        }
예제 #12
0
        public static PicasaInfo RetrievePicasaInfo(PicasaEntry picasaEntry)
        {
            PhotoAccessor photoAccessor = new PhotoAccessor(picasaEntry);

            LOG.InfoFormat("Retrieving Picasa info for {0}", photoAccessor.Id);

            PicasaInfo picasaInfo = new PicasaInfo();

            picasaInfo.ID = photoAccessor.Id;
            picasaInfo.Title = picasaEntry.Title.Text;
            picasaInfo.Timestamp = picasaEntry.Updated;
            picasaInfo.Description = picasaEntry.Summary.Text;
            picasaInfo.SquareThumbnailUrl = picasaEntry.Media.Thumbnails[0].Url;
            picasaInfo.OriginalUrl = picasaEntry.Media.Content.Url;

            List<AtomLink> links = picasaEntry.Links.Where(r => r.Type.Equals("text/html", StringComparison.OrdinalIgnoreCase)).ToList();
            picasaInfo.WebUrl = string.Empty;
            if (links.Count > 0)
            {
                picasaInfo.WebUrl = links.First().HRef.ToString();
            }
            return picasaInfo;
        }
 public void MovePhotoToAlbum(PicasaEntry photo, string newAlbumId)
 {
     PhotoAccessor ac = new PhotoAccessor(photo);
     ac.AlbumId = newAlbumId;
     try
     {
         PicasaEntry updatedEntry = (PicasaEntry)photo.Update();
     }
     catch
     {
         var service = GetPicasaService(true);
         photo.Service = service;
         PicasaEntry updatedEntry = (PicasaEntry)photo.Update();
     }
 }
예제 #14
0
        private void button1_Click(object sender, EventArgs e)
        {
            PicasaClient picasa = new PicasaClient();
            var alreadyFoundExt = new HashSet<string>();

            //picasa.Test();

            var foundAlbums = new HashSet<string>();
            var picasaFoundFiles = picasa.GetPhotos(null, ".avi");
            PicasaEntry pe = null;
            foreach (var file in picasaFoundFiles)
            {
                var ph = new PhotoAccessor(file);

                if (ph.PhotoTitle.ToLower()== "2005-12-16Mafia.avi".ToLower())
                {
                    pe = file;
                    var value = ph.Timestamp;
                    var tmp = new DateTime(1970, 1, 1, 0, 0, 0);
                    tmp = tmp.AddMilliseconds(value);

                    break;
                }
            }


            picasa.SetPhotoCreationDate(pe, DateTime.Now);





            MessageBox.Show(pe.Title.ToString());
        }
        private void MoveFile(string fileName, string drivePhotoDirId)
        {
            //Try get picasa file by google file name  
            if (googleFiles.ContainsKey(fileName))
            {
                foreach (var googleFile in googleFiles[fileName])
                {
                    //Add by 
                    var googleFileName = ((File)googleFile).OriginalFilename;
                    lock (picasaFiles)
                    {
                        if (!picasaFiles.ContainsKey(googleFileName))
                        {
                            var foundAlbums = new HashSet<string>();
                            var picasaFoundFiles = picasa.GetPhotos(null, googleFileName);
                            foreach (var file in picasaFoundFiles)
                            {
                                AddPicasaFile(file, picasaFiles, picasaFilesId);
                                var picasaFoto = new PhotoAccessor(file);
                                foundAlbums.Add(picasaFoto.AlbumId);
                            }
                            //Also try to add any files from album of found files
                            foreach (var albumId in foundAlbums)
                                AddPicasaFiles(picasa, picasaFiles, picasaFilesId, albumId);
                        }
                    }
                }
            }

            if (!localFiles.ContainsKey(fileName))
                return;

            List<File> googleFilesSelect;
            if (googleFiles.ContainsKey(fileName))
                googleFilesSelect = googleFiles[fileName];
            else
                googleFilesSelect = new List<File>();

            List<PicasaEntry> picasaFilesSelect;
            if (picasaFiles.ContainsKey(fileName))
                picasaFilesSelect = picasaFiles[fileName];
            else
                picasaFilesSelect = new List<PicasaEntry>();



            //Match file by Data
            var matchedFiles = MediaKeyMatcher.MatchFilesWithTheSameName(localFiles[fileName], googleFilesSelect, picasaFilesSelect);


            foreach (var matched in matchedFiles)
            {
                //No such files on google storage
                if (matched.googleFiles.Count == 0 && matched.picasaFiles.Count == 0)
                    continue;

                //No such file on local storage
                if (matched.localFiles.Count == 0)
                    continue;


                //*****************************************
                //Select local file to get folder structure
                FileDesc localFile;
                if (matched.localFiles.Count > 1)
                {
                    var localFilesSizes = new HashSet<long>();
                    //Get local files size
                    foreach (var file in matched.localFiles)
                        localFilesSizes.Add(MediaKeyMatcher.GetFileSize(file.path));

                    if (localFilesSizes.Count > 1)
                    {
                        //Can't distinguish this files
                        LogText("Different local files with the same name. Skipping tham:");
                        foreach (FileDesc file in matched.localFiles)
                            LogText("   " + file.path);
                        continue;
                    }

                    //Files are really the same
                    //Many folders exists
                    var key = MakePrefDirKey(matched.localFiles);
                    lock (preferableDirs)
                    {
                        if (preferableDirs.ContainsKey(key))
                        {
                            var sel = preferableDirs[key];
                            localFile = null;
                            //Select pref dir
                            if (sel != null)
                            {
                                foreach (var fileDesc in matched.localFiles)
                                {
                                    if (fileDesc.relPath == sel.Item1 && fileDesc.album == sel.Item2)
                                    {
                                        localFile = fileDesc;
                                        break;
                                    }
                                }
                            }

                            if (localFile == null)
                            {
                                LogText("The same files in different folders. Skipping tham:");
                                foreach (FileDesc file in matched.localFiles)
                                    LogText("   " + file.path);
                                continue;
                            }
                        }
                        else
                        {
                            //Ask user for choose
                            DialogResult dialogResult = DialogResult.Cancel;
                            int index = -1;
                            bool chooseAlways = false;
                            var folders = new List<string>();
                            for (int i = 0; i < matched.localFiles.Count; i++)
                                folders.Add(matched.localFiles[i].path);

                            Action act = () =>
                            {
                                dialogResult = FolderSelectorForm.SelectTheFolder(fileName, folders, out index, out chooseAlways);
                            };
                            _progressBar.Invoke(act);
                            if (dialogResult == DialogResult.OK && index >= 0)
                            {
                                localFile = matched.localFiles[index];
                                if (chooseAlways)
                                    preferableDirs.Add(key, new Tuple<string, string>(localFile.relPath, localFile.album));
                            }
                            else
                            {
                                if (chooseAlways)
                                    preferableDirs.Add(key, null);

                                LogText("The same files in different folders. Skipping tham:");
                                foreach (FileDesc file in matched.localFiles)
                                    LogText("   " + file.path);
                                continue;
                            }
                        }
                    }
                }
                else
                {
                    //One file
                    localFile = matched.localFiles[0];
                }
                //*****************************************


                //Move files to picasa album
                if (matched.picasaFiles.Count > 0)
                {
                    AlbumAccessor picasaAlbum;
                    lock (picasaAlbumsByName)
                    {
                        if (picasaAlbumsByName.ContainsKey(localFile.album))
                            picasaAlbum = picasaAlbumsByName[localFile.album];
                        else
                        {
                            picasaAlbum = picasa.CreateAlbum(localFile.album, localFile.relPath);
                            picasaAlbumsByName.Add(localFile.album, picasaAlbum);
                        }
                    }

                    if (matched.picasaFiles.Count > 1)
                    {
                        var photo = new PhotoAccessor(matched.picasaFiles[0]);
                        LogText("Has " + matched.picasaFiles.Count + " dublicates with name '" + photo.PhotoTitle + "' among the Google Photo files. All of them will move to album '" + localFile.album + "'");
                    }

                    foreach (PicasaEntry picasaFile in matched.picasaFiles)
                    {
                        var photo = new PhotoAccessor(picasaFile);
                        if (photo.AlbumId != picasaAlbum.Id) //Not in that album yet
                            picasa.MovePhotoToAlbum(picasaFile, picasaAlbum.Id);
                    }
                }

                //Move files to google dirs
                if (matched.googleFiles.Count != 0)
                {
                    string googleDirId;
                    lock (googleDirs)
                    {
                        if (googleDirs.ContainsKey(localFile.relPath))
                            googleDirId = googleDirs[localFile.relPath];
                        else
                        {
                            googleDirId = drive.CreateCascadeDirectory(localFile.relPath, drivePhotoDirId).Id;
                            googleDirs.Add(localFile.relPath, googleDirId);
                        }
                    }

                    if (matched.googleFiles.Count > 1)
                        LogText("Has " + matched.googleFiles.Count + " dublicates with name '" + matched.googleFiles[0].OriginalFilename + "' among the google files. All of them will move to '" + localFile.relPath + "'");

                    foreach (File googleFile in matched.googleFiles)
                    {
                        bool hasSameParent = false;
                        foreach (var parent in googleFile.Parents)
                        {
                            if (parent.Id == googleDirId)
                            {
                                hasSameParent = true;
                                break;
                            }
                        }
                        if (!hasSameParent) //If not already in this folder
                            drive.MoveFileToDirectory(googleFile.Id, googleDirId);

                        /*
                        if (googleFile.ImageMediaMetadata == null || String.IsNullOrWhiteSpace(googleFile.ImageMediaMetadata.Date))
                        {
                            //No Exif date for file.
                            //Will change google CreationDate if its bigger then fileDate
                            var creationDate = System.IO.File.GetCreationTime(localFile.path);
                            var fi = new System.IO.FileInfo(localFile.path);
                            if (creationDate > fi.LastWriteTime) //Get min among creation and modified date
                                creationDate = fi.LastWriteTime;
                            if (googleFile.CreatedDate > creationDate)
                                drive.SetCreationDate(googleFile.Id, creationDate);
                        }*/

                    }
                }
            }
        }
 void AddPicasaFile(PicasaEntry newFile,
     Dictionary<string, List<PicasaEntry>> picasaFiles, HashSet<string> picasaFilesId)
 {
     var photo = new PhotoAccessor(newFile);
     if (picasaFilesId.Contains(photo.Id))
         return; //This file already in picasa files
     picasaFilesId.Add(photo.Id);
     if (!picasaFiles.ContainsKey(photo.PhotoTitle))
         picasaFiles.Add(photo.PhotoTitle, new List<PicasaEntry>());
     picasaFiles[photo.PhotoTitle].Add(newFile);
 }