From 0361ae52af5eb2c61db4fc3f3696277d2ea7f230 Mon Sep 17 00:00:00 2001 From: dyknon Date: Sun, 23 Aug 2026 14:50:47 +0900 Subject: export-firefox-cookies --- export-firefox-cookies | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 export-firefox-cookies (limited to 'export-firefox-cookies') diff --git a/export-firefox-cookies b/export-firefox-cookies new file mode 100644 index 0000000..98367f3 --- /dev/null +++ b/export-firefox-cookies @@ -0,0 +1,50 @@ +# Firefox のクッキーを cookies.txt (Netscape HTTP Cookie File) として出す方法 + +yt-dlp のためにクッキーをエクスポートしたかった。 +なんか、アドオンとか入れるのはなんか嫌だ。と思ったので。 + +$FIREFOX_PROFILE/cookies.sqlite にかかれているみたいなので、 +sqlite3 コマンドで引っ張り出して jq と sed で整形する。 +正しさは知らないが、なんとなく動いた。 + +``` +echo '# Netscape HTTP Cookie File' +echo +sqlite3 cookies.sqlite \ + '.mode json --limits 0,0,0' \ + 'select * from moz_cookies' \ + | jq -r '.[] + | if .isHttpOnly then "#HttpOnly_\n" else "" end + + .host +"\t" + + (if .host|test("^\\.") then "TRUE" else "FALSE" end) +"\t" + + .path +"\t" + + (if .isSecure then "TRUE" else "FALSE" end) +"\t" + + (.expiry/1000|floor|tostring) +"\t" + + .name +"\t" + +.value + ' +``` + +select を使ってエクスポート対象を絞り込める +(もちろん、 jq でやったっていい) + +``` +echo '# Netscape HTTP Cookie File' +echo +sqlite3 cookies.sqlite \ + ".mode json --limits 0,0,0" \ + "select * from moz_cookies where + host like '%.google.com' + or host like '%.youtube.com' + " \ + | jq -r '.[] + | if .isHttpOnly then "#HttpOnly_\n" else "" end + + .host +"\t" + + (if .host|test("^\\.") then "TRUE" else "FALSE" end) +"\t" + + .path +"\t" + + (if .isSecure then "TRUE" else "FALSE" end) +"\t" + + (.expiry/1000|floor|tostring) +"\t" + + .name +"\t" + +.value + ' +``` -- cgit v1.2.3