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 (Exception ex)
            {
                Logger.Log("ERROR: LocalLibrary.UpdateMediaItem: " + ex);
            }

            return(updated);
        }
        public bool CreateMediaItem(LibraryItem libraryItem, bool updateMetadata)
        {
            try
            {
                using (AVAsset asset = AVAsset.FromUrl(NSUrl.FromFilename(libraryItem.LocalFilePath)))
                {
                    if (isRecording(asset))
                    {
                        if (updateMetadata)
                        {
                            fetchMetadata(asset, ref libraryItem);
                        }

                        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)
                                {
                                    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);
                            }
                        }
                    }
                    else
                    {
                        Logger.Log($"WARNNING: {libraryItem.LocalFilePath} is not a MMT recording with valid PLVF flag. DELETING");
                        NSError error;
                        if (!NSFileManager.DefaultManager.Remove(NSUrl.FromFilename(libraryItem.LocalFilePath), out error))
                        {
                            Logger.Log($"WARNNING: Unable to delete {libraryItem.LocalFilePath}: " + error);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log("ERROR: LocalLibrary.CreateMediaItem: " + ex);
            }

            return(false);
        }