private bool GetExifDetails(string strPicture, ref int iRotation, ref string strDateTaken) { using (ExifMetadata extractor = new ExifMetadata()) { ExifMetadata.Metadata metaData = extractor.GetExifMetadata(strPicture); try { string picExifDate = metaData.DatePictureTaken.DisplayValue; if (!String.IsNullOrEmpty(picExifDate)) // If the image contains a valid exif date store it in the database, otherwise use the file date { DateTime dat; DateTime.TryParseExact(picExifDate, "G", Thread.CurrentThread.CurrentCulture, DateTimeStyles.None, out dat); strDateTaken = dat.ToString("yyyy-MM-dd HH:mm:ss"); if (_useExif) { iRotation = EXIFOrientationToRotation(Convert.ToInt32(metaData.Orientation.Hex)); } return(true); } } catch (FormatException ex) { Log.Error("PictureDatabaseSqlLite: Exif date conversion exception err:{0} stack:{1}", ex.Message, ex.StackTrace); } } return(false); }
private void Update() { if (m_pTexture != null) { m_pTexture.Dispose(); } int iRotate = PictureDatabase.GetRotation(FileName); m_pTexture = Util.Picture.Load(FileName, iRotate, 1024, 1024, true, false, out m_iTextureWidth, out m_iTextureHeight); lblCameraModel.Label = string.Empty; lblDateTakenLabel.Label = string.Empty; lblEquipmentMake.Label = string.Empty; lblExposureCompensation.Label = string.Empty; lblExposureTime.Label = string.Empty; lblFlash.Label = string.Empty; lblFstop.Label = string.Empty; lblImgDimensions.Label = string.Empty; lblImgTitle.Label = string.Empty; lblMeteringMode.Label = string.Empty; lblResolutions.Label = string.Empty; lblShutterSpeed.Label = string.Empty; lblViewComments.Label = string.Empty; using (ExifMetadata extractor = new ExifMetadata()) { ExifMetadata.Metadata metaData = extractor.GetExifMetadata(FileName); lblCameraModel.Label = metaData.CameraModel.DisplayValue; lblDateTakenLabel.Label = metaData.DatePictureTaken.DisplayValue; lblEquipmentMake.Label = metaData.EquipmentMake.DisplayValue; lblExposureCompensation.Label = metaData.ExposureCompensation.DisplayValue; lblExposureTime.Label = metaData.ExposureTime.DisplayValue; lblFlash.Label = metaData.Flash.DisplayValue; lblFstop.Label = metaData.Fstop.DisplayValue; lblImgDimensions.Label = metaData.ImageDimensions.DisplayValue; lblImgTitle.Label = Path.GetFileNameWithoutExtension(FileName); lblMeteringMode.Label = metaData.MeteringMode.DisplayValue; lblResolutions.Label = metaData.Resolution.DisplayValue; lblShutterSpeed.Label = metaData.ShutterSpeed.DisplayValue; lblViewComments.Label = metaData.ViewerComments.DisplayValue; imgPicture.IsVisible = false; } if (File.Exists(FileName)) { GUIPropertyManager.SetProperty("#selectedthumb", FileName); } else { GUIPropertyManager.SetProperty("#selectedthumb", string.Empty); } }
public DateTime GetDateTaken(string strPicture) { string strSQL = ""; try { string strPic = strPicture; DatabaseUtility.RemoveInvalidChars(ref strPic); strSQL = String.Format("select * from tblPicture where strFile like '{0}'", strPic); using (SqlCommand cmd = _connection.CreateCommand()) { cmd.CommandType = CommandType.Text; cmd.CommandText = strSQL; using (SqlDataReader reader = cmd.ExecuteReader()) { if (reader.Read()) { DateTime dtDateTime = (DateTime)reader["strDateTaken"]; reader.Close(); return(dtDateTime); } reader.Close(); } } AddPicture(strPicture, -1); string strDateTime; using (ExifMetadata extractor = new ExifMetadata()) { ExifMetadata.Metadata metaData = extractor.GetExifMetadata(strPic); strDateTime = DateTime.Parse(metaData.DatePictureTaken.DisplayValue).ToString("yyyy-MM-dd HH:mm:ss"); } if (strDateTime != string.Empty && strDateTime != "") { DateTime dtDateTime = DateTime.ParseExact(strDateTime, "yyyy-MM-dd HH:mm:ss", new CultureInfo("")); return(dtDateTime); } else { return(DateTime.MinValue); } } catch (Exception ex) { Log.Error("MediaPortal.Picture.Database exception err:{0} stack:{1}", ex.Message, ex.StackTrace); } return(DateTime.MinValue); }
public int GetRotation(string strPicture) { // Continue only if it's a picture files if (!Util.Utils.IsPicture(strPicture)) { return(-1); } string strSQL = ""; try { string strPic = strPicture; int iRotation; DatabaseUtility.RemoveInvalidChars(ref strPic); strSQL = String.Format("select * from tblPicture where strFile like '{0}'", strPic); using (SqlCommand cmd = _connection.CreateCommand()) { cmd.CommandType = CommandType.Text; cmd.CommandText = strSQL; using (SqlDataReader reader = cmd.ExecuteReader()) { if (reader.Read()) { iRotation = (int)reader["iRotation"]; reader.Close(); return(iRotation); } reader.Close(); } } ExifMetadata extractor = new ExifMetadata(); ExifMetadata.Metadata metaData = extractor.GetExifMetadata(strPicture); iRotation = EXIFOrientationToRotation(Convert.ToInt32(metaData.Orientation.Hex)); AddPicture(strPicture, iRotation); return(0); } catch (Exception ex) { Log.Error("MediaPortal.Picture.Database exception err:{0} stack:{1}", ex.Message, ex.StackTrace); } return(0); }
public int AddPicture(string strPicture, int iRotation) { // Continue only if it's a picture files if (!Util.Utils.IsPicture(strPicture)) { return(-1); } if (strPicture == null) { return(-1); } if (strPicture.Length == 0) { return(-1); } lock (typeof(PictureDatabase)) { string strSQL = ""; try { string strPic = strPicture; DatabaseUtility.RemoveInvalidChars(ref strPic); strSQL = String.Format("select * from tblPicture where strFile like '{0}'", strPic); using (SqlCommand cmd = _connection.CreateCommand()) { cmd.CommandType = CommandType.Text; cmd.CommandText = strSQL; using (SqlDataReader reader = cmd.ExecuteReader()) { if (reader.Read()) { int id = (int)reader["idPicture"]; reader.Close(); return(id); } reader.Close(); } } //Changed mbuzina DateTime dateTaken = DateTime.Now; using (ExifMetadata extractor = new ExifMetadata()) { ExifMetadata.Metadata metaData = extractor.GetExifMetadata(strPic); try { DateTimeFormatInfo dateTimeFormat = new DateTimeFormatInfo(); dateTimeFormat.ShortDatePattern = "yyyy:MM:dd HH:mm:ss"; dateTaken = DateTime.ParseExact(metaData.DatePictureTaken.DisplayValue, "d", dateTimeFormat); } catch (Exception) {} // Smirnoff: Query the orientation information // if(iRotation == -1) iRotation = EXIFOrientationToRotation(Convert.ToInt32(metaData.Orientation.Hex)); } strSQL = String.Format("insert into tblPicture (strFile, iRotation, strDateTaken) values('{0}',{1},'{2}')", strPic, iRotation, dateTaken); return(SqlServerUtility.InsertRecord(_connection, strSQL)); } catch (Exception ex) { Log.Error("MediaPortal.Picture.Database exception err:{0} stack:{1}", ex.Message, ex.StackTrace); } return(-1); } }
/// <summary> /// Returns latest added Pictures db. /// </summary> /// <param name="type">Type of data to fetch</param> /// <returns>Resultset of matching data</returns> private LatestsCollection GetLatestPictures() { latestPictures = new LatestsCollection(); latestPicturesFiles = new Hashtable(); if (!InitDB()) { return(latestPictures); } int x = 0; try { CurrentFacade.HasNew = false; string sqlQuery = "SELECT strFile, strDateTaken FROM picture ORDER BY strDateTaken DESC LIMIT " + Utils.FacadeMaxNum + ";"; SQLiteResultSet resultSet = PicturesDB.Execute(sqlQuery); CloseDB(); if (resultSet != null) { if (resultSet.Rows.Count > 0) { int i0 = 1; for (int i = 0; i < resultSet.Rows.Count; i++) { string filename = resultSet.GetField(i, 0); if (string.IsNullOrEmpty(filename)) { continue; } // string thumb = String.Format(@"{0}\{1}L.jpg", Thumbs.Pictures, MediaPortal.Util.Utils.EncryptLine(filename)); string thumb = MediaPortal.Util.Utils.GetPicturesLargeThumbPathname(filename); if (!File.Exists(thumb)) { // thumb = String.Format(@"{0}\{1}.jpg", Thumbs.Pictures, MediaPortal.Util.Utils.EncryptLine(filename)); thumb = MediaPortal.Util.Utils.GetPicturesThumbPathname(filename); if (!File.Exists(thumb)) { // thumb = "DefaultPictureBig.png"; thumb = filename; } } if (!File.Exists(thumb)) { continue; } string dateAdded = resultSet.GetField(i, 1); bool isnew = false; try { DateTime dTmp = DateTime.Parse(dateAdded); dateAdded = String.Format("{0:" + Utils.DateFormat + "}", dTmp); isnew = (dTmp > Utils.NewDateTime); if (isnew) { CurrentFacade.HasNew = true; } } catch { } string title = Path.GetFileNameWithoutExtension(Utils.GetFilenameNoPath(filename)).ToUpperInvariant(); string exif = string.Empty; string exifoutline = string.Empty; if (File.Exists(filename)) { using (ExifMetadata extractor = new ExifMetadata()) { ExifMetadata.Metadata metaData = extractor.GetExifMetadata(filename); exif = exif + (!string.IsNullOrEmpty(metaData.CameraModel.DisplayValue) ? metaData.CameraModel.DisplayValue + System.Environment.NewLine : string.Empty); exif = exif + (!string.IsNullOrEmpty(metaData.DatePictureTaken.DisplayValue) ? metaData.DatePictureTaken.DisplayValue + System.Environment.NewLine : string.Empty); exif = exif + (!string.IsNullOrEmpty(metaData.EquipmentMake.DisplayValue) ? metaData.EquipmentMake.DisplayValue + System.Environment.NewLine : string.Empty); exif = exif + (!string.IsNullOrEmpty(metaData.ExposureCompensation.DisplayValue) ? metaData.ExposureCompensation.DisplayValue + System.Environment.NewLine : string.Empty); exif = exif + (!string.IsNullOrEmpty(metaData.ExposureTime.DisplayValue) ?metaData.ExposureTime.DisplayValue + System.Environment.NewLine : string.Empty); exif = exif + (!string.IsNullOrEmpty(metaData.Flash.DisplayValue) ? metaData.Flash.DisplayValue + System.Environment.NewLine : string.Empty); exif = exif + (!string.IsNullOrEmpty(metaData.Fstop.DisplayValue) ? metaData.Fstop.DisplayValue + System.Environment.NewLine : string.Empty); exif = exif + (!string.IsNullOrEmpty(metaData.ImageDimensions.DisplayValue) ? metaData.ImageDimensions.DisplayValue + System.Environment.NewLine : string.Empty); exif = exif + (!string.IsNullOrEmpty(metaData.MeteringMode.DisplayValue) ? metaData.MeteringMode.DisplayValue + System.Environment.NewLine : string.Empty); exif = exif + (!string.IsNullOrEmpty(metaData.Resolution.DisplayValue) ? metaData.Resolution.DisplayValue + System.Environment.NewLine : string.Empty); exif = exif + (!string.IsNullOrEmpty(metaData.ShutterSpeed.DisplayValue) ? metaData.ShutterSpeed.DisplayValue + System.Environment.NewLine : string.Empty); exif = exif + (!string.IsNullOrEmpty(metaData.ViewerComments.DisplayValue) ? metaData.ViewerComments.DisplayValue + System.Environment.NewLine : string.Empty); exifoutline = exifoutline + (!string.IsNullOrEmpty(metaData.EquipmentMake.DisplayValue) ? metaData.EquipmentMake.DisplayValue + " " : string.Empty); exifoutline = exifoutline + (!string.IsNullOrEmpty(metaData.CameraModel.DisplayValue) ? metaData.CameraModel.DisplayValue + " " : string.Empty); exifoutline = exifoutline + (!string.IsNullOrEmpty(metaData.ViewerComments.DisplayValue) ? metaData.ViewerComments.DisplayValue + " " : string.Empty); } } latestPictures.Add(new Latest(dateAdded, thumb, filename, title, exifoutline, null, null, null, null, null, null, null, null, null, null, null, null, null, exif, null, isnew)); latestPicturesFiles.Add(i0, filename); Utils.ThreadToSleep(); x++; i0++; if (x == Utils.FacadeMaxNum) { break; } } } } resultSet = null; } catch (Exception ex) { logger.Error("GetLatestPictures: " + ex.ToString()); } return(latestPictures); }
/// <summary> /// Returns latest added Pictures db. /// </summary> /// <param name="type">Type of data to fetch</param> /// <returns>Resultset of matching data</returns> private LatestsCollection GetLatestPictures() { latestPictures = new LatestsCollection(); latestPicturesFiles = new Hashtable(); if (!PictureDatabase.DbHealth) { return(latestPictures); } int x = 0; try { CurrentFacade.HasNew = false; string sqlQuery = "SELECT strFile, strDateTaken FROM picture" + (PictureDatabase.FilterPrivate ? " WHERE idPicture NOT IN (SELECT DISTINCT idPicture FROM picturekeywords WHERE strKeyword = 'Private')" : string.Empty) + " ORDER BY strDateTaken DESC LIMIT " + Utils.FacadeMaxNum + ";"; List <PictureData> pictures = PictureDatabase.GetPicturesByFilter(sqlQuery, "pictures"); if (pictures != null) { if (pictures.Count > 0) { int i0 = 1; for (int i = 0; i < pictures.Count; i++) { string filename = pictures[i].FileName; if (string.IsNullOrEmpty(filename)) { continue; } // string thumb = String.Format(@"{0}\{1}L.jpg", Thumbs.Pictures, MediaPortal.Util.Utils.EncryptLine(filename)); string thumb = MediaPortal.Util.Utils.GetPicturesLargeThumbPathname(filename); if (!File.Exists(thumb)) { // thumb = String.Format(@"{0}\{1}.jpg", Thumbs.Pictures, MediaPortal.Util.Utils.EncryptLine(filename)); thumb = MediaPortal.Util.Utils.GetPicturesThumbPathname(filename); if (!File.Exists(thumb)) { // thumb = "DefaultPictureBig.png"; thumb = filename; } } if (!File.Exists(thumb)) { continue; } bool isnew = false; isnew = (pictures[i].DateTaken > Utils.NewDateTime); if (isnew) { CurrentFacade.HasNew = true; } string title = Path.GetFileNameWithoutExtension(Utils.GetFilenameNoPath(filename)).ToUpperInvariant(); string exif = string.Empty; string exifoutline = string.Empty; if (File.Exists(filename)) { using (ExifMetadata extractor = new ExifMetadata()) { ExifMetadata.Metadata metaData = extractor.GetExifMetadata(filename); if (!metaData.IsEmpty()) { exif = metaData.ToString(); exifoutline = metaData.ToShortString(); } } } latestPictures.Add(new Latest() { DateTimeAdded = pictures[i].DateTaken, Title = title, Subtitle = exifoutline, Thumb = thumb, Fanart = filename, Classification = exif, IsNew = isnew }); latestPicturesFiles.Add(i0, filename); Utils.ThreadToSleep(); x++; i0++; if (x == Utils.FacadeMaxNum) { break; } } } } } catch (Exception ex) { logger.Error("GetLatestPictures: " + ex.ToString()); } return(latestPictures); }