Skip to content

Instantly share code, notes, and snippets.

@guidocella
Last active November 3, 2023 19:47
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guidocella/a272b6e68f9c44532b011f6596e95c61 to your computer and use it in GitHub Desktop.
Save guidocella/a272b6e68f9c44532b011f6596e95c61 to your computer and use it in GitHub Desktop.
Convert qutebrowser's cookies to Netscape format
#!/bin/sh
{
echo '# Netscape HTTP Cookie File' # needed by youtube-dl
# There is no attempt to url encode $1, but SQLite already handles
# characters like spaces, so only ? % and # should cause issues.
sqlite3 -separator ' ' "file:${1:-$HOME/.local/share/qutebrowser}/webengine/Cookies?nolock=1" "
SELECT
host_key,
IIF(host_key LIKE '.%', 'TRUE', 'FALSE'),
path,
IIF(is_secure, 'TRUE', 'FALSE'),
IIF(expires_utc == 0, 0, expires_utc / 1000000 - 11644473600),
name,
value
FROM cookies;"
} > $XDG_RUNTIME_DIR/cookies.txt
# expires_utc is converted from the Windows NT Time Format to a UNIX timestamp
@Konubinix
Copy link

I had to replace '\t' by $'\t'. Otherwise, it worked like a charm. Thank you :-)

@guidocella
Copy link
Author

guidocella commented Aug 25, 2023

I had to replace '\t' by $'\t'. Otherwise, it worked like a charm. Thank you :-)

It seems that '\t' works in dash but not in bash and $'\t' works in bash but not in dash. I just restored the literal tab.

Edit: actually I also have sh linked to bash and it worked fine until now so it is sqlite3 that can interpret \t. What sh are you using to have it break?

@dirkf
Copy link

dirkf commented Aug 25, 2023

Maybe this?

    ...
    tab_char="\t"
    sqlite3 -separator "$tab_char" "file:${1:-$HOME/.local/share/qutebrowser}/webengine/Cookies?nolock=1" "
    ...

@dirkf
Copy link

dirkf commented Aug 25, 2023

Also, could this be rendered as a qutebrowser userscript?

@guidocella
Copy link
Author

It should run fine as a userscript. You can even use $QUTE_DATA_DIR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment