diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | mbbmlib.py | 89 |
2 files changed, 25 insertions, 65 deletions
@@ -4,3 +4,4 @@ foo* *.html old .*.swp +*.sqlite* @@ -8,6 +8,7 @@ # History: # 2022-03-05 fix even more UTF-8 crap # 2023-04-01 add bare 17-row Firefox moz_places support. Still need to follow probably origin_id to moz_origins to the icons file to moz_icons? +# 2023-04-02 removing newmoon support to focus on FF icon support # Usage: # main command is export_bookmarks_to_html. # Reference: @@ -321,47 +322,27 @@ class Bookmark: # now conduct regular operations if browser == 'firefox': - raw_bookmarks= conn.execute("SELECT * FROM moz_bookmarks") - raw_places = conn.execute("SELECT * FROM moz_places") + raw_bookmarks = conn.execute("SELECT id, type, fk, parent, position, title, keyword_id, folder_type, dateAdded, lastModified FROM moz_bookmarks") + raw_places = conn.execute("SELECT id, url, title FROM moz_places p") + if fetch_icons: + conn.execute(f"""ATTACH "{icons_file}" AS i""") + raw_places = conn.execute("SELECT p.id, p.url, p.title, i.id, i.data FROM moz_places p LEFT join moz_pages_w_icons w on p.url = w.page_url LEFT JOIN moz_icons_to_pages ic ON ic.page_id = w.id LEFT JOIN moz_icons i on i.id = ic.icon_id") elif browser == 'palemoon': - raw_bookmarks= conn.execute("SELECT id,type,fk,parent,position,title,keyword_id,folder_type,dateAdded,lastModified,guid FROM moz_bookmarks") - raw_places = conn.execute("SELECT id,url,title,rev_host,visit_count,hidden,typed,favicon_id,frecency,last_visit_date,guid,foreign_count,url_hash FROM moz_places") - - if fetch_icons and browser != "palemoon": - with sqlite3.connect(icons_file) as conn: - raw_icons = conn.execute("SELECT * FROM moz_icons") - - if browser == "firefox": - for row in raw_bookmarks: - bid, btype, parent, fk, position, title, keyword_id, folder_type, dateAdded, lastModified, guid, syncStatus, syncChangeCounter = row - db_bookmarks.append(db_bookmark(bid, btype, parent, fk, position, title, keyword_id, folder_type, dateAdded, lastModified, guid, syncStatus, syncChangeCounter)) - for row in raw_places: - #print(f"DEBUG: len(row): {len(row)}, row: {row}") - if (len(row)) == 15: - # LibreWolf, observed 2021-12-02 has no column for favicon_id. - pid, url, title, rev_host, visit_count, hidden, typed, frecency, last_visit_date, guid, foreign_count, url_hash, description, preview_image_url, origin_id = row - favicon_id = 0 - elif len(row) == 17: - # Firefox probably 111.0, observed 2023-04-01 added a new row - pid, url, title, rev_host, visit_count, hidden, typed, frecency, last_visit_date, guid, foreign_count, url_hash, description, preview_image_url, origin_id, site_name, recalc_frecency = row - favicon_id = 0 - else: - # 16 rows? - pid, url, title, rev_host, visit_count, hidden, typed, favicon_id, frecency, last_visit_date, guid, foreign_count, url_hash, description, preview_image_url, origin_id = row - db_places.append(db_place(pid, url, title, rev_host, visit_count, hidden, typed, favicon_id, frecency, last_visit_date, guid, foreign_count, url_hash, description, preview_image_url, origin_id)) - - elif browser == "palemoon": - for row in raw_bookmarks: - bid, btype, fk, parent, position, title, keyword_id, folder_type, dateAdded, lastModified, guid = row - db_bookmarks.append(db_bookmark(bid, btype, fk, parent, position, title, keyword_id, folder_type, dateAdded, lastModified, guid)) - for row in raw_places: - pid, url, title, rev_host, visit_count, hidden, typed, favicon_id, frecency, last_visit_date, guid, foreign_count, url_hash = row - db_places.append(db_place(pid, url, title, rev_host, visit_count, hidden, typed, favicon_id, frecency, last_visit_date, guid, foreign_count, url_hash, "", "", 0)) - - if fetch_icons and (browser != "palemoon"): - for row in raw_icons: - iid, icon_url, fixed_icon_url, width, root, color, expire_ms, data = row - db_icons.append(db_icon(iid, icon_url, fixed_icon_url, width, root, color, expire_ms, data)) + printf(f"Fatal! Palemoon no longer supported as of version 20230402a.") + return -1 + + for row in raw_bookmarks: + bid, btype, fk, parent, position, title, keyword_id, folder_type, dateAdded, lastModified = row + db_bookmarks.append(db_bookmark(bid, btype, parent, fk, position, title, keyword_id, folder_type, dateAdded, lastModified)) + for row in raw_places: + if fetch_icons: + pid, url, title, iid, icon_data = row + else: + pid, url, title = row + iid = None + icon_data = None + db_places.append(db_place(pid, url, title)) + db_icons.append(db_icon(iid, url, icon_data)) ## print, to validate #for bm in db_bookmarks: @@ -448,7 +429,7 @@ class Bookmark: ) class db_bookmark: - def __init__(self,bid,btype,fk,bparent,position,title,keyword_id,folder_type,dateAdded,lastModified,guid,syncStatus="",syncChangeCounter=""): + def __init__(self,bid,btype,bparent,fk,position,title,keyword_id,folder_type,dateAdded,lastModified): self.bid = bid self.btype = btype self.bparent = bparent @@ -459,9 +440,6 @@ class db_bookmark: self.folder_type = folder_type self.dateAdded = dateAdded self.lastModified = lastModified - self.guid = guid - self.syncStatus = syncStatus - self.syncChangeCounter = syncChangeCounter def __str__(self): encoded = "Encoding error on bookmark " + str(self.bid) @@ -477,34 +455,15 @@ class db_bookmark: return encoded class db_place: - def __init__(self,pid,url,title,rev_host,visit_count,hidden,typed,favicon_id,frecency,last_visit_date,guid,foreign_count,url_hash,description,preview_image_url,origin_id,recalc_frecency=None): + def __init__(self,pid,url,title): self.pid = pid self.url = url self.title = title - self.rev_host = rev_host - self.visit_count = visit_count - self.hidden = hidden - self.typed = typed - self.favicon_id = favicon_id - self.frecency = frecency - self.last_visit_date = last_visit_date - self.guid = guid - self.foreign_count = foreign_count - self.url_hash = url_hash - self.description = description - self.preview_image_url = preview_image_url - self.origin_id = origin_id - self.recalc_frecency = recalc_frecency class db_icon: - def __init__(self,iid,icon_url,fixed_icon_url,width,root,color,expire_ms,data): + def __init__(self,iid,icon_url,data): self.iid = iid self.icon_url = icon_url - self.fixed_icon_url = fixed_icon_url - self.width = width - self.root = root - self.color = color - self.expire_ms = expire_ms self.data = data def export_bookmarks_to_html(places_file, output_file, limit=2000, fetch_icons=True, iconsize=32, debuglev=0): |