//private void fetchMetadata(AVAsset asset, ref LibraryItem libraryItem) //{ // if (libraryItem != null) // { // //Common metadata // libraryItem.IsLocal = true; // if (!string.IsNullOrEmpty(libraryItem.LocalFilePath) && File.Exists(libraryItem.LocalFilePath)) // libraryItem.Updated = File.GetLastWriteTime(libraryItem.LocalFilePath); // } //} public bool UpdateMediaItem(LibraryItem libraryItem, bool createIfNotExisting) { var updated = false; try { lock (databaseSync) { using (var conn = new SQLiteConnection(DatabasePath)) { LibraryItemProperties dbItem = null; if (libraryItem.Storage == LibraryItemStorage.AppLocal) { string relativePath = libraryItem.LocalFilePath.Substring(ItemDownloader.DownloaderPath.Length); dbItem = conn.Table <LibraryItemProperties>().FirstOrDefault(item => (relativePath == item.Path) && (libraryItem.Storage == item.Storage)); } else if (libraryItem.Storage == LibraryItemStorage.iTunes) { dbItem = conn.Table <LibraryItemProperties>().FirstOrDefault(item => (item.Id == libraryItem.ID) && (libraryItem.Storage == item.Storage)); } if (dbItem != null) { dbItem.BookmarkTime = libraryItem.BookmarkTime; dbItem.HardLinkName = libraryItem.HardLinkFileName; conn.Update(dbItem); } else if (createIfNotExisting) { LibraryItemProperties properties = new LibraryItemProperties() { Id = libraryItem.ID, Storage = libraryItem.Storage, Path = (libraryItem.Storage == LibraryItemStorage.AppLocal) ? libraryItem.LocalFilePath.Substring(ItemDownloader.DownloaderPath.Length) : libraryItem.LocalFilePath, HardLinkName = libraryItem.HardLinkFileName }; conn.Insert(properties); updated = true; } } } } catch (System.Exception ex) { Logger.Log("ERROR: LocalLibrary.UpdateMediaItem: " + ex); } return(updated); }
public bool CreateMediaItem(LibraryItem libraryItem, bool updateMetadata) { try { using (var conn = new SQLiteConnection(DatabasePath)) { LibraryItemProperties dbItem = null; if (libraryItem.Storage == LibraryItemStorage.AppLocal) { string relativePath = libraryItem.LocalFilePath.Substring(ItemDownloader.DownloaderPath.Length); dbItem = conn.Table <LibraryItemProperties>().FirstOrDefault(item => (relativePath == item.Path) && (libraryItem.Storage == item.Storage)); } else if (libraryItem.Storage == LibraryItemStorage.iTunes) { dbItem = conn.Table <LibraryItemProperties>().FirstOrDefault(item => (item.Id == libraryItem.ID) && (libraryItem.Storage == item.Storage)); } if (dbItem != null) { conn.Delete(dbItem); } LibraryItemProperties properties = new LibraryItemProperties() { Id = libraryItem.ID, Storage = libraryItem.Storage, Path = (libraryItem.Storage == LibraryItemStorage.AppLocal) ? libraryItem.LocalFilePath.Substring(ItemDownloader.DownloaderPath.Length) : libraryItem.LocalFilePath }; conn.Insert(properties); return(true); } } catch (System.Exception ex) { Logger.Log("ERROR: LocalLibrary.CreateMediaItem: " + ex); } return(false); }