Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for bookmarks from Microsoft Edge #585

Merged
merged 3 commits into from
Jun 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 49 additions & 1 deletion buku
Original file line number Diff line number Diff line change
Expand Up @@ -2393,10 +2393,38 @@ class BukuDb:
except Exception as e:
LOGERR(e)

def load_edge_database(self, path, unique_tag, add_parent_folder_as_tag):
"""Open Edge Bookmarks JSON file and import data.

Parameters
----------
path : str
Path to Microsoft Edge bookmarks file.
unique_tag : str
Timestamp tag in YYYYMonDD format.
add_parent_folder_as_tag : bool
True if bookmark parent folders should be added as tags else False.
"""

with open(path, 'r', encoding="utf8") as datafile:
data = json.load(datafile)

roots = data['roots']
for entry in roots:
# Needed to skip 'sync_transaction_version' key from roots
if isinstance(roots[entry], str):
continue
for item in self.traverse_bm_folder(
roots[entry]['children'],
unique_tag,
roots[entry]['name'],
add_parent_folder_as_tag):
self.add_rec(*item)

def auto_import_from_browser(self):
"""Import bookmarks from a browser default database file.

Supports Firefox and Google Chrome.
Supports Firefox, Google Chrome and Microsoft Edge.

Returns
-------
Expand All @@ -2414,6 +2442,8 @@ class BukuDb:
profile = get_firefox_profile_name(default_ff_folder)
if profile:
ff_bm_db_path = '~/.mozilla/firefox/{}/places.sqlite'.format(profile)

me_bm_db_path = '~/.config/microsoft-edge/Default/Bookmarks'
elif sys.platform == 'darwin':
gc_bm_db_path = '~/Library/Application Support/Google/Chrome/Default/Bookmarks'
cb_bm_db_path = '~/Library/Application Support/Chromium/Default/Bookmarks'
Expand All @@ -2423,8 +2453,11 @@ class BukuDb:
if profile:
ff_bm_db_path = ('~/Library/Application Support/Firefox/'
'{}/places.sqlite'.format(profile))

me_bm_db_path = '~/Library/Application Support/Microsoft Edge/Default/Bookmarks'
elif sys.platform == 'win32':
username = os.getlogin()

gc_bm_db_path = ('C:/Users/{}/AppData/Local/Google/Chrome/User Data/'
'Default/Bookmarks'.format(username))
cb_bm_db_path = ('C:/Users/{}/AppData/Local/Chromium/User Data/'
Expand All @@ -2434,6 +2467,9 @@ class BukuDb:
profile = get_firefox_profile_name(default_ff_folder)
if profile:
ff_bm_db_path = os.path.join(default_ff_folder, '{}/places.sqlite'.format(profile))

me_bm_db_path = ('C:/Users/{}/AppData/Local/Microsoft/Edge/User Data/'
'Default/Bookmarks'.format(username))
else:
LOGERR('buku does not support {} yet'.format(sys.platform))
self.close_quit(1)
Expand Down Expand Up @@ -2488,6 +2524,18 @@ class BukuDb:
LOGERR(e)
print('Could not import bookmarks from Firefox.')

try:
jarun marked this conversation as resolved.
Show resolved Hide resolved
if self.chatty:
resp = input('Import bookmarks from microsoft edge? (y/n): ')
if resp == 'y':
bookmarks_database = os.path.expanduser(me_bm_db_path)
if not os.path.exists(bookmarks_database):
raise FileNotFoundError
self.load_edge_database(bookmarks_database, newtag, add_parent_folder_as_tag)
except Exception as e:
LOGERR(e)
print('Could not import bookmarks from microsoft-edge')

self.conn.commit()

if newtag:
Expand Down