Metadata-Version: 2.4
Name: befave
Version: 0.1.0
Summary: Keep favorites in sync across Chrome, Firefox, Safari and Opera via a deduplicated sqlite3 database
Author: David Jackson
Author-email: David Jackson <pyguy411@gmail.com>
License-Expression: MIT
License-File: LICENSE
Requires-Python: >=3.9
Description-Content-Type: text/markdown

# befave

Keep your favorites in sync across browsers. `befave` reads the bookmark export
from Chrome, Firefox, Safari or Opera, merges everything into one sqlite3
database with no duplicates, and writes it back out as a file any of those
browsers can import. Two commands do this: `pull` reads a browser's exported
file into the database, and `push` writes the database out as a file for a
browser to import. (Browsers call these steps "export" and "import"; `befave`
uses its own words to keep them apart.) Pull and push can be repeated in
cycles, so favorites can round trip between browsers.

## Why

- Frustrated that the browser on your work computer doesn't have the same
  favorites as your home computer? Export from each browser, pull both files
  into `befave`, and push the merged set back to either one.
- Added new favorites in a new browser after you pulled your favorites from
  another one? Export the new browser's bookmarks, pull them (only the new
  ones are added), then push the full set to any browser.
- Switching browsers, or using several at once? Keep one master list and
  load it into whichever browser you pick up.

## Install

```
uv tool install befave   # once published
# or from a checkout
uv run befave
```

## Usage

Run `befave` and it asks what it needs to know. Most questions are numbered
choices: type the number and press Enter. Anything you pass as an argument is
not asked again.

```
befave                      # asks: pull or push?
befave pull                 # asks for the file(s), source and database
befave pull --db a.sqlite3 --source home-firefox example_formats/firefox_bookmarks.html
befave push                 # asks for the target browser, output file, source, database
befave push out.html --browser firefox --source home-firefox --db a.sqlite3
```

When not run from a terminal, `befave` never prompts. It uses the default
database and fails with a message if something required is missing.

### Step by step

**Pull**: read a browser's exported bookmarks file into the database.

1. In your browser, export your bookmarks as an HTML file (see below).
2. Run `befave` and choose `1` (pull), or run `befave pull`.
3. Enter the path to the exported file (`.html` or `.zip`).
4. **Which database?** Choose `1` to use the default database (its path is
   shown), or `2` to type the path to a different one.
5. **Which source is this?** A source is one browser profile on one computer,
   such as `work-chrome`. Pick an existing one from the list, or choose "Add a
   new source" and type a name. Use the same name every time you pull from that
   browser, because `befave` compares each pull with the previous one to spot
   favorites you deleted.
6. If asked to confirm deletions or restores, choose `1` (Yes) or `2` (No); see
   [Deletions](#deletions).

**Push**: write the database out as a file a browser can import.

1. Run `befave` and choose `2` (push), or run `befave push`.
2. **Which browser will import this file?** Choose the browser. This only sets
   the name of the toolbar folder in the file, so your toolbar favorites land
   on that browser's real toolbar (see [What push does](#what-push-does)). It
   does not change which favorites are included.
3. Enter the path for the output `.html` file.
4. Choose the database, as in pull.
5. Choose the source the file is for, usually the browser profile you are about
   to import it into. Pushing records what that source now has, so a favorite
   you later delete there is recognized as a deletion and not re-added.
6. In the browser, import the file with its bookmark manager's import option.

### Getting an export file from your browser

Use the browser's bookmark manager export (HTML). Safari's export can be a
`.zip`, which `befave` opens itself. The browser is detected by reading the
file, so you never say which one it came from.

### Database

The default is `~/.befave/favorites.db`; use `--db` to choose
another file. One table, `bookmarks`, holds the URL, title, folder path, add
and last-modified dates, tags (Firefox) and the icon (base64 data). The other
tables (`sources`, `snapshots`, `source_items`, `tombstones`) track deletions.

### Using more than one computer

The database is a single file on one machine; `befave` does not sync over the
network. To share favorites between, say, a work and a home computer, keep the
database in a folder you already sync (Dropbox, iCloud Drive, a USB stick, etc.)
and point both computers at it with `--db`:

```
befave pull --db ~/Dropbox/favorites.db --source work-chrome bookmarks.html
befave push out.html --browser chrome --source work-chrome --db ~/Dropbox/favorites.db
```

Or copy `~/.befave/favorites.db` between machines. Use it from
one computer at a time, and let the sync finish before running `befave` on
another, so two copies don't diverge.

## What pull does

- **No duplicates.** URLs are compared after lowercasing the scheme and host,
  dropping the `#fragment`, and removing `utm_*` tracking parameters. The path
  and the rest of the query keep their case. The first URL processed wins,
  including across files and runs; the same URL in several folders is saved once.
- **Web links only.** Only `http`, `https` and `ftp` links are kept. Browser
  internals such as `chrome://`, `about:`, `javascript:`, `moz-extension://`,
  `place:` and `file://` are skipped.
- **Browser defaults are skipped.** Firefox's "Mozilla Firefox" folder (and its
  stray help/customize links) and the 12 links Safari ships in Favorites.
  The lists are `BUNDLED_FOLDERS` and `SAFARI_DEFAULTS` in `puller.py`.
- **Toolbar folders are normalized.** Chrome/Opera "Bookmarks Bar", Firefox
  "Bookmarks Toolbar" and Safari "Favorites" are all stored as `Bookmarks Bar`.

## Deletions

Every pull and push is tied to a **source**: one browser profile on one
computer (for example `work-chrome`). `befave` asks you to pick an existing
source or add a new one, or you can pass `--source NAME`.

Each pull is treated as the full list of that source's favorites. A favorite
that was in the source's previous pull but is missing now counts as deleted
and is removed from the database, so it is no longer pushed to your other
browsers. A deleted favorite is not brought back by a pull of another source
that still has it.

Two safeguards ask for confirmation (`pull --yes` accepts them):

- **Mass deletion:** if more than 30% of a source's favorites (for sources with
  more than 10) are missing, it may be a partial export, such as a single folder.
- **Restoring:** a file contains a favorite that was deleted earlier and that
  source did not have in its last pull. Declining keeps it deleted.

The first pull of a source never deletes anything.

## What push does

Writes a Netscape-format HTML file with the folder hierarchy rebuilt. The
toolbar folder is named for the target browser (`--browser`):

| Browser | Toolbar folder |
|---|---|
| chrome, opera | Bookmarks Bar |
| firefox | Bookmarks Toolbar |
| safari | Favorites |

The file has no wrapper folder. Other root folders sit beside the toolbar.

## Possible future feature: hosted sync

Today you share the database file yourself (see above). A paid hosted service
could do that for you: sign in, and your favorites sync between all your
computers and browsers without moving files around. This is only an idea and
nothing is built yet. If you would be interested, please get in touch at
pyguy411@gmail.com.

## Development

Example exports live in `example_formats/`, named after their browser. They
contain real bookmarks and are git-ignored: **never commit sample bookmarks or
test databases.**

```
uv run befave -h
uv build
```

## License

MIT. See [LICENSE](LICENSE). The software is provided "as is", without warranty of any kind.
