|
|
@ -37,6 +37,7 @@ class DatabaseManager { |
|
|
|
|
|
|
|
|
for c in item.children { |
|
|
for c in item.children { |
|
|
if s.index == c.indexId { |
|
|
if s.index == c.indexId { |
|
|
|
|
|
c.objectID = s.objectID |
|
|
c.time = s.time |
|
|
c.time = s.time |
|
|
c.length = s.length |
|
|
c.length = s.length |
|
|
c.loop = s.loop |
|
|
c.loop = s.loop |
|
|
@ -60,6 +61,17 @@ class DatabaseManager { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func getKItem(_ item: MediaItem) -> KItem { |
|
|
func getKItem(_ item: MediaItem) -> KItem { |
|
|
|
|
|
if let oid = item.objectID { |
|
|
|
|
|
do { |
|
|
|
|
|
let i = try managedObjectContext.existingObject(with: oid) |
|
|
|
|
|
|
|
|
|
|
|
if i != nil { |
|
|
|
|
|
return i as! KItem |
|
|
|
|
|
} |
|
|
|
|
|
} catch { |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
let fetchRequest = KItem.fetchRequest() |
|
|
let fetchRequest = KItem.fetchRequest() |
|
|
fetchRequest.predicate = NSPredicate(format: "name == %@ AND path == %@ AND root == %@", item.name, item.path, item.root) |
|
|
fetchRequest.predicate = NSPredicate(format: "name == %@ AND path == %@ AND root == %@", item.name, item.path, item.root) |
|
|
|
|
|
|
|
|
@ -95,6 +107,22 @@ class DatabaseManager { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func saveItemMetaData(_ item: MediaItem) { |
|
|
func saveItemMetaData(_ item: MediaItem) { |
|
|
|
|
|
if (item.type == ItemType.SNAPSHOT) { |
|
|
|
|
|
if let oid = item.objectID { |
|
|
|
|
|
do { |
|
|
|
|
|
let i = try managedObjectContext.existingObject(with: oid) |
|
|
|
|
|
|
|
|
|
|
|
if i != nil { |
|
|
|
|
|
let snap = i as! KSnapshot |
|
|
|
|
|
updateSnapshot(snap: snap, c: item) |
|
|
|
|
|
print("DB -- Update snapshot at \(item.indexId)") |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
} catch { |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (item.type == ItemType.VIDEO) { |
|
|
if (item.type == ItemType.VIDEO) { |
|
|
let k = getKItem(item) |
|
|
let k = getKItem(item) |
|
|
|
|
|
|
|
|
@ -112,17 +140,8 @@ class DatabaseManager { |
|
|
for c in item.children { |
|
|
for c in item.children { |
|
|
if !kstimes.contains(Int32(c.indexId)) { |
|
|
if !kstimes.contains(Int32(c.indexId)) { |
|
|
let snap = KSnapshot(context: managedObjectContext) |
|
|
let snap = KSnapshot(context: managedObjectContext) |
|
|
snap.time = c.time |
|
|
|
|
|
snap.index = Int32(c.indexId) |
|
|
snap.index = Int32(c.indexId) |
|
|
snap.length = c.length |
|
|
|
|
|
snap.loop = c.loop |
|
|
|
|
|
snap.offx = Int16(c.offset.x) |
|
|
|
|
|
snap.offy = Int16(c.offset.y) |
|
|
|
|
|
snap.sizex = Int16(c.size.width) |
|
|
|
|
|
snap.sizey = Int16(c.size.height) |
|
|
|
|
|
snap.scale = c.scale |
|
|
|
|
|
snap.rating = Int16(c.rating) |
|
|
|
|
|
snap.thumb = c.thumbUrl |
|
|
|
|
|
|
|
|
updateSnapshot(snap: snap, c: c) |
|
|
k.addToSnapshots(snap) |
|
|
k.addToSnapshots(snap) |
|
|
|
|
|
|
|
|
print("DB -- Insert snapshot at \(c.indexId)") |
|
|
print("DB -- Insert snapshot at \(c.indexId)") |
|
|
@ -130,42 +149,47 @@ class DatabaseManager { |
|
|
else { |
|
|
else { |
|
|
for snap in ksitems { |
|
|
for snap in ksitems { |
|
|
if snap.index == c.indexId { |
|
|
if snap.index == c.indexId { |
|
|
snap.time = c.time |
|
|
|
|
|
snap.length = c.length |
|
|
|
|
|
snap.loop = c.loop |
|
|
|
|
|
snap.offx = Int16(c.offset.x) |
|
|
|
|
|
snap.offy = Int16(c.offset.y) |
|
|
|
|
|
snap.sizex = Int16(c.size.width) |
|
|
|
|
|
snap.sizey = Int16(c.size.height) |
|
|
|
|
|
snap.scale = c.scale |
|
|
|
|
|
snap.rating = Int16(c.rating) |
|
|
|
|
|
snap.thumb = c.thumbUrl |
|
|
|
|
|
|
|
|
|
|
|
var ct = [String](c.tags) |
|
|
|
|
|
|
|
|
|
|
|
for t in snap.tags as! Set<KTag> { |
|
|
|
|
|
if !c.tags.contains(t.name!) { |
|
|
|
|
|
snap.removeFromTags(t) |
|
|
|
|
|
print("remove \(t.name!)") |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
ct.removeAll(where: { e in e == t.name!}) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for a in ct { |
|
|
|
|
|
addTag(a, snapshot: snap) |
|
|
|
|
|
print("add \(a)") |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
updateSnapshot(snap: snap, c: c) |
|
|
print("DB -- Update snapshot at \(c.indexId)") |
|
|
print("DB -- Update snapshot at \(c.indexId)") |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
save() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
save() |
|
|
|
|
|
|
|
|
private func updateSnapshot(snap: KSnapshot, c: MediaItem) { |
|
|
|
|
|
snap.time = c.time |
|
|
|
|
|
snap.length = c.length |
|
|
|
|
|
snap.loop = c.loop |
|
|
|
|
|
snap.offx = Int16(c.offset.x) |
|
|
|
|
|
snap.offy = Int16(c.offset.y) |
|
|
|
|
|
snap.sizex = Int16(c.size.width) |
|
|
|
|
|
snap.sizey = Int16(c.size.height) |
|
|
|
|
|
snap.scale = c.scale |
|
|
|
|
|
snap.rating = Int16(c.rating) |
|
|
|
|
|
|
|
|
|
|
|
snap.thumb = c.thumbUrl |
|
|
|
|
|
|
|
|
|
|
|
var ct = [String](c.tags) |
|
|
|
|
|
|
|
|
|
|
|
for t in snap.tags as! Set<KTag> { |
|
|
|
|
|
if !c.tags.contains(t.name!) { |
|
|
|
|
|
snap.removeFromTags(t) |
|
|
|
|
|
print("remove \(t.name!)") |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
ct.removeAll(where: { e in e == t.name!}) |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for a in ct { |
|
|
|
|
|
addTag(a, snapshot: snap) |
|
|
|
|
|
print("add \(a)") |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func createTag(_ answer: String) { |
|
|
func createTag(_ answer: String) { |
|
|
@ -263,6 +287,8 @@ class DatabaseManager { |
|
|
let i = s.item! |
|
|
let i = s.item! |
|
|
let sitem = MediaItem(name: i.name!, path: i.path!, root: i.root!, type: ItemType.VIDEO) |
|
|
let sitem = MediaItem(name: i.name!, path: i.path!, root: i.root!, type: ItemType.VIDEO) |
|
|
sitem.loaded = true |
|
|
sitem.loaded = true |
|
|
|
|
|
sitem.compilation = true |
|
|
|
|
|
sitem.objectID = i.objectID |
|
|
|
|
|
|
|
|
let c = MediaItem(name: i.name!, path: i.path!, root: i.root!, type: ItemType.SNAPSHOT) |
|
|
let c = MediaItem(name: i.name!, path: i.path!, root: i.root!, type: ItemType.SNAPSHOT) |
|
|
c.time = s.time |
|
|
c.time = s.time |
|
|
@ -274,9 +300,18 @@ class DatabaseManager { |
|
|
c.offset.y = CGFloat(s.offy) |
|
|
c.offset.y = CGFloat(s.offy) |
|
|
c.scale = s.scale |
|
|
c.scale = s.scale |
|
|
c.rating = Int(s.rating) |
|
|
c.rating = Int(s.rating) |
|
|
c.thumbUrl = s.thumb |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if s.thumb != nil { |
|
|
|
|
|
c.thumbUrl = s.thumb |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
c.thumbUrl = c.snapshotDirPathForVideo + "\(s.index)_thumb.jpg" |
|
|
|
|
|
print("Thumb " + c.thumbUrl!) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
c.indexId = Int(s.index) |
|
|
c.indexId = Int(s.index) |
|
|
c.parent = sitem |
|
|
c.parent = sitem |
|
|
|
|
|
c.objectID = s.objectID |
|
|
|
|
|
|
|
|
for t in s.tags as! Set<KTag> { |
|
|
for t in s.tags as! Set<KTag> { |
|
|
c.tags.append(t.name!) |
|
|
c.tags.append(t.name!) |
|
|
|