private void RefreshPhotos(string revquery) { foreach (Album pl in albums) { //Console.WriteLine ("Refreshing photos in album " + pl.Name); byte [] photos_data = client.Fetcher.Fetch(String.Format("/databases/{0}/containers/{1}/items", id, pl.getId()), photo_query); ContentNode photos_node = ContentParser.Parse(client.Bag, photos_data); //photos_node.Dump (); //if (IsUpdateResponse (photos_node)) // return; // handle photo additions/changes foreach (ContentNode photoNode in (ContentNode [])photos_node.GetChild("dmap.listing").Value) { // DEBUG data //photoNode.Dump (); Photo photo = Photo.FromNode(photoNode); Photo existing = LookupPhotoById(photo.Id); pl.AddPhoto(photo); if (existing == null) { Console.WriteLine("adding " + photo.Title + " to album " + pl.Name); AddPhoto(photo); } else { Console.WriteLine("updating " + existing.Title); existing.Update(photo); } } if ((byte)photos_node.GetChild("dmap.updatetype").Value == 1) { // handle photo deletions ContentNode delete_list = photos_node.GetChild("dmap.deletedidlisting"); if (delete_list != null) { foreach (ContentNode deleted in (ContentNode [])delete_list.Value) { Photo photo = LookupPhotoById((int)deleted.Value); if (photo != null) { RemovePhoto(photo); } } } } } }
public void DownloadPhoto(Photo photo, string dest) { /* BinaryWriter writer = new BinaryWriter (File.Open (dest, FileMode.Create)); * MemoryStream data = new MemoryStream (); * try { * long len; * using (BinaryReader reader = new BinaryReader (StreamPhoto (photo, out len))) { * int count = 0; * byte [] buf = new byte [chunk_length]; * * // Skip the header * //count = reader.Read (buf,0,89); * * //if (count < 89) * // count+=reader.Read (buf,0,89-count); * * while (true) { * buf = reader.ReadBytes (8192); * if (buf.Length == 0) * break; * * data.Write (buf, 0, buf.Length); * //Console.Write (buf.); * } * */ /* do { * count = reader.Read (buf, 0, chunk_length); * writer.Write (buf, 0, count); * data.Write (buf, 0, count); * } while (count != 0); */ /*data.Flush (); * * ContentNode node = ContentParser.Parse (client.Bag, data.GetBuffer ()); * node.Dump (); * reader.Close (); * * } * } finally { * data.Close (); * * writer.Close (); * }*/ // maybe use FetchResponse to get a stream and feed it to pixbuf? byte [] photos_data = client.Fetcher.Fetch(String.Format("/databases/{0}/items", id), String.Format("meta=dpap.thumb,dpap.filedata&query=('dmap.itemid:{0}')", photo.Id)); ContentNode node = ContentParser.Parse(client.Bag, photos_data); // DEBUG Console.WriteLine("About to dump the photo!"); node.Dump(); ContentNode filedata_node = node.GetChild("dpap.filedata"); Console.WriteLine("Photo starts at index " + filedata_node.Value); BinaryWriter writer = new BinaryWriter(File.Open(dest, FileMode.Create)); int count = 0; int off = System.Int32.Parse(filedata_node.Value.ToString()); byte [] photo_buf; MemoryStream data = new MemoryStream(); writer.Write(photos_data, (int)off, (int)photos_data.Length - off); data.Position = 0; // Gdk.Pixbuf pb = new Gdk.Pixbuf (data); data.Close(); Console.Write("Written " + count + " out of " + (photos_data.Length - off)); }
public static ContentCodeBag ParseCodes(byte [] buffer) { ContentCodeBag bag = new ContentCodeBag(); // add some codes to bootstrap us bag.AddCode("mccr", "dmap.contentcodesresponse", ContentType.Container); bag.AddCode("mdcl", "dmap.dictionary", ContentType.Container); bag.AddCode("mcnm", "dmap.contentcodesnumber", ContentType.Long); bag.AddCode("mcna", "dmap.contentcodesname", ContentType.String); bag.AddCode("mcty", "dmap.contentcodestype", ContentType.Short); bag.AddCode("mstt", "dmap.status", ContentType.Long); // some photo-specific codes // shouldn't be needed now bag.AddCode("ppro", "dpap.protocolversion", ContentType.Long); bag.AddCode("pret", "dpap.blah", ContentType.Container); bag.AddCode("avdb", "dpap.serverdatabases", ContentType.Container); bag.AddCode("aply", "dpap.databasecontainers", ContentType.Container); bag.AddCode("abpl", "dpap.baseplaylist", ContentType.Char); bag.AddCode("apso", "dpap.playlistsongs", ContentType.Container); bag.AddCode("pasp", "dpap.aspectratio", ContentType.String); bag.AddCode("adbs", "dpap.databasesongs", ContentType.Container); bag.AddCode("picd", "dpap.creationdate", ContentType.Long); bag.AddCode("pifs", "dpap.imagefilesize", ContentType.Long); bag.AddCode("pwth", "dpap.imagepixelwidth", ContentType.Long); bag.AddCode("phgt", "dpap.imagepixelheight", ContentType.Long); bag.AddCode("pcmt", "dpap.imagecomments", ContentType.String); bag.AddCode("prat", "dpap.imagerating", ContentType.Long); bag.AddCode("pimf", "dpap.imagefilename", ContentType.String); bag.AddCode("pfmt", "dpap.imageformat", ContentType.String); bag.AddCode("plsz", "dpap.imagelargefilesize", ContentType.Long); bag.AddCode("pfdt", "dpap.filedata", ContentType.FileData); ContentNode node = ContentParser.Parse(bag, buffer); foreach (ContentNode dictNode in (node.Value as ContentNode [])) { if (dictNode.Name != "dmap.dictionary") { continue; } ContentCode code = new ContentCode(); foreach (ContentNode item in (dictNode.Value as ContentNode [])) { switch (item.Name) { case "dmap.contentcodesnumber": code.Number = (int)item.Value; break; case "dmap.contentcodesname": code.Name = (string)item.Value; break; case "dmap.contentcodestype": code.Type = (ContentType)Enum.ToObject(typeof(ContentType), (short)item.Value); break; } } bag.codes [code.Number] = code; } return(bag); }
private void RefreshAlbums(string revquery) { byte [] albums_data; try { albums_data = client.Fetcher.Fetch(String.Format("/databases/{0}/containers", id), "meta=dpap.aspectratio,dmap.itemid,dmap.itemname,dpap.imagefilename,dpap.imagefilesize,dpap.creationdate,dpap.imagepixelwidth,dpap.imagepixelheight,dpap.imageformat,dpap.imagerating,dpap.imagecomments,dpap.imagelargefilesize&type=photo"); } catch (WebException) { return; } ContentNode albums_node = ContentParser.Parse(client.Bag, albums_data); // DEBUG data albums_node.Dump(); Console.WriteLine("after dump!"); if (IsUpdateResponse(albums_node)) { return; } // handle album additions/changes ArrayList plids = new ArrayList(); if (albums_node.GetChild("dmap.listing") == null) { return; } foreach (ContentNode albumNode in (ContentNode [])albums_node.GetChild("dmap.listing").Value) { // DEBUG Console.WriteLine("foreach loop"); Album pl = Album.FromNode(albumNode); if (pl != null) { plids.Add(pl.Id); Album existing = LookupAlbumById(pl.Id); if (existing == null) { AddAlbum(pl); } else { existing.Update(pl); } } } // DEBUG Console.WriteLine("delete albums that don't exist"); // delete albums that no longer exist foreach (Album pl in new List <Album> (albums)) { if (!plids.Contains(pl.Id)) { RemoveAlbum(pl); } } plids = null; // DEBUG Console.WriteLine("Add/remove photos in the albums"); // add/remove photos in the albums foreach (Album pl in albums) { byte [] album_photos_data = client.Fetcher.Fetch(String.Format("/databases/{0}/containers/{1}/items", id, pl.Id), "meta=dpap.aspectratio,dmap.itemid,dmap.itemname,dpap.imagefilename,dpap.imagefilesize,dpap.creationdate,dpap.imagepixelwidth,dpap.imagepixelheight,dpap.imageformat,dpap.imagerating,dpap.imagecomments,dpap.imagelargefilesize&type=photo"); ContentNode album_photos_node = ContentParser.Parse(client.Bag, album_photos_data); if (IsUpdateResponse(album_photos_node)) { return; } if ((byte)album_photos_node.GetChild("dmap.updatetype").Value == 1) { // handle album photo deletions ContentNode delete_list = album_photos_node.GetChild("dmap.deletedidlisting"); if (delete_list != null) { foreach (ContentNode deleted in (ContentNode [])delete_list.Value) { int index = pl.LookupIndexByContainerId((int)deleted.Value); if (index < 0) { continue; } pl.RemoveAt(index); } } } // add new photos, or reorder existing ones int plindex = 0; foreach (ContentNode pl_photo_node in (ContentNode [])album_photos_node.GetChild("dmap.listing").Value) { Photo plphoto = null; int container_id = 0; Photo.FromAlbumNode(this, pl_photo_node, out plphoto, out container_id); if (pl [plindex] != null && pl.GetContainerId(plindex) != container_id) { pl.RemoveAt(plindex); pl.InsertPhoto(plindex, plphoto, container_id); } else if (pl [plindex] == null) { pl.InsertPhoto(plindex, plphoto, container_id); } plindex++; } } }
private int GetCurrentRevision() { ContentNode rev_node = ContentParser.Parse(bag, fetcher.Fetch("/update"), "dmap.serverrevision"); return((int)rev_node.Value); }