aboutsummaryrefslogtreecommitdiff
path: root/mbbmlib.py
diff options
context:
space:
mode:
authorB. Stack <bgstack15@gmail.com>2023-04-02 17:05:59 -0400
committerB. Stack <bgstack15@gmail.com>2023-04-02 17:41:22 -0400
commit730da898b2b2d06db170a8421e6c75b54db2c759 (patch)
tree47418e876ae4eaafcd2e7be91412be1ba46e3e49 /mbbmlib.py
parentWIP: handle 17-row Firefox moz_places, but icons are broken right now (diff)
downloadmbbmlib-master.tar.gz
mbbmlib-master.tar.bz2
mbbmlib-master.zip
correct and simplify fields stored and retrievedHEADmaster
and remove newmoon support for now
Diffstat (limited to 'mbbmlib.py')
-rw-r--r--mbbmlib.py89
1 files changed, 24 insertions, 65 deletions
diff --git a/mbbmlib.py b/mbbmlib.py
index 55b7e61..6df614e 100644
--- a/mbbmlib.py
+++ b/mbbmlib.py
@@ -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):
bgstack15