Esempio n. 1
0
        IDbItem GetExifFor(string file)
        {
            try
            {
                string ext = System.IO.Path.GetExtension(file).ToLower();
                if (!_extensions.Contains(ext))
                {
                    return(null);
                }

                using (ExifMetaInfo exif = new ExifMetaInfo(file))
                {
                    FileInfo info    = new FileInfo(file);
                    IDbItem  picture = _pictureDatabase.CreateNew();;
                    picture["contentURI"] = file;
                    picture["CoverArt"]   = file;
                    picture["title"]      = Path.GetFileNameWithoutExtension(file);
                    picture["Date"]       = info.CreationTime;
                    picture["path"]       = Path.GetDirectoryName(file);

                    picture["EquipmentMake"] = exif.EquipMake;
                    picture["CameraModel"]   = exif.EquipModel;
                    picture["title"]         = Path.GetFileNameWithoutExtension(file);

                    if (exif.DTOrig != DateTime.MinValue)
                    {
                        picture["Date"] = exif.DTOrig;
                    }
                    else
                    {
                        picture["Date"] = info.CreationTime;
                    }

                    picture["ExposureCompensation"] = ((double)exif.ExposureBias).ToString();
                    picture["ExposureTime"]         = exif.ExposureTime.ToString() + "s";
                    picture["Flash"]         = exif.FlashMode;
                    picture["Fstop"]         = "F" + ((double)exif.FNumber).ToString();
                    picture["ImgDimensions"] = string.Format("{0}x{1}", exif.PixXDim, exif.PixYDim);
                    picture["ISOSpeed"]      = exif.ISOSpeed;
                    picture["Orientation"]   = exif.Orientation;
                    picture["MeteringMod"]   = exif.MeteringMode.ToString();

                    //picture["Resolutions"] = tag.Resolutions;
                    picture["ShutterSpeed"] = exif.ExposureTime.ToString() + "s";
                    picture["ViewComment"]  = exif.ImageDescription;
                    picture["path"]         = Path.GetDirectoryName(file);
                    picture["dateAdded"]    = info.CreationTime;
                    return(picture);
                }
            }
            catch (Exception)
            {
            }
            return(null);
        }
Esempio n. 2
0
        public bool FileImport(string filePath)
        {
            try
            {
                if (String.IsNullOrEmpty(filePath))
                {
                    return(false);
                }
                if (filePath.ToLower().IndexOf("folder.jpg") >= 0)
                {
                    return(false);
                }
                string fName = System.IO.Path.GetFileName(filePath);
                if (fName.ToLower().StartsWith("albumart"))
                {
                    return(false);
                }
                string ext = System.IO.Path.GetExtension(filePath).ToLower();
                if (!_extensions.Contains(ext))
                {
                    return(false);
                }
                try
                {
                    Query           imageByFilename = new Query("contentURI", Operator.Same, filePath);
                    IList <IDbItem> result          = _pictureDatabase.Query(imageByFilename);
                    if (result.Count > 0)
                    {
                        return(false);
                    }
                }
                catch (Exception)
                {
                    return(false);
                }
                IDbItem picture = GetExifFor(filePath);
                if (picture == null)
                {
                    return(false);
                }

                picture.Save();
                return(true);
            }
            catch (Exception ex)
            {
                ServiceScope.Get <ILogger>().Info("pictureimporter:error ImportFile:{0}", filePath);
                ServiceScope.Get <ILogger>().Error(ex);
                return(false);
            }
        }
Esempio n. 3
0
 private static IEnumerable <IContentDelayed> KrijgContentDelayed(IDbItem vanItem, DbSetSettings metSettings)
 {
     if (metSettings.ItemsHaveSubContent)
     {
         return(vanItem.Content.TryAccessSubs()
                .Select(s => new ContentDelayed(s.Name.Name, s.Content))
                .ToList());
     }
     if (metSettings.ItemIsSubContent)
     {
         var content = KrijgDirecteContent(vanItem.Content, null);
         if (content.InhoudType == InhoudType.Tekst)
         {
             return(SplitFile(content.Inhoud)
                    .Select(s => new ContentDirect(s))
                    .ToList());
         }
     }
     return(new List <IContentDelayed>());
 }
 private static IEnumerable<IContentDelayed> KrijgContentDelayed(IDbItem vanItem, FileEngineSetSettings metSettings)
 {
     if (metSettings.ItemsHaveSubContent)
         return vanItem.Content.TryAccessSubs()
             .Select(s => new ContentDelayed(s.Name, s.Content))
             .ToList();
     if (metSettings.ItemIsSubContent) {
         var content = KrijgDirecteContent(vanItem.Content, null);
         if (content.InhoudType == InhoudType.Tekst)
             return SplitFile(content.Inhoud)
                 .Select(s => new ContentDirect(s))
                 .ToList();
     }
     return new List<IContentDelayed>();
 }
