X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=Storage%2Fbkmk_stjson.py;h=077f89cfa6cceb1e7575cde3f2d5a154759dca8c;hb=742ce372d408094cf0e5cc6b0a11c93afda3e08b;hp=77b3a039348f01262313a4bbf12ebe0c5bd4d0f5;hpb=1bf29b390bf31ab36e581102a6316c79d272d4e1;p=bookmarks_db.git diff --git a/Storage/bkmk_stjson.py b/Storage/bkmk_stjson.py index 77b3a03..077f89c 100644 --- a/Storage/bkmk_stjson.py +++ b/Storage/bkmk_stjson.py @@ -39,6 +39,8 @@ class storage_json(Walker): dict["lastModified"] = f.last_modified parent_idx = getattr(f, 'parent_idx') if parent_idx: dict["parent"] = parent_idx + root = getattr(f, 'root') + if root: dict["root"] = root dict["title"] = f.name.decode('utf-8') dict["type"] = "text/x-moz-place-container" self.folder_stack[-1].append(dict) @@ -57,11 +59,23 @@ class storage_json(Walker): dict["id"] = b.id index = getattr(b, 'index') if index: dict["index"] = index + keyword = getattr(b, 'keyword') + if keyword: dict["keyword"] = keyword dict["lastModified"] = b.last_modified dict["parent"] = b.parent_idx dict["title"] = b.name.decode('utf-8') dict["type"] = "text/x-moz-place" - dict["uri"] = b.href + dict["uri"] = uri = b.href + if uri.startswith('place:'): + if uri.startswith('place:sort=8'): + value = 'MostVisited' + elif uri.startswith('place:folder=BOOKMARKS_MENU'): + value = 'RecentlyBookmarked' + elif uri.startswith('place:sort=14'): + value = 'RecentTags' + dict["annos"] = make_annos(value, name='Places/SmartBookmark') + del dict["dateAdded"] + del dict["lastModified"] self.folder_stack[-1].append(dict) def ruler(self, r, level): @@ -94,9 +108,13 @@ class storage_json(Walker): # Work around a bug in Mozilla - remove the trailing comma bkmk_s = bkmk_s.strip().replace(',]', ']') bookmarks_dict = json.loads(bkmk_s) + del bkmk_s root_folder = Folder() root_folder.header = '' + root_folder.add_date = bookmarks_dict["dateAdded"] + root_folder.comment = '' + root_folder.last_modified = bookmarks_dict["lastModified"] self.folder_stack = [root_folder] self.current_folder = root_folder @@ -106,28 +124,22 @@ class storage_json(Walker): return root_folder - def load_folder(self, folder, _dict): - if _dict["type"] != "text/x-moz-place-container": - raise ValueError("Root object is not a Mozilla container") + def load_folder(self, folder, fdict): + if fdict["type"] != "text/x-moz-place-container": + raise ValueError("The object is not a Mozilla container") - folder.id = _dict["id"] - folder.index = _dict.get("index") - folder.parent_idx = _dict.get("parent") + folder.id = fdict["id"] + folder.index = fdict.get("index") + folder.parent_idx = fdict.get("parent") + folder.root = fdict.get("root") + folder.name = encode(fdict["title"]) - folder.name = encode(_dict["title"]) - folder.comment = '' - folder.add_date = _dict["dateAdded"] - folder.last_modified = _dict["lastModified"] - - for record in _dict["children"]: + for record in fdict["children"]: if record["type"] == "text/x-moz-place-container": folder = Folder( add_date=record["dateAdded"], comment=get_comment(record.get("annos")), last_modified=record["lastModified"]) - folder.id = record["id"] - folder.parent_idx = record["parent"] - folder.name = encode(record["title"]) self.current_folder.append(folder) self.folder_stack.append(folder) self.current_folder = folder @@ -138,6 +150,7 @@ class storage_json(Walker): href=record["uri"], add_date=record.get("dateAdded"), last_modified=record.get("lastModified"), + keyword=record.get("keyword"), comment=get_comment(record.get("annos")), charset=record.get("charset")) bookmark.id = record["id"] @@ -171,20 +184,20 @@ def encode(title): def get_comment(annos): if not annos: - return None + return '' for a in annos: if a["name"] == "bookmarkProperties/description" and \ a["type"] == 3: return a["value"].encode('utf-8') - return None + return '' -def make_annos(comment): +def make_annos(value, name="bookmarkProperties/description"): return [{ "expires": 4, "flags": 0, "mimeType": None, - "name": "bookmarkProperties/description", + "name": name, "type": 3, - "value": comment.decode('utf-8')}] + "value": value.decode('utf-8')}]