Esempio n. 5
0
        public void GetMetaDataFor(string folder, ref IList <IAbstractMediaItem> items)
        {
            try
            {
                Query           imagesByPath = new Query("path", Operator.Same, folder);
                IList <IDbItem> results      = _pictureDatabase.Query(imagesByPath);
                foreach (IAbstractMediaItem item in items)
                {
                    if (item.ContentUri == null)
                    {
                        continue;
                    }
                    if (item.ContentUri.IsFile == false)
                    {
                        continue;
                    }
                    if (item.ContentUri.LocalPath.ToLower().IndexOf("folder.jpg") >= 0)
                    {
                        continue;
                    }
                    string fName = Path.GetFileName(item.ContentUri.LocalPath);
                    if (fName.ToLower().StartsWith("albumart"))
                    {
                        continue;
                    }
                    //string ext = Path.GetExtension(item.ContentUri.LocalPath).ToLower();
                    //if (Extensions.Contains(ext))
                    //{
                    bool       found     = false;
                    IMediaItem mediaItem = item as IMediaItem;
                    if (mediaItem != null)
                    {
                        foreach (IDbItem dbItem in results)
                        {
                            string contentUri = dbItem.Attributes["contentURI"].Value.ToString();

                            if (mediaItem.ContentUri != null && mediaItem.ContentUri.IsFile && mediaItem.ContentUri.LocalPath == contentUri)
                            {
                                found = true;
                                IEnumerator <KeyValuePair <string, IDbAttribute> > enumer = dbItem.Attributes.GetEnumerator();
                                while (enumer.MoveNext())
                                {
                                    mediaItem.MetaData[enumer.Current.Key] = enumer.Current.Value.Value;
                                }
                                mediaItem.Title = dbItem.Attributes["title"].Value as string;
                                break;
                            }
                        }
                        if (!found)
                        {
                            IDbItem dbItem = GetExifFor(mediaItem.ContentUri.LocalPath);
                            if (dbItem != null)
                            {
                                IEnumerator <KeyValuePair <string, IDbAttribute> > enumer = dbItem.Attributes.GetEnumerator();
                                while (enumer.MoveNext())
                                {
                                    mediaItem.MetaData[enumer.Current.Key] = enumer.Current.Value.Value;
                                }
                                mediaItem.Title = dbItem.Attributes["title"].Value as string;
                            }
                        }
                    }
                    //}
                }
            }
            catch (Exception)
            {
            }
        }
Esempio n. 6
0
 public void FileRenamed(string filePath, string oldFilePath)
 {
     try
     {
         // The rename may have been on a directory or a file
         FileInfo fi = new FileInfo(filePath);
         if (fi.Exists)
         {
             IList <IDbItem> result;
             try
             {
                 Query imageByFilename = new Query("contenturi", Operator.Same, oldFilePath);
                 result = _pictureDatabase.Query(imageByFilename);
                 if (result.Count > 0)
                 {
                     IDbItem picture = result[0];
                     picture["contenturi"] = filePath;
                     picture.Save();
                 }
             }
             catch (Exception)
             {
                 return;
             }
         }
         else
         {
             // Must be a directory, so let's change the path entries, containing the old
             // name with the new name
             DirectoryInfo di = new DirectoryInfo(filePath);
             if (di.Exists)
             {
                 IList <IDbItem> result;
                 try
                 {
                     Query imageByFilename = new Query("contenturi", Operator.Like, String.Format("{0}%", oldFilePath));
                     result = _pictureDatabase.Query(imageByFilename);
                     if (result.Count > 0)
                     {
                         // We might have changed a Top directory, so we get a lot of path entries returned
                         for (int i = 0; i < result.Count; i++)
                         {
                             IDbItem picture = result[i];
                             string  strPath = picture["contenturi"].ToString().Replace(oldFilePath, filePath);
                             picture["contenturi"] = strPath;
                             picture.Save();
                         }
                     }
                 }
                 catch (Exception)
                 {
                     return;
                 }
             }
         }
     }
     catch (Exception ex)
     {
         ServiceScope.Get <ILogger>().Info("pictureimporter:error FileRenamed:{0}", filePath);
         ServiceScope.Get <ILogger>().Error(ex);
     }
 }